[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250417181010.3cc5777f@gandalf.local.home>
Date: Thu, 17 Apr 2025 18:10:10 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc: Mykyta Yatsenko <mykyta.yatsenko5@...il.com>, akpm@...ux-foundation.org,
linux-mm@...ck.org, mhiramat@...nel.org, andrii@...nel.org,
kernel-team@...a.com, linux-kernel@...r.kernel.org, Mykyta Yatsenko
<yatsenko@...a.com>
Subject: Re: [PATCH mm] maccess: fix strncpy_from_user_nofault empty string
handling
On Thu, 17 Apr 2025 13:44:48 -0700
Andrii Nakryiko <andrii.nakryiko@...il.com> wrote:
> > @@ -808,7 +809,9 @@ static __always_inline char *test_string(char *str)
> > kstr = ubuf->buffer;
> >
> > /* For safety, do not trust the string pointer */
> > - if (!strncpy_from_kernel_nofault(kstr, str, USTRING_BUF_SIZE))
> > + cnt = strncpy_from_kernel_nofault(kstr, str, USTRING_BUF_SIZE);
> > + /* Return null if empty string or error */
> > + if (cnt <= 1)
> > return NULL;
>
> I wouldn't touch this part and leave it up to Steven to fix (if he
> agrees it needs fixing). Current logic seems wrong already, as it
> won't correctly handle -EFAULT. And, on the other hand, there is
> nothing wrong or special about empty string, so I don't think it needs
> special handling. Let's drop these changes in trace_events_filter.c?
Bah, it is wrong. I don't usually use filtering on strings much, but come
to think of it, the last time I tried, it didn't work, but I found another
way to get what I was looking for, and didn't look deeper into it.
I only care if it faulted or not. I don't care about it just copying zero
bytes. It should have been:
if (strncpy_from_kernel_nofault(kstr, str, USTRING_BUF_SIZE) < 0)
>
> > return kstr;
> > }
> > @@ -818,6 +821,7 @@ static __always_inline char *test_ustring(char *str)
> > struct ustring_buffer *ubuf;
> > char __user *ustr;
> > char *kstr;
> > + int cnt;
> >
> > if (!ustring_per_cpu)
> > return NULL;
> > @@ -827,7 +831,9 @@ static __always_inline char *test_ustring(char *str)
> >
> > /* user space address? */
> > ustr = (char __user *)str;
> > - if (!strncpy_from_user_nofault(kstr, ustr, USTRING_BUF_SIZE))
This is broken too.
As this isn't relying on the other change in this patch, I'll just fix it
myself. I'm getting a pull request ready anyway.
Thanks!
-- Steve
> > + cnt = strncpy_from_user_nofault(kstr, ustr, USTRING_BUF_SIZE);
> > + /* Return null if empty string or error */
> > + if (cnt <= 1)
> > return NULL;
>
> ditto
>
> >
Powered by blists - more mailing lists