Re: [PATCH] fs: nfs: Fix a sleep-in-atomic bug in nfs_access_add_cache

From: Trond Myklebust
Date: Mon Jun 05 2017 - 07:48:50 EST


On Mon, 2017-06-05 at 16:05 +0800, Jia-Ju Bai wrote:
> The driver may sleep under a rcu read lock, and function call path
> is:
> nfs_permission (acquire the lock by rcu_read_lock)
> Â nfs_do_access
> ÂÂÂÂnfs_access_add_cache
> ÂÂÂÂÂÂkmalloc(GFP_KERNEL) --> may sleep
>
> To fix it, "GFP_KERNEL" is replaced with "GFP_ATOMIC".
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@xxxxxxx>
> ---
> Âfs/nfs/dir.c |ÂÂÂÂ2 +-
> Â1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> index 32ccd77..7a074db 100644
> --- a/fs/nfs/dir.c
> +++ b/fs/nfs/dir.c
> @@ -2333,7 +2333,7 @@ static void nfs_access_add_rbtree(struct inode
> *inode, struct nfs_access_entry *
> Â
> Âvoid nfs_access_add_cache(struct inode *inode, struct
> nfs_access_entry *set)
> Â{
> - struct nfs_access_entry *cache = kmalloc(sizeof(*cache),
> GFP_KERNEL);
> + struct nfs_access_entry *cache = kmalloc(sizeof(*cache),
> GFP_ATOMIC);
> Â if (cache == NULL)
> Â return;
> Â RB_CLEAR_NODE(&cache->rb_node);

The RCU locked codepath will not ever hit nfs_access_add_rbtree(). It
returns with an error code of -ECHILD after the test of "may_block".

Cheers
Trond
--
Trond Myklebust
Linux NFS client maintainer, PrimaryData
trond.myklebust@xxxxxxxxxxxxxxx