From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965578AbcBCS02 (ORCPT ); Wed, 3 Feb 2016 13:26:28 -0500 Received: from mail-yk0-f174.google.com ([209.85.160.174]:33202 "EHLO mail-yk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965227AbcBCS0Z (ORCPT ); Wed, 3 Feb 2016 13:26:25 -0500 Date: Wed, 3 Feb 2016 13:26:21 -0500 From: Jeff Layton To: William Dauchy Cc: Dmitry Vyukov , "J. Bruce Fields" , Alexander Viro , "linux-fsdevel@vger.kernel.org" , LKML , syzkaller , Kostya Serebryany , Alexander Potapenko , Sasha Levin , Eric Dumazet Subject: Re: fs: WARNING in locks_free_lock_context() Message-ID: <20160203132621.27675437@synchrony.poochiereds.net> In-Reply-To: References: <20151223085428.69ac2522@tlielax.poochiereds.net> X-Mailer: Claws Mail 3.13.1 (GTK+ 2.24.29; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 3 Feb 2016 19:19:37 +0100 William Dauchy wrote: > Hello Jeff, > > On Wed, Dec 23, 2015 at 2:54 PM, Jeff Layton wrote: > > Ooh, nice catch...and just in time for Christmas. > > > > filp_close does this after the fd has been detached from the file table > > in __close_fd: > > > > if (likely(!(filp->f_mode & FMODE_PATH))) { > > dnotify_flush(filp, id); > > locks_remove_posix(filp, id); > > } > > fput(filp); > > > > ...and fcntl_setlk does this: > > > > /* > > * Attempt to detect a close/fcntl race and recover by > > * releasing the lock that was just acquired. > > */ > > /* > > * we need that spin_lock here - it prevents reordering between > > * update of i_flctx->flc_posix and check for it done in close(). > > * rcu_read_lock() wouldn't do. > > */ > > spin_lock(¤t->files->file_lock); > > f = fcheck(fd); > > spin_unlock(¤t->files->file_lock); > > if (!error && f != filp && flock.l_type != F_UNLCK) { > > flock.l_type = F_UNLCK; > > goto again; > > } > > > > ...so in principle that should keep new locks from racing onto the list > > just after we call filp_close. Hmm...I'll see if I can reproduce and > > figure out how this could happen. > > Just wondering if you had the time to figure out this warning? > > Thanks, Yes...this commit in mainline fixes it: commit 7f3697e24dc3820b10f445a4a7d914fc356012d1 Author: Jeff Layton Date: Thu Jan 7 16:38:10 2016 -0500 locks: fix unlock when fcntl_setlk races with a close ...and the patch is applicable to all kernels currently in circulation. The original bug is very old (from 2005). -- Jeff Layton