Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1556426ybj; Fri, 20 Sep 2019 12:23:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqygGAUULreuV9Nu3tVjHz6UQbw+P+lbS7X+RtQp9tjCxtAeZjWxYyj9I2gcKCoj0PD93Ony X-Received: by 2002:a50:93a4:: with SMTP id o33mr24303181eda.0.1569007421217; Fri, 20 Sep 2019 12:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569007421; cv=none; d=google.com; s=arc-20160816; b=LZymoKLjRO5hmg98X+4YG+O7Ixwpxn3XNZ0Tt9puyqRDLYEIO2y/+NhnoL6w5kLRA0 zgLvEdVIuA4CBPERjEgENNuhS38pXmEKHefcwZhiiKhf6s+nmooUcoYzyzLNr55UIWs8 slBinaTnu2Jb6MMAJEa0ho7yXUCnl2h3jICcieK1xnDl/maqbNCBKiXWGFxOJgq294L7 v1uvOct1tpSyRVAtxGwxJeC2oMTJPEeBs2ufpodeEwBmwAx8Y2aBbWPSfUt1KyvBWp2R W4rZO8BZkW+8Bztb4dYGRMVYZUmZEWmx/ys9kzYmoeJUEhq/I4RVxoZAvrpblDkAE9Od mWiw== 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=Ak9kPBTZT3FDBWUxRZiZdWTwDA1Aj/i07qHpeaTyDkM=; b=VxGOCIebTMAbaWhigZXs5kjnmU0HudZb0jyx0qmT0hoA4O0AaZ9GHnY6+XL9oeia0a 2QFoUzqONkcqFwNx5Jtm5H68+9g1aZEdeuQHjSQ2jGHxkFby+8oiKxHfYw5NzVQBkGmW AjJaKCL2Mf6fJPZJXM5GxtXbJMmVLCwsiA4747rpCWltvJoAxJV+YdEN+3QWPFi79R/G JPu4A7bt5OUcu/dyl6waDIzNBAXqMIqrGZ8TAi3JQasi8st+ADgg22ok9RQ89obRYNKA LHVMtFSAylAf8si8owjmilCC5MI8KiajAKMpK6keTjq4viIHBt9dT/SsL2qZr4bWpM2P 6How== 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 ca9si1943354edb.79.2019.09.20.12.23.18; Fri, 20 Sep 2019 12:23:41 -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 S1726193AbfITMpv (ORCPT + 99 others); Fri, 20 Sep 2019 08:45:51 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:35040 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbfITMpv (ORCPT ); Fri, 20 Sep 2019 08:45:51 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.2 #3 (Red Hat Linux)) id 1iBII0-0005O2-Mk; Fri, 20 Sep 2019 12:45:33 +0000 Date: Fri, 20 Sep 2019 13:45:32 +0100 From: Al Viro To: Xiaoming Ni Cc: dwmw2@infradead.org, dilinger@queued.net, richard@nod.at, houtao1@huawei.com, bbrezillon@kernel.org, daniel.santos@pobox.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] jffs2:freely allocate memory when parameters are invalid Message-ID: <20190920124532.GN1131@ZenIV.linux.org.uk> References: <1568962478-126260-1-git-send-email-nixiaoming@huawei.com> <20190920114336.GM1131@ZenIV.linux.org.uk> <206f8d57-dad9-26c3-6bf6-1d000f5698d4@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <206f8d57-dad9-26c3-6bf6-1d000f5698d4@huawei.com> User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 20, 2019 at 08:21:53PM +0800, Xiaoming Ni wrote: > > > On 2019/9/20 19:43, Al Viro wrote: > > On Fri, Sep 20, 2019 at 02:54:38PM +0800, Xiaoming Ni wrote: > >> Use kzalloc() to allocate memory in jffs2_fill_super(). > >> Freeing memory when jffs2_parse_options() fails will cause > >> use-after-free and double-free in jffs2_kill_sb() > > > > ... so we are not freeing it there. What's the problem? > > No code logic issues, no memory leaks > > But there is too much code logic between memory allocation and free, > which is difficult to understand. Er? An instance of jffs2 superblock might have a related object attached to it; it is created in jffs2 superblock constructor and freed in destructor. > The modified code is easier to understand. You are making the cleanup logics harder to follow.