Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp572925imu; Thu, 3 Jan 2019 03:18:37 -0800 (PST) X-Google-Smtp-Source: ALg8bN5WVDqBbpurl2n9LJfz0w+EG4nGTbQ03bGTqFyQeT+B/qLRX55j1ikRa2HgsoEtPOv6cbNz X-Received: by 2002:a63:151f:: with SMTP id v31mr16355887pgl.34.1546514317400; Thu, 03 Jan 2019 03:18:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546514317; cv=none; d=google.com; s=arc-20160816; b=oYwI0eUKeErTQnCBTvXDl1MVBNBCvEfCjh+1gEUvklfBlqxp23R3ovA7ZuztX0Ru4a qbrp1DzSUtIgT2GJm+hkip1olDkgI4LUI9n3g+eSuPd2RfKJZWapDlQTJStk6mswBDqj X5Jvv1xrreE8Hl4g0nBohFW6BnhH9YpWnn0F9g0GwUDVyUsugdHOuc6jjY0K/M0Hfki2 vVwIpq76gi+e4QuIokH8tIp0c2t2RMJgklg7qZ5v0plZkap+8IVdKES409CXK3O9vPUZ C0peh3MGcXESpE9stVQ7A76ilA+7aZye4QVqw/67cghF3crz902zthrX3o3ELc1JChi1 PAog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ZJx0GF5XDvl3hKCapI4OWRHPvs0JSIqTuYW+z6iiDhc=; b=nwlB63Bf3EG7ssyK7VGT136oHvlwMDYzjfkeiePWp84ge7hKUuE5zzfX9X+4AIRvAE G1Envc/Ravcq6uXvvS07C+M2EFPrZJzJ4pSl0ucMDN0eo1dA0Y38rZ7NTUc0uXM2KzBT Dk+SDeKf7LbrWhXd1jLT28xhc1ckwjtsgA6coR6JQATo4aNKJvybUVJ7IPaZa54ThzP+ sPEEdTHIvji9VlC3j+fs7/p7Oi+ou6UqtLNRpGACsYziczZDUGXmfptXpuMeR84Er/xd idqha3WpDOiBB8ixisM+hvA8m5ucIrTpayPDlZpEQj97TMkxGzgb3GI6T/6xoxCcYtz1 AA+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4si28316957pgm.487.2019.01.03.03.18.21; Thu, 03 Jan 2019 03:18:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730298AbfACIsQ (ORCPT + 99 others); Thu, 3 Jan 2019 03:48:16 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:48786 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726702AbfACIsQ (ORCPT ); Thu, 3 Jan 2019 03:48:16 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.91 #2 (Red Hat Linux)) id 1geyfi-0002zp-9W; Thu, 03 Jan 2019 08:48:10 +0000 Date: Thu, 3 Jan 2019 08:48:10 +0000 From: Al Viro To: Sahitya Tummala Cc: Junxiao Bi , Joel Becker , Christoph Hellwig , linux-kernel@vger.kernel.org Subject: Re: [PATCH] configfs: Fix use-after-free when accessing sd->s_dentry Message-ID: <20190103084810.GK2217@ZenIV.linux.org.uk> References: <1546503064-12695-1-git-send-email-stummala@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1546503064-12695-1-git-send-email-stummala@codeaurora.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 03, 2019 at 01:41:04PM +0530, Sahitya Tummala wrote: > In the vfs_statx() context, during path lookup, the dentry gets > added to sd->s_dentry via configfs_attach_attr(). In the end, > vfs_statx() kills the dentry by calling path_put(), which invokes > configfs_d_iput(). Ideally, this dentry must be removed from > sd->s_dentry but it doesn't if the sd->s_count >= 3. As a result, > sd->s_dentry is holding reference to a stale dentry pointer whose > memory is already freed up. This results in use-after-free issue, > when this stale sd->s_dentry is accessed later in > configfs_readdir() path. > > This issue can be easily reproduced, by running the LTP test case - > sh fs_racer_file_list.sh /config > (https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/fs/racer/fs_racer_file_list.sh) > > Signed-off-by: Sahitya Tummala > --- > fs/configfs/dir.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c > index 39843fa..a5906c5 100644 > --- a/fs/configfs/dir.c > +++ b/fs/configfs/dir.c > @@ -66,7 +66,7 @@ static void configfs_d_iput(struct dentry * dentry, > * configfs_attach_attr and set sd->s_dentry to null > * even it's still in use. > */ > - if (atomic_read(&sd->s_count) <= 2) > + if (sd->s_dentry == dentry) > sd->s_dentry = NULL; > > spin_unlock(&configfs_dirent_lock); Please, update the comment above as well - it refers the increment of sd->s_count, which becomes stale. I agree that the problem is real and the fix is sane (and that's what should've been done in the first place, back in "configfs: fix race between dentry put and lookup", which has introduced that logics).