From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752824AbdJGKhC (ORCPT ); Sat, 7 Oct 2017 06:37:02 -0400 Received: from mail-qt0-f173.google.com ([209.85.216.173]:44528 "EHLO mail-qt0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750952AbdJGKhA (ORCPT ); Sat, 7 Oct 2017 06:37:00 -0400 X-Google-Smtp-Source: AOwi7QCjpoCp7WVCjbpAY29QqAm1eCV+il5fXbSGwsFOfHV/LIL6Xi2GuPU+vkw43oLIYlt6a2mpcA== Message-ID: <1507372617.26934.0.camel@redhat.com> Subject: Re: [PATCH] fs/afs/flock and fs/locks: Fix possible sleep-in-atomic bugs in posix_lock_file From: Jeff Layton To: Jia-Ju Bai , dhowells@redhat.com, viro@zeniv.linux.org.uk, bfields@fieldses.org Cc: linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Date: Sat, 07 Oct 2017 06:36:57 -0400 In-Reply-To: <1507370104-21751-1-git-send-email-baijiaju1990@163.com> References: <1507370104-21751-1-git-send-email-baijiaju1990@163.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.24.5 (3.24.5-1.fc26) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2017-10-07 at 17:55 +0800, Jia-Ju Bai wrote: > The kernel may sleep under a spinlock, and the function call paths are: > afs_do_unlk (acquire the spinlock) > posix_lock_file > posix_lock_inode (fs/locks.c) > locks_get_lock_context > kmem_cache_alloc(GFP_KERNEL) --> may sleep > > afs_do_setlk (acquire the spinlock) > posix_lock_file > posix_lock_inode (fs/locks.c) > locks_get_lock_context > kmem_cache_alloc(GFP_KERNEL) --> may sleep > > To fix them, GFP_KERNEL is replaced with GFP_ATOMIC. > These bugs are found by my static analysis tool and my code review. > > Signed-off-by: Jia-Ju Bai > --- > fs/locks.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/locks.c b/fs/locks.c > index 1bd71c4..975cc62 100644 > --- a/fs/locks.c > +++ b/fs/locks.c > @@ -222,7 +222,7 @@ struct file_lock_list_struct { > if (likely(ctx) || type == F_UNLCK) > goto out; > > - ctx = kmem_cache_alloc(flctx_cache, GFP_KERNEL); > + ctx = kmem_cache_alloc(flctx_cache, GFP_ATOMIC); > if (!ctx) > goto out; > NAK This needs to be fixed in the AFS code. It should not be calling these functions with a spinlock held. -- Jeff Layton