Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1199440ybh; Thu, 23 Jul 2020 03:01:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyH0K9Unb4WOXPSTp9o7MU71j7NH6Nc6OlOJkMo1pRd3sUqtqk2E8ISBddHnxaKXQjhXLTm X-Received: by 2002:a05:6402:1c0f:: with SMTP id ck15mr3276222edb.155.1595498503307; Thu, 23 Jul 2020 03:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595498503; cv=none; d=google.com; s=arc-20160816; b=Y1a+6Xyix3LMl24yUcPw2g2UaWwbtHjXcFZZAb/5ZfkzZh1StD/nD9Y1qCwCU6RXRa CiBIC7YpHvRdLWsjzC363Y7nkmvfkYuhDAlASIntOB7QJL3kUgG4vAf5xvnCXljw13we K/zQVlKvOwmUc9Urj8f4AQM9p/mkIVc4iQmhOfCIRBpn2CDWz8CpGHIU5ceE0vLu8S6i SqVyx78wOb8fFY2GvSqmUcEXuA9CSGnAPiWYkNW385Lfk7FErqDbBFKmvE+tHobgIqQ7 IMCwbIEQLqcEuBXp3+DKnyax2QCYl3WcRUlWehEqDgFsLb8Ln7lZQ5SbtbwmcnFI21qn yY+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=poit/Hvu3XwP4KP0RkmYXhp7Epm5+iTaYYX5hB7D+Zk=; b=oHjw+1r1xP/p87TmlFksl6c9P1FASvfu2ox6Mh5jCp/81EjjlAnOY0YfT/AzagmeHh vwTQCNg5rs/emcaNAGjpmUaJMBwx0C+i8oTWcIWM3BoV/bQQekdYUsggE4RNacpoQny0 B6IAkfX9PdwFyi2XFhrV70QtkDBzM/rcE2ksw5RgpVvL4ctrMp+o6+4BfnuMaFdEGwm8 qV09YH5Bl4OBnTZ3a4m2jXQ6+w8j6raTTNe0CzrHKi12jO1vHx0TeQq0cYKJP+cnh1RU taQvGJer3QBeuJz22EtYmgB5w/+GcrUV9PUqhKnhFLY+CZsyXUlbd4XVLRBuqeLXbhWG IyxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a14si1665303eds.487.2020.07.23.03.01.18; Thu, 23 Jul 2020 03:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728159AbgGWJ6y (ORCPT + 99 others); Thu, 23 Jul 2020 05:58:54 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:57352 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725858AbgGWJ6y (ORCPT ); Thu, 23 Jul 2020 05:58:54 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 23A9053A4D19736B6009; Thu, 23 Jul 2020 17:58:52 +0800 (CST) Received: from [10.174.177.167] (10.174.177.167) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Thu, 23 Jul 2020 17:58:45 +0800 Subject: Re: [PATCH] jffs2: move jffs2_init_inode_info() just after allocating inode To: "zhangyi (F)" , , , David Woodhouse , Richard Weinberger CC: , , , , , , References: <20200106080411.41394-1-yi.zhang@huawei.com> From: Hou Tao Message-ID: <2202d894-5b47-e606-2f58-306ec151626b@huawei.com> Date: Thu, 23 Jul 2020 17:58:45 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200106080411.41394-1-yi.zhang@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.167] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Cc +Richard +David On 2020/1/6 16:04, zhangyi (F) wrote: > After commit 4fdcfab5b553 ("jffs2: fix use-after-free on symlink > traversal"), it expose a freeing uninitialized memory problem due to > this commit move the operaion of freeing f->target to > jffs2_i_callback(), which may not be initialized in some error path of > allocating jffs2 inode (eg: jffs2_iget()->iget_locked()-> > destroy_inode()->..->jffs2_i_callback()->kfree(f->target)). > Could you please elaborate the scenario in which the use of a uninitialized f->target is possible ? IMO one case is that there are concurrent jffs2_lookup() and jffs2 GC on an evicted inode, and two new inodes are created, and then one needless inode is destroyed. > Fix this by initialize the jffs2_inode_info just after allocating it. > > Reported-by: Guohua Zhong > Reported-by: Huaijie Yi > Signed-off-by: zhangyi (F) > Cc: stable@vger.kernel.org > --- A Fixes tag is also needed here. > fs/jffs2/fs.c | 2 -- > fs/jffs2/super.c | 2 ++ > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c > index ab8cdd9e9325..50a9df7d43a5 100644 > --- a/fs/jffs2/fs.c > +++ b/fs/jffs2/fs.c > @@ -270,7 +270,6 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino) > f = JFFS2_INODE_INFO(inode); > c = JFFS2_SB_INFO(inode->i_sb); > > - jffs2_init_inode_info(f); > mutex_lock(&f->sem); > > ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node); > @@ -438,7 +437,6 @@ struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode, struct jffs2_r > return ERR_PTR(-ENOMEM); > > f = JFFS2_INODE_INFO(inode); > - jffs2_init_inode_info(f); > mutex_lock(&f->sem); > > memset(ri, 0, sizeof(*ri)); > diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c > index 0e6406c4f362..90373898587f 100644 > --- a/fs/jffs2/super.c > +++ b/fs/jffs2/super.c > @@ -42,6 +42,8 @@ static struct inode *jffs2_alloc_inode(struct super_block *sb) > f = kmem_cache_alloc(jffs2_inode_cachep, GFP_KERNEL); > if (!f) > return NULL; > + > + jffs2_init_inode_info(f); > return &f->vfs_inode; > } > >