Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6979225rwn; Tue, 13 Sep 2022 11:49:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR60tAiABy7JCFbttd4YC8SyYPRO6l8lPue9UKB3EcQDDqkQtEwkTMfoFkqPb16RdVo+Qd9t X-Received: by 2002:a17:907:6e25:b0:77c:88db:a1ec with SMTP id sd37-20020a1709076e2500b0077c88dba1ecmr9669053ejc.123.1663094946051; Tue, 13 Sep 2022 11:49:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663094946; cv=none; d=google.com; s=arc-20160816; b=0LZcow+Hpw8U0tM4nGKTW0wziQY/b7cco/Xq68z9UvodN3ziXt7NWzrWmRIQ6Y7xfe JJT2wjyyAFKPmVjPzVM480R1vjbzrUds+6AXDbsSSl3cLOwi6U8SksY0QdISWpZXjjLX Ec9ASN0jlMyT/dCmisw+DU/aX+BpktSALI96zA24Xjl6GSRiA1t1doAYbhQmDcabYDse pcsoABgH0ZunsTXlGwdGAwWqxdz8rqBSpStZdNVEk8wZsVtB532bzbCRqs6NTvpAZnn/ KnZa5p8aKthI8mPrrHrYLJMi8dMEJHs1aEJbjUNgTsOUbmuTrQoSdIygpQCbZTDdvqN+ sRAA== 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=uENaF8Aeuw2AlPXswf2tmsAc80uie0EF9ocI5lWSah4=; b=aTMh+mQoXw+gbfMNtv/JZwi/a7LvTx0YUj0CbKB3SN5KfJaCC7pMmmbBo7rXAXJxSP Cy5ibfth0xPo7j+m93IOGFH2K9qSYPr6u4TR6NUseYXGM4SgKWPG0wQJv1w6NSoJxg26 AJmVP4B6YFL/t15Nhp6oeJqOLep+z8vIyEyY4p8WjjedmXYpUzznFtEDV0n2GaconkLH woJCmD7RqhXbcTIiA8qbLe9s2TChgrCIph/rKmBLIRIHGp4LJ0h/UV4lIK7AlLC/Nt6Y InR5Qug3qPglVBrA2HUsov3gLcVg0VoaIYe3Yg5u6J6TmzamlrUWB203Wjem3B6SDWbb RYkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=h7s9WaOq; 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 fg4-20020a056402548400b00451a3b1670bsi5445726edb.539.2022.09.13.11.48.40; Tue, 13 Sep 2022 11:49:06 -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=h7s9WaOq; 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 S230414AbiIMScA (ORCPT + 99 others); Tue, 13 Sep 2022 14:32:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232580AbiIMSbk (ORCPT ); Tue, 13 Sep 2022 14:31:40 -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 C698C6EF27; Tue, 13 Sep 2022 10:48:07 -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=uENaF8Aeuw2AlPXswf2tmsAc80uie0EF9ocI5lWSah4=; b=h7s9WaOqvv/tQn2jfoY5egIZOW PrrDUAkHI0zCIxU3oWP+jOBvWIY0JN/z7I1vi2K81QlyuGOVZkswMUBOwY9Ppnk9D4+vF6OQMmgP/ 1wrgWV3lycre6hB5fzg6vA//ecQ8V3oFAWzRedmQRfYziH++Ev3WkQzhPv3cAZfuPu79s8PTe0dj6 Td7IdApw72FnjQ9Aidplf58ckjrsGfDRKvY7iW8v+/bSm3NitCQJw6BaPP5dZQnThPAhtiPh57tQr Yqldtxr6/BVfcADvQJ9CMor9HgsyXFGgALLlEEblsQEn4m43zju2EZlZYOZsBvopdp8RU1Xt73P9o ItoPkeoA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1oYA0z-00FvQm-2L; Tue, 13 Sep 2022 17:48:05 +0000 Date: Tue, 13 Sep 2022 18:48:05 +0100 From: Al Viro To: Jann Horn Cc: linux-fsdevel , David Howells , kernel list Subject: Re: BUG: d_path() races with do_move_mount() on ->mnt_ns, leading to use-after-free 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 Tue, Sep 13, 2022 at 07:14:56PM +0200, Jann Horn wrote: > As the subject says, there's a race between d_path() (specifically > __prepend_path()) looking at mnt->mnt_ns with is_anon_ns(), and > do_move_mount() switching out the ->mnt_ns and freeing the old one. > This can theoretically lead to a use-after-free read, but it doesn't > seem to be very interesting from a security perspective, since all it > gets you is a comparison of a value in freed memory with zero. ... with d_absolute_path() being the only caller that might even theoretically care. Anyway, shouldn't be hard to deal with - adding rcu_head to struct mnt_namespace (anon-unioned with e.g. ->list) and turning kfree() in free_mnt_ns() into kfree_rcu() ought to do it...