Re: [PATCH] cobalt/posix/syscall: Account for changes in kernel 7.0
"Bezdeka, Florian" <[email protected]>
| Newsgroups | dev.linux.lists.xenomai |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 2026-04-14 at 18:03 +0200, Florian Bezdeka wrote: > On Tue, 2026-04-14 at 17:35 +0200, Jan Kiszka wrote: > > From: Jan Kiszka <[email protected]> > > > > With 7.0, we no longer have a access to trace print function that takes > > the string size directly. [__]trace_puts will now always invoke strlen > > on the passed string. We therefore need to terminate our string > > properly, even if a larger one was passed. > > > > We could keep the micro-optimized variant for older kernels, but as that > > is phasing out and the gain is likely minimal (the string is still in L1 > > cache after copy_from_user), simply switch all versions to the same > > pattern. > > > > Signed-off-by: Jan Kiszka <[email protected]> > > --- > > kernel/cobalt/posix/syscall.c | 11 +++++++++-- > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c > > index a26da154c4..bc1825676f 100644 > > --- a/kernel/cobalt/posix/syscall.c > > +++ b/kernel/cobalt/posix/syscall.c > > @@ -46,6 +46,12 @@ > > #include "../debug.h" > > #include <trace/events/cobalt-posix.h> > > > > +#if LINUX_VERSION_CODE >= KERNEL_VERSION(7,0,0) > > +#include <linux/trace_printk.h> > > +#else > > +#include <linux/kernel.h> > > +#endif > > + > > /* Syscall must run into the Linux domain. */ > > #define __xn_exec_lostage 0x1 > > /* Syscall must run into the Xenomai domain. */ > > @@ -194,12 +200,13 @@ static COBALT_SYSCALL(ftrace_puts, current, > > char buf[256]; > > unsigned len; > > > > - len = cobalt_strncpy_from_user(buf, str, sizeof(buf)); > > + len = cobalt_strncpy_from_user(buf, str, sizeof(buf) - 1); > > if (len < 0) > > return -EFAULT; > > > > #ifdef CONFIG_TRACING > > - __trace_puts(_THIS_IP_, buf, len); > > + buf[sizeof(buf) - 1] = 0; > > Shouldn't we terminate at buf[len]? > > buf[len+1] to buf[sizeof(buf)-1] might be garbage, no? Ignore that. Pressed Send to fast... That is just the worst case as strncpy does not terminate in case the full buffer was used but does so if less then the full size was needed. > > > + trace_puts(buf); > > #endif > > > > return 0; > > -- > > 2.47.3