Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21233360ybl; Mon, 6 Jan 2020 00:06:00 -0800 (PST) X-Google-Smtp-Source: APXvYqyUbAK2LEDki1sPM4YZn9xbp6APuOB7TbW+L6QQ/hdcnz4rpjajSi1s08AodomWPaw8J1bo X-Received: by 2002:a9d:7519:: with SMTP id r25mr104191143otk.284.1578297959999; Mon, 06 Jan 2020 00:05:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578297959; cv=none; d=google.com; s=arc-20160816; b=CTJtR5DB1RzDVp8KnmCJAs6WIjWNEqnbH0/HhVoFx7sXgheShRE6lBtVeT4wRkFTmJ gfQz7WaC1uta8HmWz/JMvTT/4nJYDUm5sBx9+biOD6a2pK/U40XRwUzfWivIH4TyOWzY LkgQTCmES0rXghgKKQdslQy7xGTPHswhHA3uTM8tNY2ytoxRSTn57t1i+sUXM6UnNIOK DYremUzJUVUXH39GfIEleDy3THwoSmu5M/IuchqRyux37G7OsPyqMDwXu969j0Pe+Vl+ kqCmX9+C6368o4sBWtzHBim1lzQ2PwVnxersTflDVhStwN13fcMIpU3BnWjmTYfOClSJ /+wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=h8S+XSxqb1l2cuTnP0wfaSaKoq9MYRUb+Lr8iWSez9o=; b=waBeIAjub73sIU1Wcy/Cqw0XxANTbCnp6Dzq1PbKlov8sDdS5ig0eutOrsF47Qo/FS dwiMra8Ysj+Ph0HdMQ6NqB9vPK/NQ33Xdn5rkxFgmNRstFohu7vLGV4cJi2gLB1oelMo EwX3GsfQV6dzOIA7PWdsGTD5N+Bjob18G9iMBowaJxCzp7BisavbL0T9mEtMU5bMEfqA 3QBOlR5jlxgI+qb3Qk4AtYdAdidbMt15uo1cOPSDPc5JulJIjDfckfnq6EW+954GJFc8 DG0WisF6FeIpyaIvNoKAMpW5WOkjbLSyMNke6Iio0i6+5l/V80Oa9WaBHfqj1ebrxRe3 kkfQ== 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 c19si32962847otn.7.2020.01.06.00.05.47; Mon, 06 Jan 2020 00:05:59 -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 S1726296AbgAFIFJ (ORCPT + 99 others); Mon, 6 Jan 2020 03:05:09 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:57486 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725446AbgAFIFJ (ORCPT ); Mon, 6 Jan 2020 03:05:09 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A87FC39B56C3B4CF6703; Mon, 6 Jan 2020 16:05:06 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Mon, 6 Jan 2020 16:04:57 +0800 From: "zhangyi (F)" To: CC: , , , , , , , , Subject: [PATCH] jffs2: move jffs2_init_inode_info() just after allocating inode Date: Mon, 6 Jan 2020 16:04:11 +0800 Message-ID: <20200106080411.41394-1-yi.zhang@huawei.com> X-Mailer: git-send-email 2.17.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)). 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 --- 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; } -- 2.17.2