[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec
|
From: |
Richard Henderson |
|
Subject: |
Re: [PATCH 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec |
|
Date: |
Tue, 7 Jun 2022 14:28:47 -0700 |
|
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 |
On 6/7/22 13:14, Warner Losh wrote:
+void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
+ int count, int copy)
+{
+ struct target_iovec *target_vec;
+
+ target_vec = lock_user(VERIFY_READ, target_addr,
+ count * sizeof(struct target_iovec), 1);
+ if (target_vec) {
Locking the same region twice seems like a bad idea.
How about something like
typedef struct {
struct target_iovec *target;
abi_ulong target_addr;
int count;
struct iovec host[];
} IOVecMap;
IOVecMap *lock_iovec(abi_ulong target_addr, int count, bool copy_in)
{
IOVecMap *map;
if (count == 0) ...
if (count < 0) ...
map = g_try_malloc0(sizeof(IOVecNew) + sizeof(struct iovec) * count);
if (!map) ...
map->target = lock_user(...);
if (!map->target) {
g_free(map);
errno = EFAULT;
return NULL;
}
map->target_addr = target_addr;
map->count = count;
// lock loop
fail:
unlock_iovec(vec, false);
errno = err;
return NULL;
}
void unlock_iovec(IOVecMap *map, bool copy_out)
{
for (int i = 0, count = map->count; i < count; ++i) {
if (map->host[i].iov_base) {
abi_ulong target_base = tswapal(map->target[i].iov_base);
unlock_user(map->host[i].iov_base, target_base,
copy_out ? map->host[i].iov_len : 0);
}
}
unlock_user(map->target, map->target_addr, 0);
g_free(map);
}
r~
- [PATCH 0/6] bsd-user upstreaming: read, write and exit, Warner Losh, 2022/06/07
- [PATCH 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec, Warner Losh, 2022/06/07
- Re: [PATCH 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec,
Richard Henderson <=
- Re: [PATCH 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec, Warner Losh, 2022/06/07
- Re: [PATCH 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec, Richard Henderson, 2022/06/07
- Re: [PATCH 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec, Warner Losh, 2022/06/07
- Re: [PATCH 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec, Richard Henderson, 2022/06/07
- Re: [PATCH 2/6] bsd-user/freebsd/os-syscall.c: unlock_iovec, Warner Losh, 2022/06/08
[PATCH 3/6] bsd-user/freebsd/os-syscall.c: Tracing and error boilerplate, Warner Losh, 2022/06/07
[PATCH 1/6] bsd-user/freebsd/os-syscall.c: lock_iovec, Warner Losh, 2022/06/07