Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp758963ybj; Sat, 21 Sep 2019 11:16:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2Rch4QxNOTdHboh0WOX3KEA0QlZMfcHmRwdPWcehHvqGMJBQ9n0U4l9sJ22mCAChUNHZB X-Received: by 2002:aa7:dcd7:: with SMTP id w23mr26732974edu.170.1569089812600; Sat, 21 Sep 2019 11:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569089812; cv=none; d=google.com; s=arc-20160816; b=eZlHkSdW7haavv8/J6sW47oX1Cli9A088/c63hmSL2nJ0Boc3LIIFfMm+b3cmFNzX/ Yb+shQst7KBjP/fUv/oBsSAUJnDujBJD0Ho4IIT8hkj12PM/Fz9zYTutyXaHdEJ5iASN 0jmAr8rJsV3LWwAyiTLjKw4HHDOk82gcePKpHsB8COjhnVJukAin1h1l3acjkPvHfZp9 ofBiSwt+jX0v97bMFqREJGJLX2ZIKcJmd1ECAMyPeCNArFWVSGv5ecW+Yyi8/xdXjo77 Mn6aIYYNSA9mlS8WocQ9hptQYaJMAd3vIPhDVefMiWJcPcOeVaieQyMraN2eadw/e+wR sl9A== 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=X5YPzzn0Hsx+9GvupezBpUsN95uO4wPlqwAuoTfp1Ow=; b=zBuYJ9RJH1Iz9imie2lw6hYryhetRjKxZkJQP3dxEpmLRbWLx6ao2Dhm4uMiN9i24O 3Z1N6ghIX6ksNyyx+ZyHbT84VZ8VYbyeX+BlaVdOWd9TzKL9sEz1+moSMQkEHa1+3mGN fSvgtdQx9cl1V/x5p9kAn5ZuKFVx+xInIOsfqJwU4v1Y2WtMUj7Fco5Nq7C6ZkzVgm4v SOtEPLCIiLXQlxHcXpun+wzNSbgBUx7hN71+/nhQ8hMNAKVcV2P5b87cVl8aVAF7vhNu JxwC2oQM8cWP9GLOApYeklA4wviiUVr0Npfy7q1Ge6f0jOXvW/2k0rRyizJhVHSA4k0R Jf9Q== 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 b9si2796959eju.269.2019.09.21.11.15.59; Sat, 21 Sep 2019 11:16:52 -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 S1726781AbfITMyy (ORCPT + 99 others); Fri, 20 Sep 2019 08:54:54 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:35276 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726524AbfITMyx (ORCPT ); Fri, 20 Sep 2019 08:54:53 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.2 #3 (Red Hat Linux)) id 1iBIQs-0005Yn-1s; Fri, 20 Sep 2019 12:54:42 +0000 Date: Fri, 20 Sep 2019 13:54:42 +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: <20190920125442.GA20754@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> <20190920124532.GN1131@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190920124532.GN1131@ZenIV.linux.org.uk> User-Agent: Mutt/1.12.1 (2019-06-15) 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 01:45:33PM +0100, Al Viro wrote: > 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. PS: the whole point of ->kill_sb() is that it's always called on superblock destruction, whether that instance had been fully set up of failed halfway through. In particular, anything like foofs_fill_super() *will* be followed by ->kill_sb(). Always. Which allows for simpler logics in failure exits. And the main thing about those is that they are always the bitrot hot spots - they are systematically undertested, so that's the last place where you want something non-trivial. As for "too much code between"... Huh? We fail jffs2_fill_super() immediately, which has get_tree_mtd() (or mount_mtd() in slightly earlier kernels) destroy the superblock there and then...