From: "J. Bruce Fields" <bfields@fieldses.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>,
Artur Molchanov <arturmolchanov@gmail.com>,
Anna Schumaker <anna.schumaker@netapp.com>,
Chuck Lever <chuck.lever@oracle.com>,
Jakub Kicinski <kuba@kernel.org>,
linux-nfs@vger.kernel.org, kernel-janitors@vger.kernel.org,
Colin King <colin.king@canonical.com>
Subject: Re: [PATCH] net/sunrpc: clean up error checking in proc_do_xprt()
Date: Fri, 06 Nov 2020 20:33:16 +0000 [thread overview]
Message-ID: <20201106203316.GA26028@fieldses.org> (raw)
In-Reply-To: <20201027141758.GA3488087@mwanda>
On Tue, Oct 27, 2020 at 05:17:58PM +0300, Dan Carpenter wrote:
> There are three changes but none of them should affect run time:
>
> 1) You can't write to this file because the permissions are 0444. But
> it sort of looked like you could do a write and it would result in
> a read. Then it looked like proc_sys_call_handler() just ignored
> it. Which is confusing. It's more clear if the "write" just
> returns zero.
> 2) The "lenp" pointer is never NULL so that check can be removed.
> 3) In the original code, the "if (*lenp < 0)" check didn't work because
> "*lenp" is unsigned. Fortunately, the memory_read_from_buffer()
> call will never fail in this context so it doesn't affect runtime.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> net/sunrpc/sysctl.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/net/sunrpc/sysctl.c b/net/sunrpc/sysctl.c
> index a18b36b5422d..04526bab4a06 100644
> --- a/net/sunrpc/sysctl.c
> +++ b/net/sunrpc/sysctl.c
> @@ -63,19 +63,19 @@ static int proc_do_xprt(struct ctl_table *table, int write,
> void *buffer, size_t *lenp, loff_t *ppos)
> {
> char tmpbuf[256];
> - size_t len;
> + ssize_t len;
>
> - if ((*ppos && !write) || !*lenp) {
> - *lenp = 0;
> + *lenp = 0;
> +
> + if (write || *ppos)
> return 0;
> - }
> +
> len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
> - *lenp = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
> + len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
Except now we're passing *lenp = 0, that can't be right.
Though I actually kind of prefer this to Colin King's patch which just
casts (*lenp) in the comparison below.
--b.
> + if (len < 0)
> + return len;
>
> - if (*lenp < 0) {
> - *lenp = 0;
> - return -EINVAL;
> - }
> + *lenp = len;
> return 0;
> }
>
> --
> 2.28.0
WARNING: multiple messages have this Message-ID (diff)
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>,
Artur Molchanov <arturmolchanov@gmail.com>,
Anna Schumaker <anna.schumaker@netapp.com>,
Chuck Lever <chuck.lever@oracle.com>,
Jakub Kicinski <kuba@kernel.org>,
linux-nfs@vger.kernel.org, kernel-janitors@vger.kernel.org,
Colin King <colin.king@canonical.com>
Subject: Re: [PATCH] net/sunrpc: clean up error checking in proc_do_xprt()
Date: Fri, 6 Nov 2020 15:33:16 -0500 [thread overview]
Message-ID: <20201106203316.GA26028@fieldses.org> (raw)
In-Reply-To: <20201027141758.GA3488087@mwanda>
On Tue, Oct 27, 2020 at 05:17:58PM +0300, Dan Carpenter wrote:
> There are three changes but none of them should affect run time:
>
> 1) You can't write to this file because the permissions are 0444. But
> it sort of looked like you could do a write and it would result in
> a read. Then it looked like proc_sys_call_handler() just ignored
> it. Which is confusing. It's more clear if the "write" just
> returns zero.
> 2) The "lenp" pointer is never NULL so that check can be removed.
> 3) In the original code, the "if (*lenp < 0)" check didn't work because
> "*lenp" is unsigned. Fortunately, the memory_read_from_buffer()
> call will never fail in this context so it doesn't affect runtime.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> net/sunrpc/sysctl.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/net/sunrpc/sysctl.c b/net/sunrpc/sysctl.c
> index a18b36b5422d..04526bab4a06 100644
> --- a/net/sunrpc/sysctl.c
> +++ b/net/sunrpc/sysctl.c
> @@ -63,19 +63,19 @@ static int proc_do_xprt(struct ctl_table *table, int write,
> void *buffer, size_t *lenp, loff_t *ppos)
> {
> char tmpbuf[256];
> - size_t len;
> + ssize_t len;
>
> - if ((*ppos && !write) || !*lenp) {
> - *lenp = 0;
> + *lenp = 0;
> +
> + if (write || *ppos)
> return 0;
> - }
> +
> len = svc_print_xprts(tmpbuf, sizeof(tmpbuf));
> - *lenp = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
> + len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len);
Except now we're passing *lenp = 0, that can't be right.
Though I actually kind of prefer this to Colin King's patch which just
casts (*lenp) in the comparison below.
--b.
> + if (len < 0)
> + return len;
>
> - if (*lenp < 0) {
> - *lenp = 0;
> - return -EINVAL;
> - }
> + *lenp = len;
> return 0;
> }
>
> --
> 2.28.0
next prev parent reply other threads:[~2020-11-06 20:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <031F93AC-744F-4E02-9948-1C1F5939714B@gmail.com>
2020-10-27 14:17 ` [PATCH] net/sunrpc: clean up error checking in proc_do_xprt() Dan Carpenter
2020-10-27 14:17 ` Dan Carpenter
2020-11-06 20:33 ` J. Bruce Fields [this message]
2020-11-06 20:33 ` J. Bruce Fields
2020-11-06 20:59 ` J. Bruce Fields
2020-11-06 20:59 ` J. Bruce Fields
2020-11-09 9:10 ` Dan Carpenter
2020-11-09 9:10 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201106203316.GA26028@fieldses.org \
--to=bfields@fieldses.org \
--cc=anna.schumaker@netapp.com \
--cc=arturmolchanov@gmail.com \
--cc=chuck.lever@oracle.com \
--cc=colin.king@canonical.com \
--cc=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@hammerspace.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.