Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2882687rwb; Mon, 15 Aug 2022 13:14:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR6QndYSYVgmdzUyx+riPL5TCX/IGnWmEiQ7LN38ls4OSVntL7+nAwSOFC3VXWF4wq5xekU4 X-Received: by 2002:a17:907:69b0:b0:730:c511:c856 with SMTP id ra48-20020a17090769b000b00730c511c856mr11296521ejc.240.1660594489283; Mon, 15 Aug 2022 13:14:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594489; cv=none; d=google.com; s=arc-20160816; b=0DniAZVscHvvXWjBEoMbt+IILwClwVQ6m3oaxZ/l89nALiK0Hv8eo2Ugw+d4tuqPTG WzA44/Qm2rNbcOb5VIG2376Hl/Z0Gy0O/CK2xUZHc/NNgLCP+TTMERasFfg4k6iFfy5T csN6z2NohIJoT2FVKZqftxjubpVdNYDcucgW/kdoGb4nJQv/KHpBRT2IR0thjQFdXoxO mLSlbNoyLmWn8+Q/VEguKVpkhjmFYo4wECuwoirWuftzcOBv9q3i7vPlZS6+S3L+Ml7b Z4gV4EPk+IG0+bzZw5fOBahBhe3mrgEqPBOfoMWwqvdjnb30J0aU6rGo1LrX2xTm46Ly K0vQ== 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=Peq9JtWu1E4wR6oLY4ARrrcqindLx2FfBvAEgWzQ1g0=; b=wvrDfu/iEKn5F7lQS8UsSfMcyB8gszQ4ab2RRWaPdzy+OvCxAvA9/Rc0UTWz74coqH H33p6miVXtncAGi6Mizkhd6sPYTUIcnwEgmQlNmE2yLsLUGQ/IMZdaesTbkia/xUqis2 BO+uodo6UocSyx8YjGZqV+zqWqDbBtW9W/WxaJj3c27V6ZTtslDK2N7+z4l3WQhADg9I IFJq2fxFLCT58kKraaRo+Izmx8hWQQaQf0ClUO/dn7io9jszrB9VnnBAt6LOpNY3u0NN hlCLCmTF7QkOYv5Tj9GF5uwyPvK2MRcNqYB45dNMB6M/ecBKGlotR+TFC2/ULfsSKO34 WepA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=w2tLn6ET; 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 v18-20020a1709067d9200b0072f1c8d0e62si7766836ejo.95.2022.08.15.13.14.23; Mon, 15 Aug 2022 13:14:49 -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=w2tLn6ET; 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 S233640AbiHOSkS (ORCPT + 99 others); Mon, 15 Aug 2022 14:40:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242048AbiHOSjP (ORCPT ); Mon, 15 Aug 2022 14:39:15 -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 B57412E6B8; Mon, 15 Aug 2022 11:23:54 -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=Peq9JtWu1E4wR6oLY4ARrrcqindLx2FfBvAEgWzQ1g0=; b=w2tLn6ETVYP0VvljwROUi5c9Q/ rveWi+fG4t0fVcKB8q1gaZj8w72ZcqqAKvJDoLctt58naFC32aD+X4WKR+yk4FIlBv/57aq3IMObi 6jS7VEFtjnk4FEMuwQ8+Fjy8laYEJZy6EcLFItyiTPh5qAGwOMKYiQ6KeIQKxCsNKd2oY6u19eCRm pR2Hzxb627+lWtmepjuPenaVX0DcWRc5KKJNlIxPNAzsI6C9Lino+xxMTUciyHL/wKO+9SgnbZbvI YEg3IuCRpq7nZ2tZ9dWcU9PJPGY179wOkToWpHf9rdYl4q/9kHG57Ze0zJ4QSdhMVDEFbqJTVyy6e BlseRfMA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1oNekh-004kXN-TZ; Mon, 15 Aug 2022 18:23:52 +0000 Date: Mon, 15 Aug 2022 19:23:51 +0100 From: Al Viro To: Jiacheng Xu <578001344xu@gmail.com> Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, konishi.ryusuke@gmail.com, linux-nilfs@vger.kernel.org, security@kernel.org Subject: Re: KASAN: use-after-free in nilfs_mdt_destroy Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Mon, Aug 15, 2022 at 07:02:14PM +0100, Al Viro wrote: > On Mon, Aug 15, 2022 at 10:03:21PM +0800, Jiacheng Xu wrote: > > > Patch: > > Fix this bug by moving the assignment of inode->i_private before > > security_inode_alloc. > > An ad-hoc patch is proposed: > > https://patchwork.kernel.org/project/linux-fsdevel/patch/20211011030956.2459172-1-mudongliangabcd@gmail.com/ > > ... and that looks like utter bollocks. Why does security_inode_alloc() > look at ->i_private? Which LSM is involved? OK, I see... The role of security_inode_alloc() here is that it's a possible cause of failure. And yes, dealing with that class of bugs here might be better. However, *IF* we go that way, why not move that thing to the very end? Just prior to this_cpu_inc(nr_inodes); Sure, nilfs2 steps only into uninitialized ->i_private. Who's to say that we won't run into somebody deciding that e.g. inode->i_data.private_data is worth a look? Just move the call of security_inode_alloc() down to immediately before the nr_inode increment, with explanation along the lines of "In case of security_inode_alloc() failure the inode is passed to ->destroy_inode(); doing security_inode_alloc() last makes for easier life for ->destroy_inode() instances - they can rely upon the rest of inode_init_always() having been done. It's not just a theoretical problem - nilfs2 has actually stepped into that [reference to report]"