Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1618921 > unrolled thread

[PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec

Started byLiping Zhang <zlpnobody@163.com>
First post2017-04-07 18:00 +0200
Last post2017-04-08 19:30 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec Liping Zhang <zlpnobody@163.com> - 2017-04-07 18:00 +0200
    Re: [PATCH 3/3] sysctl: report EINVAL if value is larger than  UINT_MAX for proc_douintvec Linus Torvalds <torvalds@linux-foundation.org> - 2017-04-07 19:00 +0200
      Re: [PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec ebiederm@xmission.com (Eric W. Biederman) - 2017-04-07 23:10 +0200
        Re: [PATCH 3/3] sysctl: report EINVAL if value is larger than  UINT_MAX for proc_douintvec Linus Torvalds <torvalds@linux-foundation.org> - 2017-04-08 19:30 +0200

#1618921 — [PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec

FromLiping Zhang <zlpnobody@163.com>
Date2017-04-07 18:00 +0200
Subject[PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec
Message-ID<ttEsN-K9-3@gated-at.bofh.it>
From: Liping Zhang <zlpnobody@gmail.com>

Currently, inputting the following command will succeed but actually the
value will be truncated:
  # echo 0x12ffffffff > /proc/sys/net/ipv4/tcp_notsent_lowat

This is not friendly to the user, so instead, we should report error
when the value is larger than UINT_MAX.

Fixes: e7d316a02f68 ("sysctl: handle error writing UINT_MAX to u32 fields")
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
---
 kernel/sysctl.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 8cca4c7..e8d1ed0 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2133,6 +2133,8 @@ static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
 	if (write) {
 		if (*negp)
 			return -EINVAL;
+		if (*lvalp > (unsigned long) UINT_MAX)
+			return -EINVAL;
 		*valp = *lvalp;
 	} else {
 		unsigned int val = *valp;
-- 
2.5.5

[toc] | [next] | [standalone]


#1618974 — Re: [PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec

FromLinus Torvalds <torvalds@linux-foundation.org>
Date2017-04-07 19:00 +0200
SubjectRe: [PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec
Message-ID<ttFoT-1r2-45@gated-at.bofh.it>
In reply to#1618921
On Fri, Apr 7, 2017 at 8:51 AM, Liping Zhang <zlpnobody@163.com> wrote:
> From: Liping Zhang <zlpnobody@gmail.com>
>
> Currently, inputting the following command will succeed but actually the
> value will be truncated:
>   # echo 0x12ffffffff > /proc/sys/net/ipv4/tcp_notsent_lowat
>
> This is not friendly to the user, so instead, we should report error
> when the value is larger than UINT_MAX.

I applied the two other patches, but I didn't apply this one.

It's entirely possible that people end up doing something like

   echo -1 > /proc/sys/some_random_uint

because that's a fairly normal thing to do to set all bits. Making
that an error seems wrong.

                 Linus

[toc] | [prev] | [next] | [standalone]


#1619104

Fromebiederm@xmission.com (Eric W. Biederman)
Date2017-04-07 23:10 +0200
Message-ID<ttJiN-4zq-15@gated-at.bofh.it>
In reply to#1618974
Linus Torvalds <torvalds@linux-foundation.org> writes:

> On Fri, Apr 7, 2017 at 8:51 AM, Liping Zhang <zlpnobody@163.com> wrote:
>> From: Liping Zhang <zlpnobody@gmail.com>
>>
>> Currently, inputting the following command will succeed but actually the
>> value will be truncated:
>>   # echo 0x12ffffffff > /proc/sys/net/ipv4/tcp_notsent_lowat
>>
>> This is not friendly to the user, so instead, we should report error
>> when the value is larger than UINT_MAX.
>
> I applied the two other patches, but I didn't apply this one.
>
> It's entirely possible that people end up doing something like
>
>    echo -1 > /proc/sys/some_random_uint
>
> because that's a fairly normal thing to do to set all bits. Making
> that an error seems wrong.

Except that doesn't help in this case.  The function do_uintvec_conv
rules already rejects all negative values on write.  So -1 is already
rejected.

In fact the function proc_douintvec_conv has always rejected negative
values so this change won't even create a regression.

So it looks perfectly reasonable to reject values that are simply too
large to be written to the uint.

So even today to write all bits set you do have to do:

   echo 0xffffffff > /proc/sys/some_random_uint

Eric

[toc] | [prev] | [next] | [standalone]


#1619346 — Re: [PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec

FromLinus Torvalds <torvalds@linux-foundation.org>
Date2017-04-08 19:30 +0200
SubjectRe: [PATCH 3/3] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec
Message-ID<tu2ls-8cD-19@gated-at.bofh.it>
In reply to#1619104
On Fri, Apr 7, 2017 at 2:01 PM, Eric W. Biederman <ebiederm@xmission.com> wrote:
>
> Except that doesn't help in this case.  The function do_uintvec_conv
> rules already rejects all negative values on write.  So -1 is already
> rejected.

Oh, I should have noticed that.

So yes, that patch looks good too. Will apply.

             Linus

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web