Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2875380rwb; Mon, 15 Aug 2022 13:06:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR4W3uk/S+56ofgjdzx/4vQiXzAbkz9QWhFqzr4YNkKUcpvvEh/mClB5JE6KbQW6yp64iChO X-Received: by 2002:a17:907:6d16:b0:731:17b5:699 with SMTP id sa22-20020a1709076d1600b0073117b50699mr12186365ejc.23.1660593968189; Mon, 15 Aug 2022 13:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660593968; cv=none; d=google.com; s=arc-20160816; b=L045fuNlb4eu2vzo8cLz44sZX0qTSYpy5ZhvVVNjjcUcilvGGiSTpFf62BFucZ6gzk Id4hizw7NVvncQG3LkQ6qaZXW7Ft4F9H4WVPSlWClIs1fm0e9R13rM5nOknUfLM+CTGv tYf/f8Z97OR+XaYUBoVe75FTQMHleTeT1/zKozAUHbTLTh3nn2vrO3Fr9MsItcL/En/3 K62tOD361/xf5uUKvQRy2347gCnDpPqmuKqSdfzot7wOasjwzyk3xx8YJ1H2rP6jpMTw +71VBlF4/bkIYPuiDRzuaEFYdS9AtAY53aOSUenzHYfzjNgDlfagEuLlWhz4fdSYrBCH uM4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=pQgnV2W+m6IHyd1sfXNyPuGcZpvyoD3dq7ndy9+1QWY=; b=xlcG2yf1hKi3L6zSA2CkN+Q+hG6aOFvPDZ04YLr63yQMqhw+AiwWVro3U85uEM7zx4 pv2InTz+qSpyV3E+QvAaESXU/yACmabUILUyYdTN+W97EkP9GXMK/cnsA2D4p/Crv1GJ N0OfoS0gLXToJJpdDz7BCH3kkFF/MANJ4lPIz8Z9k6VEgwBdh54u/Bkei12KgCZrqraw 4i9aZEy0j18Ysr2yMme6pBXVJAJgyWN3YlpKsfPwuqeVoFPbPP9A1el5//T/PEHCO8ed uZiTr61vSRlOuR7LOeYU30ipLT9WhSsazR3NZ6W/ZN1tNJQIVi6sHHuPDqNnnYWZp3Ts Sa7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="nOms3/1U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a170906448e00b007309e910729si6969976ejo.580.2022.08.15.13.05.42; Mon, 15 Aug 2022 13:06:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="nOms3/1U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244097AbiHOStp (ORCPT + 99 others); Mon, 15 Aug 2022 14:49:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233146AbiHOSoB (ORCPT ); Mon, 15 Aug 2022 14:44:01 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FC632FFC3; Mon, 15 Aug 2022 11:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=pQgnV2W+m6IHyd1sfXNyPuGcZpvyoD3dq7ndy9+1QWY=; b=nOms3/1Uq5YOF1bwlhQz39B/xq lhJn4Xz+bgO4S+tzCDXYpLB8VrlkUqBdIrbUt95mBrUHdr683sUAqzaa2EL8z+RDmYP2StzlwdOJ2 dlu4xtB6GtZ7UapVk2WD/TlGptwIfUv0tciWlGulljYY9+Fcpo2ICJpMpb0BJvuXzzX0zDUpw9zyU KyGPgpkB3lZyjCE3mM8iw+OX+wUW/BWlIlrIvAWaQoFKHxiKHBkFWxJrLM4RNSV+3QMORX/AlleaD vpDR4/Jp7QyIvjl5gi8PPa6yPcN0ObjLRunLjv/8GqjUnNkTYLzal4MQ7zci7VkeymEdMAPpsPy07 le8oCyVA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1oNent-004kaQ-Ps; Mon, 15 Aug 2022 18:27:10 +0000 Date: Mon, 15 Aug 2022 19:27:09 +0100 From: Al Viro To: Ryusuke Konishi Cc: Andrew Morton , linux-nilfs , LKML , Jiacheng Xu , Mudong Liang Subject: Re: [PATCH] nilfs2: fix use-after-free bug in nilfs_mdt_destroy() Message-ID: References: <20220815175114.23576-1-konishi.ryusuke@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220815175114.23576-1-konishi.ryusuke@gmail.com> Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 16, 2022 at 02:51:14AM +0900, Ryusuke Konishi wrote: > In alloc_inode(), inode_init_always() could return -ENOMEM if > security_inode_alloc() fails. If this happens for nilfs2, > nilfs_free_inode() is called without initializing inode->i_private and > nilfs_free_inode() wrongly calls nilfs_mdt_destroy(), which frees > uninitialized inode->i_private and can trigger a crash. > > Fix this bug by initializing inode->i_private in nilfs_alloc_inode(). > > Link: https://lkml.kernel.org/r/CAFcO6XOcf1Jj2SeGt=jJV59wmhESeSKpfR0omdFRq+J9nD1vfQ@mail.gmail.com > Link: https://lkml.kernel.org/r/20211011030956.2459172-1-mudongliangabcd@gmail.com > Reported-by: butt3rflyh4ck > Reported-by: Hao Sun > Reported-by: Jiacheng Xu > Reported-by: Mudong Liang > Signed-off-by: Ryusuke Konishi > Cc: Al Viro > --- > fs/nilfs2/super.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c > index ba108f915391..aca5614f1b44 100644 > --- a/fs/nilfs2/super.c > +++ b/fs/nilfs2/super.c > @@ -159,6 +159,7 @@ struct inode *nilfs_alloc_inode(struct super_block *sb) > ii->i_cno = 0; > ii->i_assoc_inode = NULL; > ii->i_bmap = &ii->i_bmap_data; > + ii->vfs_inode.i_private = NULL; > return &ii->vfs_inode; > } FWIW, I think it's better to deal with that in inode_init_always(), but not just moving ->i_private initialization up - we ought to move security_inode_alloc() to the very end. No sense playing whack-a-mole with further possible bugs of that sort...