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


Groups > linux.kernel > #1569724

Re: [PATCH] sysctl: add proper unsigned int support

From Alexey Dobriyan <adobriyan@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] sysctl: add proper unsigned int support
Date 2017-01-30 14:10 +0100
Message-ID <t5jSy-4oc-31@gated-at.bofh.it> (permalink)
References <t54gO-3cc-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sun, Jan 29, 2017 at 10:29 PM, Luis R. Rodriguez <mcgrof@kernel.org> wrote:
> Commit e7d316a02f6838 ("sysctl: handle error writing UINT_MAX to u32 fields")
> added proc_douintvec() to start help adding support for unsigned int,
> this however was only half the work needed, all these issues are present
> with the current implementation:
>
>   o Printing the values shows a negative value, this happens
>     since do_proc_dointvec() and this uses proc_put_long()
>   o We can easily wrap around the int values: UINT_MAX is
>     4294967295, if we echo in 4294967295 + 1 we end up with 0,
>     using 4294967295 + 2 we end up with 1.
>  o We echo negative values in and they are accepted
>
> Fix all these issues by adding our own do_proc_douintvec().
>
> Cc: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Fixes: e7d316a02f68 ("sysctl: handle error writing UINT_MAX to u32 fields")
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
>
> I split this off as its own atomic fix from a larger RFC series [0].
> I've only provided the fix here, and split off further functionality
> into a separate patch for the future. Although this is a fix I don't think
> its super critical, and specially due to its size do not think it can
> be stable material.
>
> I do have proc_douintvec_minmax() but since we have no users for it
> it can wait until I add something that makes use of it. If someone
> needs it now though please let me know.
>
> Likewise adding proc_douintvec_minmax_sysadmin() is very trivial but I have no
> immediate users for it so it can wait even longer.
>
> [0] https://lkml.kernel.org/r/20161208184801.1689-1-mcgrof@kernel.org
>
>  kernel/sysctl.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 115 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 8dbaec0e4f7f..118341d3a139 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -2125,12 +2125,12 @@ static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
>         return 0;
>  }
>
> -static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
> -                                int *valp,
> -                                int write, void *data)
> +static int do_proc_douintvec_conv(unsigned long *lvalp,
> +                                 unsigned int *valp,
> +                                 int write, void *data)
>  {
>         if (write) {
> -               if (*negp)
> +               if (*lvalp > (unsigned long) UINT_MAX)

Cast is unnecessary here.

> +static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,

> +       for (; left && vleft--; i++, first=false) {

I'd suggest to not implement "array of unsigned int" unless
such sysctl already exists. Much of the complexity arises from this case.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] sysctl: add proper unsigned int support "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-01-29 21:30 +0100
  Re: [PATCH] sysctl: add proper unsigned int support Alexey Dobriyan <adobriyan@gmail.com> - 2017-01-30 14:10 +0100
    Re: [PATCH] sysctl: add proper unsigned int support "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-01 21:00 +0100
      Re: [PATCH] sysctl: add proper unsigned int support "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-09 02:40 +0100
      Re: [PATCH] sysctl: add proper unsigned int support "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-09 02:50 +0100
        [PATCH v2 5/9] test_sysctl: add generic script to expand on tests "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100
        [PATCH v2 9/9] test_sysctl: test against int proc_dointvec() array support "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100
        [PATCH v2 4/9] test_sysctl: add dedicated proc sysctl test driver "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100
        [PATCH v2 6/9] test_sysctl: test against PAGE_SIZE for int "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100
        [PATCH v2 1/9] sysctl: fix lax sysctl_check_table() sanity check "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100
        [PATCH v2 2/9] sysctl: add proper unsigned int support "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100
        [PATCH v2 3/9] sysctl: add unsigned int range support "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100
        [PATCH v2 7/9] test_sysctl: add simple proc_dointvec() case "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100
        [PATCH v2 0/9] sysctl: add and fix proper unsigned int support "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100
          [PATCH v2 8/9] test_sysctl: add simple proc_douintvec() case "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-02-11 01:40 +0100

csiph-web