* [PATCH] lkdtm: use the return value of strim()
@ 2023-08-17 14:21 GONG, Ruiqi
2023-08-17 16:55 ` Kees Cook
2023-08-22 12:03 ` Greg Kroah-Hartman
0 siblings, 2 replies; 5+ messages in thread
From: GONG, Ruiqi @ 2023-08-17 14:21 UTC (permalink / raw)
To: Kees Cook, Arnd Bergmann, Greg Kroah-Hartman, linux-kernel; +Cc: gongruiqi1
From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
Make use of the return value of strim() to achieve left-trim as well as
right-trim, which prevents the following unusual fail case:
# echo " EXCEPTION" > /sys/kernel/debug/provoke-crash/DIRECT
sh: write error: Invalid argument
Link: https://github.com/KSPP/linux/issues/337
Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
---
drivers/misc/lkdtm/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
index 0772e4a4757e..812c96461ab2 100644
--- a/drivers/misc/lkdtm/core.c
+++ b/drivers/misc/lkdtm/core.c
@@ -242,7 +242,7 @@ static ssize_t lkdtm_debugfs_entry(struct file *f,
}
/* NULL-terminate and remove enter */
buf[count] = '\0';
- strim(buf);
+ buf = strim(buf);
crashtype = find_crashtype(buf);
free_page((unsigned long)buf);
@@ -318,7 +318,7 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf,
}
/* NULL-terminate and remove enter */
buf[count] = '\0';
- strim(buf);
+ buf = strim(buf);
crashtype = find_crashtype(buf);
free_page((unsigned long) buf);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] lkdtm: use the return value of strim()
2023-08-17 14:21 [PATCH] lkdtm: use the return value of strim() GONG, Ruiqi
@ 2023-08-17 16:55 ` Kees Cook
2023-08-18 2:39 ` GONG, Ruiqi
2023-08-22 12:03 ` Greg Kroah-Hartman
1 sibling, 1 reply; 5+ messages in thread
From: Kees Cook @ 2023-08-17 16:55 UTC (permalink / raw)
To: GONG, Ruiqi; +Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel, gongruiqi1
On Thu, Aug 17, 2023 at 10:21:17PM +0800, GONG, Ruiqi wrote:
> From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
>
> Make use of the return value of strim() to achieve left-trim as well as
> right-trim, which prevents the following unusual fail case:
>
> # echo " EXCEPTION" > /sys/kernel/debug/provoke-crash/DIRECT
> sh: write error: Invalid argument
>
> Link: https://github.com/KSPP/linux/issues/337
> Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
> ---
> drivers/misc/lkdtm/core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
> index 0772e4a4757e..812c96461ab2 100644
> --- a/drivers/misc/lkdtm/core.c
> +++ b/drivers/misc/lkdtm/core.c
> @@ -242,7 +242,7 @@ static ssize_t lkdtm_debugfs_entry(struct file *f,
> }
> /* NULL-terminate and remove enter */
> buf[count] = '\0';
> - strim(buf);
> + buf = strim(buf);
>
> crashtype = find_crashtype(buf);
> free_page((unsigned long)buf);
Will free_page() still work in this case, though? The address won't
match the allocation any more...
-Kees
> @@ -318,7 +318,7 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf,
> }
> /* NULL-terminate and remove enter */
> buf[count] = '\0';
> - strim(buf);
> + buf = strim(buf);
>
> crashtype = find_crashtype(buf);
> free_page((unsigned long) buf);
> --
> 2.25.1
>
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lkdtm: use the return value of strim()
2023-08-17 16:55 ` Kees Cook
@ 2023-08-18 2:39 ` GONG, Ruiqi
2023-08-18 10:44 ` Heiko Carstens
0 siblings, 1 reply; 5+ messages in thread
From: GONG, Ruiqi @ 2023-08-18 2:39 UTC (permalink / raw)
To: Kees Cook; +Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel, gongruiqi1
On 2023/08/18 0:55, Kees Cook wrote:
> On Thu, Aug 17, 2023 at 10:21:17PM +0800, GONG, Ruiqi wrote:
>> From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
>>
>> Make use of the return value of strim() to achieve left-trim as well as
>> right-trim, which prevents the following unusual fail case:
>>
>> # echo " EXCEPTION" > /sys/kernel/debug/provoke-crash/DIRECT
>> sh: write error: Invalid argument
>>
>> Link: https://github.com/KSPP/linux/issues/337
>> Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
>> ---
>> drivers/misc/lkdtm/core.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
>> index 0772e4a4757e..812c96461ab2 100644
>> --- a/drivers/misc/lkdtm/core.c
>> +++ b/drivers/misc/lkdtm/core.c
>> @@ -242,7 +242,7 @@ static ssize_t lkdtm_debugfs_entry(struct file *f,
>> }
>> /* NULL-terminate and remove enter */
>> buf[count] = '\0';
>> - strim(buf);
>> + buf = strim(buf);
>>
>> crashtype = find_crashtype(buf);
>> free_page((unsigned long)buf);
>
> Will free_page() still work in this case, though? The address won't
> match the allocation any more...
Yes I noticed that, but I was under the impression that it's fine to do
free_page(paddr + offset_in_page) since the offset is within the page,
and its corresponding struct page can still be found when being freed.
Please let me know if this thought is wrong and I will submit another
version.
>
> -Kees
>
>> @@ -318,7 +318,7 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf,
>> }
>> /* NULL-terminate and remove enter */
>> buf[count] = '\0';
>> - strim(buf);
>> + buf = strim(buf);
>>
>> crashtype = find_crashtype(buf);
>> free_page((unsigned long) buf);
>> --
>> 2.25.1
>>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lkdtm: use the return value of strim()
2023-08-18 2:39 ` GONG, Ruiqi
@ 2023-08-18 10:44 ` Heiko Carstens
0 siblings, 0 replies; 5+ messages in thread
From: Heiko Carstens @ 2023-08-18 10:44 UTC (permalink / raw)
To: GONG, Ruiqi
Cc: Kees Cook, Arnd Bergmann, Greg Kroah-Hartman, linux-kernel,
gongruiqi1
On Fri, Aug 18, 2023 at 10:39:06AM +0800, GONG, Ruiqi wrote:
>
> On 2023/08/18 0:55, Kees Cook wrote:
> > On Thu, Aug 17, 2023 at 10:21:17PM +0800, GONG, Ruiqi wrote:
> >> From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
> >>
> >> Make use of the return value of strim() to achieve left-trim as well as
> >> right-trim, which prevents the following unusual fail case:
> >>
> >> # echo " EXCEPTION" > /sys/kernel/debug/provoke-crash/DIRECT
> >> sh: write error: Invalid argument
...
> >> /* NULL-terminate and remove enter */
> >> buf[count] = '\0';
> >> - strim(buf);
> >> + buf = strim(buf);
> >>
> >> crashtype = find_crashtype(buf);
> >> free_page((unsigned long)buf);
> >
> > Will free_page() still work in this case, though? The address won't
> > match the allocation any more...
>
> Yes I noticed that, but I was under the impression that it's fine to do
> free_page(paddr + offset_in_page) since the offset is within the page,
> and its corresponding struct page can still be found when being freed.
> Please let me know if this thought is wrong and I will submit another
> version.
The question is rather why you think this patch makes any sense at
all. Nobody is doing what you described above - hence there is no
problem. The comments in the code even say strim() is used to remove the
trailing '\n'. If anybody passes a string with whitespace at the beginning
then that's just a user error.
There really is no point in patches like this.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lkdtm: use the return value of strim()
2023-08-17 14:21 [PATCH] lkdtm: use the return value of strim() GONG, Ruiqi
2023-08-17 16:55 ` Kees Cook
@ 2023-08-22 12:03 ` Greg Kroah-Hartman
1 sibling, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2023-08-22 12:03 UTC (permalink / raw)
To: GONG, Ruiqi; +Cc: Kees Cook, Arnd Bergmann, linux-kernel, gongruiqi1
On Thu, Aug 17, 2023 at 10:21:17PM +0800, GONG, Ruiqi wrote:
> From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
>
> Make use of the return value of strim() to achieve left-trim as well as
> right-trim, which prevents the following unusual fail case:
>
> # echo " EXCEPTION" > /sys/kernel/debug/provoke-crash/DIRECT
> sh: write error: Invalid argument
And that is correct, don't use leading whitespace, the kernel is not
there to parse it away :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-22 12:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-17 14:21 [PATCH] lkdtm: use the return value of strim() GONG, Ruiqi
2023-08-17 16:55 ` Kees Cook
2023-08-18 2:39 ` GONG, Ruiqi
2023-08-18 10:44 ` Heiko Carstens
2023-08-22 12:03 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox