cobalt: fcntl uses void* instead of int
PATCH 1/1 cobalt: fcntl uses void* instead of int
this is consistent with glibc internals,
and fixes truncation when passing 64bit pointers
--- lib/cobalt/rtdm.c | 4 ++-- lib/cobalt/wrappers.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
lib/cobalt/rtdm.c +2 -2
@@ -139,11 +139,11 @@ static int do_ioctl(int fd, unsigned int request, void *arg) COBALT_IMPL(int, fcntl, (int fd, int cmd, ...)) {va_list ap; -int arg; +void *arg;int ret;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap); ret =XENOMAI_SYSCALL3 (sc_cobalt_fcntl, fd, cmd, arg);
lib/cobalt/wrappers.c +2 -2
@@ -216,10 +216,10 @@ __weakint __real_fcntl (int fd,int cmd, ...) {va_list ap; -int arg; +void *arg;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap);return fcntl (fd, cmd, arg);
Signature · 1 line
2.19.1
Quoted 33 lines · Norbert Lange
this is consistent with glibc internals,
and fixes truncation when passing 64bit pointers--- lib/cobalt/rtdm.c | 4 ++-- lib/cobalt/wrappers.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)lib/cobalt/rtdm.c +2
-2@@ -139,11 +139,11 @@ static int do_ioctl(int fd, unsigned int request, void *arg) COBALT_IMPL(int, fcntl, (int fd, int cmd, ...)) {va_list ap; -int arg; +void *arg;int ret;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap); ret =XENOMAI_SYSCALL3 (sc_cobalt_fcntl, fd, cmd, arg);lib/cobalt/wrappers.c +0
-0@@ -216,10 +216,10 @@ __weakint __real_fcntl (int fd,int cmd, ...) {
lib/cobalt/wrappers.c __weak · line 225
Quoted 10 lines
lib/cobalt/wrappers.c +2
-2va_list ap; -int arg; +void *arg;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap);return fcntl (fd, cmd, arg);
Fair enough, however a generic 'long' may be a better pick than an opaque pointer type in this case (*), then you would need to fix up the Cobalt kernel side implementing the actual syscall to reflect this change.
Moving away from 'int' to a longer type will also require to make Cobalt's fcntl() syscall implementation aware of the mixed ABI models when CONFIG_XENO_ARCH_SYS3264 is enabled. i.e. the argument would still be conveyed as a 32bit value for applications conforming to the ia32emu or x32 ABIs running over a 64bit kernel.
Signature · 1 line
Philippe.
Quoted 29 lines
Quoted 29 lines
lib/cobalt/rtdm.c +2
-3@@ -139,11 +139,11 @@ static int do_ioctl(int fd, unsigned int request, void *arg) COBALT_IMPL(int, fcntl, (int fd, int cmd, ...)) {va_list ap; -int arg; +void *arg;int ret;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap); ret =XENOMAI_SYSCALL3 (sc_cobalt_fcntl, fd, cmd, arg); diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c index
20ad63a61..2540e3c50100644lib/cobalt/wrappers.c +2
-2@@ -216,10 +216,10 @@ __weakint __real_fcntl (int fd,int cmd, ...) {va_list ap; -int arg; +void *arg;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap);
Quoted 6 lines
lib/cobalt/wrappers.c __weak · line 225
Quoted 2 lines
lib/cobalt/wrappers.c +0
-0return fcntl (fd, cmd, arg);Fair enough, however a generic 'long' may be a better pick than an opaque pointer type in this case (*), then you would need to fix up the Cobalt kernel side implementing the actual syscall to reflect this change.
Some fcntl calls use a pointer-to-struct, so void* or uintptr_t seems fitting for this?
(TBH I just looked at what glibc is doing, and some weird archs might have sizeof(long) < sizeof(void*))
If Xenomai only supports calls with an int, maybe truncate it just for the syscall?
ret = XENOMAI_SYSCALL3(sc_cobalt_fcntl, fd, cmd, (int)arg);
(rest of the patch untouched)
Not sure how syscalls are done, I expected the arguments are just passed in registers, In which case it does not matter (unless you don’t fit a pointer in a register)
Quoted 6 lines
Moving away from 'int' to a longer type will also require to make Cobalt's
fcntl()syscall implementation aware of the mixed ABI models whenCONFIG_XENO_ARCH_SYS3264is enabled. i.e. the argument would still
be conveyed as a 32bit value for applications conforming to the ia32emu or x32 ABIs running over a 64bit kernel.
Ok, I haven't thought about that at all. But since you apparently don't expect a pointer now, truncating the value to an int for the syscall seems fitting.
Norbert
________________________________
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Thank You
________________________________
Quoted 36 lines · Lange Norbert
Quoted 29 lines
Quoted 29 lines
lib/cobalt/rtdm.c +2
-3@@ -139,11 +139,11 @@ static int do_ioctl(int fd, unsigned int request, void *arg) COBALT_IMPL(int, fcntl, (int fd, int cmd, ...)) {va_list ap; -int arg; +void *arg;int ret;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap); ret =XENOMAI_SYSCALL3 (sc_cobalt_fcntl, fd, cmd, arg); diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c index
20ad63a61..2540e3c50100644lib/cobalt/wrappers.c +2
-2@@ -216,10 +216,10 @@ __weakint __real_fcntl (int fd,int cmd, ...) {va_list ap; -int arg; +void *arg;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap);Quoted 6 lines
lib/cobalt/wrappers.c __weak · line 225
Quoted 2 lines
lib/cobalt/wrappers.c +0
-0return fcntl (fd, cmd, arg);Fair enough, however a generic 'long' may be a better pick than an opaque pointer type in this case (*), then you would need to fix up the Cobalt kernel side implementing the actual syscall to reflect this change.
Quoted 2 lines
Some fcntl calls use a pointer-to-struct, so void* or
uintptr_tseems fitting for this?
(TBH I just looked at what glibc is doing, and some weird archs might have sizeof(long) <sizeof(void*))
The glibc is not involved in Cobalt calls, the Cobalt core in kernel space (obviously) is. In that space, a pointer always fits in a long word (it may even be shorter in the ia32emu/x32 ABI models).
Quoted 8 lines
If Xenomai only supports calls with an int, maybe truncate it just for the syscall?
ret = XENOMAI_SYSCALL3(sc_cobalt_fcntl, fd, cmd, (int)arg);(rest of the patch untouched)
Not sure how syscalls are done, I expected the arguments are just passed in registers, In which case it does not matter (unless you don’t fit a pointer in a register)
Kernel-wise, register values are native long words.
Quoted 10 lines
Quoted 6 lines
Moving away from 'int' to a longer type will also require to make Cobalt's
fcntl()syscall implementation aware of the mixed ABI models whenCONFIG_XENO_ARCH_SYS3264is enabled. i.e. the argument would still
be conveyed as a 32bit value for applications conforming to the ia32emu or x32 ABIs running over a 64bit kernel.Ok, I haven't thought about that at all. But since you apparently don't expect a pointer now, truncating the value to an int for the syscall seems fitting.
Generally speaking, having the userland interface and the kernel implementation disagree on some argument type is hard to justify. In contrast, we may want to enable long argument types right now in the fcntl implementation, so that we would not have to break the ABI twice to support them later. That would align both userland and kernel space on using a long type for the argument, fixing the issue you observed in the same move.
Signature · 1 line
Philippe.
To close this up,
is there anything expected from my side? I am not able to fix up the kernel side, esp. with the x32 API, and my disagreement with long vs void*/uintptr_t likely won't end up getting us anywhere.
Norbert
Quoted 90 lines
-----Original Message-----
From: Philippe Gerum <[email protected]>
Sent: Mittwoch, 17. Oktober 2018 17:27
To: Lange Norbert <[email protected]>; [email protected]
Subject: Re: [Xenomai] [PATCH] cobalt: fcntl uses void* instead of intE-MAIL FROM A NON-ANDRITZ SOURCE: AS A SECURITY MEASURE, PLEASE EXERCISE CAUTION WITH E-MAIL CONTENT AND ANY LINKS OR ATTACHMENTS.
Quoted 29 lines · Lange Norbert
Quoted 29 lines
Quoted 29 lines
lib/cobalt/rtdm.c +2
-3@@ -139,11 +139,11 @@ static int do_ioctl(int fd, unsigned int request, void *arg) COBALT_IMPL(int, fcntl, (int fd, int cmd, ...)) {va_list ap; -int arg; +void *arg;int ret;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap); ret =XENOMAI_SYSCALL3 (sc_cobalt_fcntl, fd, cmd, arg); diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c index
20ad63a61..2540e3c50100644lib/cobalt/wrappers.c +2
-2@@ -216,10 +216,10 @@ __weakint __real_fcntl (int fd,int cmd, ...) {va_list ap; -int arg; +void *arg;va_start (ap, cmd); - arg =va_arg (ap, int); + arg = va_arg(ap, void *);va_end (ap);Quoted 6 lines
Quoted 6 lines
lib/cobalt/wrappers.c __weak · line 225
Quoted 2 lines
lib/cobalt/wrappers.c +0
-0return fcntl (fd, cmd, arg);Fair enough, however a generic 'long' may be a better pick than an opaque pointer type in this case (*), then you would need to fix up the Cobalt kernel side implementing the actual syscall to reflect this
change.
Quoted 2 lines
Some fcntl calls use a pointer-to-struct, so void* or
uintptr_tseems fittingfor this?
Quoted 2 lines
(TBH I just looked at what glibc is doing, and some weird archs might
have sizeof(long) <sizeof(void*))The glibc is not involved in Cobalt calls, the Cobalt core in kernel space (obviously) is. In that space, a pointer always fits in a long word (it may even be shorter in the ia32emu/x32 ABI models).
Quoted 2 lines
If Xenomai only supports calls with an int, maybe truncate it just for the
syscall?
Quoted 7 lines
ret = XENOMAI_SYSCALL3(sc_cobalt_fcntl, fd, cmd, (int)arg);(rest of the patch untouched)
Not sure how syscalls are done, I expected the arguments are just passed in registers, In which case it does not matter (unless you don’t fit a pointer in a register)
Kernel-wise, register values are native long words.
Quoted 8 lines
Quoted 5 lines
Moving away from 'int' to a longer type will also require to make Cobalt's
fcntl()syscall implementation aware of the mixed ABI models whenCONFIG_XENO_ARCH_SYS3264is enabled. i.e. the argument would still be conveyed as a 32bit value for applications conforming to the ia32emu or x32 ABIs running over a 64bit kernel.Ok, I haven't thought about that at all. But since you apparently don't expect a pointer now, truncating the value to an int for the syscall
seems fitting.
Quoted 1 line
Generally speaking, having the userland interface and the kernel implementation disagree on some argument type is hard to justify. In contrast, we may want to enable long argument types right now in the fcntl implementation, so that we would not have to break the ABI twice to support them later. That would align both userland and kernel space on using a long type for the argument, fixing the issue you observed in the same move.
Quoted 2 lines
--
Philippe.
________________________________
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
Thank You
________________________________
Quoted 4 lines · Lange Norbert via Xenomai
To close this up,
is there anything expected from my side? I am not able to fix up the kernel side, esp. with the x32 API, and my disagreement with long vs void*/uintptr_t likely won't end up getting us anywhere.
The chosen userspace type is a nit. The important thing is indeed to change the kernel ABI before releasing 3.1. I've started to track to-dos for that release as issues, e.g. this one:
https://gitlab.denx.de/Xenomai/xenomai/issues/2
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 5 lines · Lange Norbert
To close this up,
is there anything expected from my side? I am not able to fix up the kernel side, esp. with the x32 API, and my disagreement with long vs void*/uintptr_t likely won't end up getting us anywhere.
The kernel patch is on its way. Contributing the userland changes would help.
Signature · 1 line
Philippe.