lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5B67E76D-139B-4004-9DE0-A626026CAEB1@oracle.com>
Date:   Tue, 6 Apr 2021 15:46:34 +0000
From:   Chuck Lever III <chuck.lever@...cle.com>
To:     Huang Guobin <huangguobin4@...wei.com>,
        Bruce Fields <bfields@...ldses.org>
CC:     Jeff Layton <jlayton@...chiereds.net>,
        Linux NFS Mailing List <linux-nfs@...r.kernel.org>,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH -next] NFSD: Use DEFINE_SPINLOCK() for spinlock



> On Apr 6, 2021, at 8:08 AM, Huang Guobin <huangguobin4@...wei.com> wrote:
> 
> From: Guobin Huang <huangguobin4@...wei.com>
> 
> spinlock can be initialized automatically with DEFINE_SPINLOCK()
> rather than explicitly calling spin_lock_init().
> 
> Reported-by: Hulk Robot <hulkci@...wei.com>
> Signed-off-by: Guobin Huang <huangguobin4@...wei.com>

This same patch was sent last July, without the Reported-by:

https://lore.kernel.org/linux-nfs/1617710898-49064-1-git-send-email-huangguobin4@huawei.com/T/#u

If I'm reading the code correctly, it appears that set_max_drc()
can be called more than once by user space API functions via
nfsd_create_serv().

It seems to me we want to guarantee that nfsd_drc_lock is
initialized exactly once, and using DEFINE_SPINLOCK() would
do just that.

Likewise, re-initializing nfsd_drc_mem_used is probably not good
to do either, but clobbering a spinlock like that might lead to
a crash.

Bruce, any further thoughts?


> ---
> fs/nfsd/nfssvc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
> index b2eef4112bc2..82ba034fa579 100644
> --- a/fs/nfsd/nfssvc.c
> +++ b/fs/nfsd/nfssvc.c
> @@ -84,7 +84,7 @@ DEFINE_MUTEX(nfsd_mutex);
>  * version 4.1 DRC caches.
>  * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage.
>  */
> -spinlock_t	nfsd_drc_lock;
> +DEFINE_SPINLOCK(nfsd_drc_lock);
> unsigned long	nfsd_drc_max_mem;
> unsigned long	nfsd_drc_mem_used;
> 
> @@ -563,7 +563,6 @@ static void set_max_drc(void)
> 	nfsd_drc_max_mem = (nr_free_buffer_pages()
> 					>> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE;
> 	nfsd_drc_mem_used = 0;
> -	spin_lock_init(&nfsd_drc_lock);
> 	dprintk("%s nfsd_drc_max_mem %lu \n", __func__, nfsd_drc_max_mem);
> }
> 
> 

--
Chuck Lever



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ