public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: Joel Granados <joel.granados@kernel.org>
Cc: nicolas.bouchinet@clip-os.org, linux-kernel@vger.kernel.org,
	linux-rdma@vger.kernel.org, linux-scsi@vger.kernel.org,
	codalist@coda.cs.cmu.edu, linux-nfs@vger.kernel.org,
	Nicolas Bouchinet <nicolas.bouchinet@ssi.gouv.fr>,
	Joel Granados <j.granados@samsung.com>,
	Clemens Ladisch <clemens@ladisch.de>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
	"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Jan Harkes <jaharkes@cs.cmu.edu>,
	Jeff Layton <jlayton@kernel.org>, Neil Brown <neilb@suse.de>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	Trond Myklebust <trondmy@kernel.org>,
	Anna Schumaker <anna@kernel.org>,
	Bart Van Assche <bvanassche@acm.org>,
	Zhu Yanjun <yanjun.zhu@linux.dev>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>
Subject: Re: [PATCH v2 2/6] sysctl: Fixes nsm_local_state bounds
Date: Mon, 3 Mar 2025 16:20:28 -0500	[thread overview]
Message-ID: <515031cd-2e25-4ae7-b0b3-5ddfda4e7bb3@oracle.com> (raw)
In-Reply-To: <42t2lpwwwihg4heu4ogudt4fe5uz7trg3y2lsoqvmjnzmhnjmy@pebnborzqodv>

On 3/3/25 9:12 AM, Joel Granados wrote:
> On Mon, Feb 24, 2025 at 09:38:17AM -0500, Chuck Lever wrote:
>> On 2/24/25 4:58 AM, nicolas.bouchinet@clip-os.org wrote:
>>> From: Nicolas Bouchinet <nicolas.bouchinet@ssi.gouv.fr>
>>>
>>> Bound nsm_local_state sysctl writings between SYSCTL_ZERO
>>> and SYSCTL_INT_MAX.
>>>
>>> The proc_handler has thus been updated to proc_dointvec_minmax.
>>>
>>> Signed-off-by: Nicolas Bouchinet <nicolas.bouchinet@ssi.gouv.fr>
>>> ---
>>>  fs/lockd/svc.c | 4 +++-
>>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
>>> index 2c8eedc6c2cc9..984ab233af8b6 100644
>>> --- a/fs/lockd/svc.c
>>> +++ b/fs/lockd/svc.c
>>> @@ -461,7 +461,9 @@ static const struct ctl_table nlm_sysctls[] = {
>>>  		.data		= &nsm_local_state,
>>>  		.maxlen		= sizeof(int),
>>>  		.mode		= 0644,
>>> -		.proc_handler	= proc_dointvec,
>>> +		.proc_handler	= proc_dointvec_minmax,
>>> +		.extra1		= SYSCTL_ZERO,
>>> +		.extra2		= SYSCTL_INT_MAX,
>>>  	},
>>>  };
>>>  
>>
>> Hi Nicolas -
>>
>> nsm_local_state is an unsigned 32-bit integer. The type of that value is
>> defined by spec, because this value is exchanged between peers on the
>> network.
>>
>> Perhaps this patch should replace proc_dointvec with proc_douintvec
>> instead.
> As Nicolas stated, that is completely up to how you used the variable.
> 
> Things to notice:
> 1. If you want the full range of a unsigned long, then you should stop
>    using proc_dointvec as it will upper limit the value to INT_MAX.
> 2. If you want to keep using nsm_local_state as unsigned int, then
>    please add SYSCTL_ZERO as a lower bound to avoid assigning negative
>    values
> 3. Having SYSCTL_INT_MAX is not necessary as it is already capped by
>    proc_dointvec{_minmax,}, but it is nice to have as it makes explicit
>    what is happening.
> 
> Let me know if you take this through your trees so I can remove it from
> sysctl.
> 
> Reviewed-by: Joel Granados <joel.granados@kernel.org>

The variable "nsm_local_state" is declared as "u32".

The range of the value of nsm_local_state is supposed to be 0 -
UINT_MAX (ie, an unsigned 32-bit integer), so I'm proposing:

 		.data		= &nsm_local_state,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
+		.proc_handler	= proc_douintvec,
 	},
 };

But I suspect that the "maxlen" field should be changed to something
like "sizeof(nsm_local_state)".

Does that seem correct to you?

I can take this patch through the NFSD tree so it can get some NFS-
specific testing.

-- 
Chuck Lever

  reply	other threads:[~2025-03-03 21:21 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24  9:58 [PATCH v2 0/6] Fixes multiple sysctl bound checks nicolas.bouchinet
2025-02-24  9:58 ` [PATCH v2 1/6] sysctl: Fixes idmap_cache_timeout bounds nicolas.bouchinet
2025-02-24  9:58 ` [PATCH v2 2/6] sysctl: Fixes nsm_local_state bounds nicolas.bouchinet
2025-02-24 14:38   ` Chuck Lever
2025-02-25 10:37     ` Nicolas Bouchinet
2025-03-03 14:12     ` Joel Granados
2025-03-03 21:20       ` Chuck Lever [this message]
2025-03-03 21:42   ` cel
2025-03-05 14:49     ` Joel Granados
2025-02-24  9:58 ` [PATCH v2 3/6] sysctl/coda: Fixes timeout bounds nicolas.bouchinet
2025-03-03 14:15   ` Joel Granados
2025-03-03 14:39     ` Jan Harkes
2025-03-05 14:47       ` Joel Granados
2025-03-06 10:40         ` Nicolas Bouchinet
2025-02-24  9:58 ` [PATCH v2 4/6] sysctl: Fixes scsi_logging_level bounds nicolas.bouchinet
2025-02-25  1:20   ` Martin K. Petersen
2025-02-25 10:47     ` Nicolas Bouchinet
2025-03-03 14:04       ` Joel Granados
2025-03-04  2:24         ` Martin K. Petersen
2025-03-05 14:44           ` Joel Granados
2025-02-24  9:58 ` [PATCH v2 5/6] sysctl/infiniband: Fixes infiniband sysctl bounds nicolas.bouchinet
2025-02-24 13:41   ` Leon Romanovsky
2025-03-03 13:57     ` Joel Granados
2025-03-03 18:53       ` Leon Romanovsky
2025-03-05 14:43         ` Joel Granados
2025-02-25  7:27   ` Zhu Yanjun
2025-02-24  9:58 ` [PATCH v2 6/6] sysctl: Fixes max-user-freq bounds nicolas.bouchinet
2025-03-03 13:52 ` [PATCH v2 0/6] Fixes multiple sysctl bound checks Joel Granados
2025-03-11  1:19 ` (subset) " Martin K. Petersen

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=515031cd-2e25-4ae7-b0b3-5ddfda4e7bb3@oracle.com \
    --to=chuck.lever@oracle.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=anna@kernel.org \
    --cc=arnd@arndb.de \
    --cc=brauner@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=clemens@ladisch.de \
    --cc=codalist@coda.cs.cmu.edu \
    --cc=gregkh@linuxfoundation.org \
    --cc=j.granados@samsung.com \
    --cc=jaharkes@cs.cmu.edu \
    --cc=jgg@ziepe.ca \
    --cc=jlayton@kernel.org \
    --cc=joel.granados@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=neilb@suse.de \
    --cc=nicolas.bouchinet@clip-os.org \
    --cc=nicolas.bouchinet@ssi.gouv.fr \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yanjun.zhu@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox