linux-user: Implement missing *xattr calls
cover linux-user: Implement missing *xattr calls
These patches implement the missing *xattr syscalls:
listxattr
fsetattr, fgetattr, fremovexattr, flistxattr lsetattr, lgetattr, lremovexattr, llistxattr
They also fix a bug in the existing code where we weren't allowing a NULL value pointer.
Tested with the testcases in crackerjack. (There are some cases where we don't behave exactly like the native kernel:
* we check for bad pointers earlier, so tend to return EFAULT when the kernel might return EINVAL in a "caller did two wrong things" case
* we insist on the whole of the caller's buffer being writable whereas the kernel only cares about being able to write the data it actually needs, so we will fail EFAULT some bad callers that the kernel doesn't
I don't think these are important.)
Peter Maydell (3):
linux-user: Allow NULL value pointer in setxattr and getxattr linux-user/syscall.c: Implement f and l versions of
set/get/removexattr
linux-user: Implement *listxattr syscalls
linux-user/syscall.c | 139 ++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 123 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.5.4
PATCH 1/3 linux-user: Allow NULL value pointer in setxattr and getxattr
It's valid to pass a NULL value pointer to setxattr, so don't fail this case EFAULT.
--- linux-user/syscall.c | 24 ++++++++++++++++++------ 1 files changed, 18 insertions(+), 6 deletions(-)
linux-user/syscall.c +18 -6
@@ -7655,11 +7655,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,break ;case TARGET_NR_setxattr: { -void *p, *n, *v; +void *p, *n, *v =0 ; +if (arg3) { + v =lock_user (VERIFY_READ , arg3, arg4,1 ); +if (!v) { + ret = -TARGET_EFAULT ; +break ; + } + } p =lock_user_string (arg1); n =lock_user_string (arg2); - v =lock_user (VERIFY_READ , arg3, arg4,1 ); -if (p && n && v) { +if (p && n) { ret =get_errno (setxattr (p, n, v, arg4, arg5)); }else { ret = -TARGET_EFAULT ;
@@ -7671,11 +7677,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,break ;case TARGET_NR_getxattr: { -void *p, *n, *v; +void *p, *n, *v =0 ; +if (arg3) { + v =lock_user (VERIFY_WRITE , arg3, arg4,0 ); +if (!v) { + ret = -TARGET_EFAULT ; +break ; + } + } p =lock_user_string (arg1); n =lock_user_string (arg2); - v =lock_user (VERIFY_WRITE , arg3, arg4,0 ); -if (p && n && v) { +if (p && n) { ret =get_errno (getxattr (p, n, v, arg4)); }else { ret = -TARGET_EFAULT ;
Signature · 1 line
1.7.5.4
PATCH 2/3 linux-user/syscall.c: Implement f and l versions of set/get/removexattr
In reply to Peter MaydellImplement the f and l versions (operate on fd, don't follow links) of the setxattr, getxattr and removexattr syscalls.
--- linux-user/syscall.c | 79 ++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 70 insertions(+), 9 deletions(-)
linux-user/syscall.c +70 -9
@@ -7642,18 +7642,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,#endif #ifdef CONFIG_ATTR #ifdef TARGET_NR_setxattr - case TARGET_NR_lsetxattr: - case TARGET_NR_fsetxattr: - case TARGET_NR_lgetxattr: - case TARGET_NR_fgetxattr: case TARGET_NR_listxattr: case TARGET_NR_llistxattr: case TARGET_NR_flistxattr: - case TARGET_NR_lremovexattr: - case TARGET_NR_fremovexattr: ret = -TARGET_EOPNOTSUPP; break; case TARGET_NR_setxattr: + case TARGET_NR_lsetxattr: { void *p, *n, *v = 0; if (arg3) {
@@ -7666,7 +7661,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, p =lock_user_string (arg1); n =lock_user_string (arg2);if (p && n) { - ret =get_errno (setxattr (p, n, v, arg4, arg5)); +if (num == TARGET_NR_setxattr) { + ret =get_errno (setxattr (p, n, v, arg4, arg5)); + }else { + ret =get_errno (lsetxattr (p, n, v, arg4, arg5)); + } }else { ret = -TARGET_EFAULT ; }
@@ -7675,7 +7674,28 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,unlock_user (v, arg3,0 ); }break ; +case TARGET_NR_fsetxattr: + { +void *n, *v =0 ; +if (arg3) { + v =lock_user (VERIFY_READ , arg3, arg4,1 ); +if (!v) { + ret = -TARGET_EFAULT ; +break ; + } + } + n =lock_user_string (arg2); +if (n) { + ret =get_errno (fsetxattr (arg1, n, v, arg4, arg5)); + }else { + ret = -TARGET_EFAULT ; + } +unlock_user (n, arg2,0 ); +unlock_user (v, arg3,0 ); + } +break ;case TARGET_NR_getxattr: +case TARGET_NR_lgetxattr: {void *p, *n, *v =0 ;if (arg3) {
@@ -7688,7 +7708,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, p =lock_user_string (arg1); n =lock_user_string (arg2);if (p && n) { - ret =get_errno (getxattr (p, n, v, arg4)); +if (num == TARGET_NR_getxattr) { + ret =get_errno (getxattr (p, n, v, arg4)); + }else { + ret =get_errno (lgetxattr (p, n, v, arg4)); + } }else { ret = -TARGET_EFAULT ; }
@@ -7697,13 +7721,38 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,unlock_user (v, arg3, arg4); }break ; +case TARGET_NR_fgetxattr: + { +void *n, *v =0 ; +if (arg3) { + v =lock_user (VERIFY_WRITE , arg3, arg4,0 ); +if (!v) { + ret = -TARGET_EFAULT ; +break ; + } + } + n =lock_user_string (arg2); +if (n) { + ret =get_errno (fgetxattr (arg1, n, v, arg4)); + }else { + ret = -TARGET_EFAULT ; + } +unlock_user (n, arg2,0 ); +unlock_user (v, arg3, arg4); + } +break ;case TARGET_NR_removexattr: +case TARGET_NR_lremovexattr: {void *p, *n; p =lock_user_string (arg1); n =lock_user_string (arg2);if (p && n) { - ret =get_errno (removexattr (p, n)); +if (num == TARGET_NR_removexattr) { + ret =get_errno (removexattr (p, n)); + }else { + ret =get_errno (lremovexattr (p, n)); + } }else { ret = -TARGET_EFAULT ; }
@@ -7711,6 +7760,18 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,unlock_user (n, arg2,0 ); }break ; +case TARGET_NR_fremovexattr: + { +void *n; + n =lock_user_string (arg2); +if (n) { + ret =get_errno (fremovexattr (arg1, n)); + }else { + ret = -TARGET_EFAULT ; + } +unlock_user (n, arg2,0 ); + } +break ;#endif #endif /* CONFIG_ATTR */ #ifdef TARGET_NR_set_thread_area
Signature · 1 line
1.7.5.4
PATCH 3/3 linux-user: Implement *listxattr syscalls
In reply to Peter MaydellImplement listxattr, flistxattr and llistxattr syscalls.
--- linux-user/syscall.c | 36 +++++++++++++++++++++++++++++++++++- 1 files changed, 35 insertions(+), 1 deletions(-)
linux-user/syscall.c +35 -1
@@ -7644,9 +7644,43 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,#ifdef TARGET_NR_setxattrcase TARGET_NR_listxattr:case TARGET_NR_llistxattr: + { +void *p, *b =0 ; +if (arg2) { + b =lock_user (VERIFY_WRITE , arg2, arg3,0 ); +if (!b) { + ret = -TARGET_EFAULT ; +break ; + } + } + p =lock_user_string (arg1); +if (p) { +if (num == TARGET_NR_listxattr) { + ret =get_errno (listxattr (p, b, arg3)); + }else { + ret =get_errno (llistxattr (p, b, arg3)); + } + }else { + ret = -TARGET_EFAULT ; + } +unlock_user (p, arg1,0 ); +unlock_user (b, arg2, arg3); +break ; + }case TARGET_NR_flistxattr: - ret = -TARGET_EOPNOTSUPP ; + { +void *b =0 ; +if (arg2) { + b =lock_user (VERIFY_WRITE , arg2, arg3,0 ); +if (!b) { + ret = -TARGET_EFAULT ; +break ; + } + } + ret =get_errno (flistxattr (arg1, b, arg3)); +unlock_user (b, arg2, arg3);break ; + }case TARGET_NR_setxattr:case TARGET_NR_lsetxattr: {
Signature · 1 line
1.7.5.4
Ping?
-- PMM
Quoted 30 lines · Peter Maydell
These patches implement the missing *xattr syscalls:
listxattr
fsetattr, fgetattr, fremovexattr, flistxattr lsetattr, lgetattr, lremovexattr, llistxattrThey also fix a bug in the existing code where we weren't allowing a NULL value pointer.
Tested with the testcases in crackerjack. (There are some cases where we don't behave exactly like the native kernel:
* we check for bad pointers earlier, so tend to return EFAULT when the kernel might return EINVAL in a "caller did two wrong things" case
* we insist on the whole of the caller's buffer being writable whereas the kernel only cares about being able to write the data it actually needs, so we will fail EFAULT some bad callers that the kernel doesn't I don't think these are important.)Peter Maydell (3):
linux-user: Allow NULL value pointer in setxattr and getxattrlinux-user/syscall.c: Implement f and l versions of set/get/removexattr
linux-user: Implement *listxattr syscallslinux-user/syscall.c | 139 ++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 123 insertions(+), 16 deletions(-)--
1.7.5.4
Ping^2 ?
-- PMM
Quoted 35 lines · Peter Maydell
Ping?
-- PMM
Quoted 30 lines · Peter Maydell
These patches implement the missing *xattr syscalls:
listxattr
fsetattr, fgetattr, fremovexattr, flistxattr lsetattr, lgetattr, lremovexattr, llistxattrThey also fix a bug in the existing code where we weren't allowing a NULL value pointer.
Tested with the testcases in crackerjack. (There are some cases where we don't behave exactly like the native kernel:
* we check for bad pointers earlier, so tend to return EFAULT when the kernel might return EINVAL in a "caller did two wrong things" case
* we insist on the whole of the caller's buffer being writable whereas the kernel only cares about being able to write the data it actually needs, so we will fail EFAULT some bad callers that the kernel doesn't I don't think these are important.)Peter Maydell (3):
linux-user: Allow NULL value pointer in setxattr and getxattrlinux-user/syscall.c: Implement f and l versions of set/get/removexattr
linux-user: Implement *listxattr syscallslinux-user/syscall.c | 139 ++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 123 insertions(+), 16 deletions(-)--
1.7.5.4