Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3794298img; Mon, 25 Mar 2019 18:40:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVK+MjIHl/1GDhYOa2fAPZB86d1zxI2Oanf7/cx1CytC0reHlVzRpAtU5KtDcejPw5VKzK X-Received: by 2002:a17:902:9a09:: with SMTP id v9mr28045677plp.225.1553564450698; Mon, 25 Mar 2019 18:40:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553564450; cv=none; d=google.com; s=arc-20160816; b=Wex/5HLtgxRMyNouGHqBuaor8JoKYeAa2Bg9Iu+CQ9BiEK/Gi+/gv+Rg5sAjIIjqD6 PRsNqWen4SLc9wguUWNWguXWKHqarki+qXrvHpAdWodBp7CUgRg1GPeyXKj7UBOLZf2f 1/2zvVHdMJ4Pjkiny9qFevPkc3jvqLr6nuIpMs76xbqVS9ZHiVcSqpN4l191/0542A3l U3fqkc1QKSDi8BHTP6JV5mF96/LLlrno20r3jbxok7R11YFWAT8qDfnoRWjmyXKRcOWj 4QFDxcpBRz9nc2nV7ac/WPPWu/1mx0M/7wsD5BGxeV7xMxYckt3QKaobdNquIx6d1FjY 0yHQ== 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=/rdGLVVqfF9fob7LijeBLAWWMZ/bqALPHytEDkNCo98=; b=P8fLlIJ5XgbRgtVnyjUIp4Tqd8yrpKYZobn5B+gzeeJd+22BQiZ1pcqsJW6NVG2jqM 93c6EPQ+zPiAcTsptTYCaqZltWEfGC10ifcDKQ0z/Wo1TZgWLz3DWF7HM7CH/kZKWMRw ae+VX1ln/oG/iuK5ajb15Cp+MxMM0Aw6JeFeuNwlC6JNdUAc7M76KTcdud9tE5LZiXxy uPmaVD/OXhkywAvXobyh0VR+W2j//emxJHAXwZqEhTVNRIW3gL6AOsq/wxyZpKv5MLQU 7/Dj69tV44Ke0b+8I7CLcW1+AcnOaSP2h9dETfCbadm0E1pZVpdv4b7vs4g7/K+oDudN zpcg== 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 59si16080043plp.100.2019.03.25.18.40.35; Mon, 25 Mar 2019 18:40:50 -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 S1730703AbfCZBjy (ORCPT + 99 others); Mon, 25 Mar 2019 21:39:54 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:58624 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727412AbfCZBjy (ORCPT ); Mon, 25 Mar 2019 21:39:54 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92 #3 (Red Hat Linux)) id 1h8b4A-0004XR-65; Tue, 26 Mar 2019 01:39:50 +0000 Date: Tue, 26 Mar 2019 01:39:50 +0000 From: Al Viro To: Linus Torvalds Cc: syzbot , Alexei Starovoitov , Daniel Borkmann , linux-fsdevel , Linux List Kernel Mailing , syzkaller-bugs Subject: jffs2: fix use-after-free on symlink traversal Message-ID: <20190326013950.GV2217@ZenIV.linux.org.uk> References: <0000000000006946d2057bbd0eef@google.com> <20190325045744.GK2217@ZenIV.linux.org.uk> <20190325211405.GP2217@ZenIV.linux.org.uk> <20190325233731.GS2217@ZenIV.linux.org.uk> <20190326013858.GU2217@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190326013858.GU2217@ZenIV.linux.org.uk> 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 free the symlink body after the same RCU delay we have for freeing the struct inode itself, so that traversal during RCU pathwalk wouldn't step into freed memory. Signed-off-by: Al Viro --- diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c index 389ea53ea487..bccfc40b3a74 100644 --- a/fs/jffs2/readinode.c +++ b/fs/jffs2/readinode.c @@ -1414,11 +1414,6 @@ void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f) jffs2_kill_fragtree(&f->fragtree, deleted?c:NULL); - if (f->target) { - kfree(f->target); - f->target = NULL; - } - fds = f->dents; while(fds) { fd = fds; diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c index bb6ae387469f..05d892c79339 100644 --- a/fs/jffs2/super.c +++ b/fs/jffs2/super.c @@ -47,7 +47,10 @@ static struct inode *jffs2_alloc_inode(struct super_block *sb) static void jffs2_i_callback(struct rcu_head *head) { struct inode *inode = container_of(head, struct inode, i_rcu); - kmem_cache_free(jffs2_inode_cachep, JFFS2_INODE_INFO(inode)); + struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); + + kfree(f->target); + kmem_cache_free(jffs2_inode_cachep, f); } static void jffs2_destroy_inode(struct inode *inode)