Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6573298imm; Mon, 23 Jul 2018 22:18:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcuCvwqqm0nFo1MkDhfEwQn896FOCgz1g4taPyMxXWoKnHHywSN7AM0rEO1e/jXnyV1qt2D X-Received: by 2002:a17:902:8ecb:: with SMTP id x11-v6mr15891729plo.308.1532409519055; Mon, 23 Jul 2018 22:18:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532409519; cv=none; d=google.com; s=arc-20160816; b=MO6bLuJAx6zkNusWx3bYrWi2B/P6thwdW0VE8XRGVYIxpI1+k8ikEpx30Z6siPDJrv HOyp/MgQu3ys9xw2NRJQNeHrlQsRTBu7J0bamWe+v8q3juCcuovXOVwZH5/IFXrQj41T nxXKy54+KYDOWKyxeyDx6mBLbsVhS5ppqpLmUeVN46LzHNvaqthfoyQhJDoV+9LCd3Ca 8uls42s+99Gb071YlLqn5nxOVV1ERUfnKBZYYrUDpz809NBW4+phrL9H9N+KbrpoQcog BefT+d/TeupIamMqVnmQeebr5n9T0H2nVT1bUvVgEP8MG1ljvIm3cdV3dJqk87qbF293 knNA== 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:arc-authentication-results; bh=E2mbEYQoq+6U+4K6oQ8KhUdpABSy8wGP5SPdq8s+X5I=; b=zyuYOfHPFYSLfKb2Rx9/Fqs0ST/cxw1qVRINoGnnn4EwT6pHACk8Opxb8z420OGzo8 lIQwIhETMNpPgb9Aec8S1e6Owl3mq5LuaxtTSxhbVaLzga6ecSX/hZofvzF2mmDaheZn YrT1teYOhHrlNrxkBWJkGAEBCEajFoR8KLJaTyl7sMH4hiwOsX6WoQd+v00Z76RSH9de JaQrkyaB1G4+Awdop0wM/+D0Oi82eSgYhFLjTg8N9/5LT2M2Pv/+2VPkFl9crsLJ7SHE NjlvEq7776c2uP0Vp/eLUR/uKbs7UhLNIAfZ6UhhOk8ZxkIq1MH2a0jOle1TOfECi/YI W8+Q== 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 123-v6si10609888pfd.201.2018.07.23.22.18.22; Mon, 23 Jul 2018 22:18:39 -0700 (PDT) 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 S2388155AbeGXGWJ (ORCPT + 99 others); Tue, 24 Jul 2018 02:22:09 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:39052 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbeGXGWJ (ORCPT ); Tue, 24 Jul 2018 02:22:09 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fhphO-0000ao-GU; Tue, 24 Jul 2018 05:17:26 +0000 Date: Tue, 24 Jul 2018 06:17:26 +0100 From: Al Viro To: "Dae R. Jeong" Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, byoungyoung@purdue.edu, kt0755@gmail.com, bammanag@purdue.edu Subject: Re: KASAN: use-after-free Read in link_path_walk Message-ID: <20180724051726.GH30522@ZenIV.linux.org.uk> References: <20180724034542.GA19283@dragonet> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180724034542.GA19283@dragonet> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 24, 2018 at 12:45:42PM +0900, Dae R. Jeong wrote: > Diagnosis: > We think that it is possible that link_path_walk() dereferences a > freed pointer when cleanup_mnt() is executed between path_init() and > link_path_walk(). > > Since I'm not an expert on a file system and don't fully understand > the crash, please see a executed program and a crash log below in > case that my understanding is wrong. > > > Executed Program: > Thread0 Thread1 > mkdir("./file0") > |--------------------------| > | mount("./file0", "./file0", "devpts", 0x0, "") > | | > openat(AT_FDCWD, chroot("./file0") > "/dev/vcs", 0x200, 0x0) umount("./file0", 0x2) > > openat(), chroot(), umount() syscalls are executed after mount() syscall. > We think a race occurs between openat() and chroot() because RaceFuzzer > executed openat() and chroot() concurrently. > > > (Possible) Thread interleaving: > CPU0 (path_openat) CPU1 (cleanup_mnt) > ===== ===== > s = path_init(nd, flags); > if (IS_ERR(s)) { > put_filp(file); > return ERR_CAST(s); > } > > deactivate_super(mnt->mnt.mnt_sb); > > while (!(error = link_path_walk(s, nd)) && > > // (in link_path_walk()) > struct dentry *parent = nd->path.dentry; > nd->flags &= ~LOOKUP_JUMPED; > if (unlikely(parent->d_flags & DCACHE_OP_HASH)) { // UAF occured Do we have LOOKUP_RCU in nd->flags at that point? And how in hell did we get that dentry there? In LOOKUP_RCU mode no freeing should be happening until after we call rcu_read_unlock(), unless the final dput() has happened before rcu_read_lock(). In which case we shouldn't have gotten to that dentry in the first place. And in non-LOOKUP_RCU mode we are bloody well holding references to everything (vfsmount and dentry alike), so that deactivate_super() shouldn't have been called as long as we are holding that reference. Details, please. Ideally - how to reproduce that.