Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1209001rwn; Thu, 8 Sep 2022 15:31:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Xf8NAyF2GPewz1pkhAzM+3dJWdZwO3OFJ4b5TnF4TR6nPs2eIsfaJX4iNNgXfQTE8z7e5 X-Received: by 2002:ac2:5191:0:b0:497:ac0c:cf65 with SMTP id u17-20020ac25191000000b00497ac0ccf65mr2872370lfi.436.1662676294710; Thu, 08 Sep 2022 15:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662676294; cv=none; d=google.com; s=arc-20160816; b=Tk4wt2EdqlY7b/mFm868/WhIkCu221+zJdL7ESkon5hlJ1ddz0/gYjCogp4DkB6Gz/ GQn+WW3uA9jIDJdMpOYskZAn97Auoo58IOq5tUq6k/66emvF3SCBJjCR39Q9NMnKC2+U dtET6BfHnzTVhAxJiIsT5plCdFsDTTjXQwqosxPbCGM4V4zjD7yK8bsCWX6ZweEYOjHQ bT0citxo62oTs8/IyYCZX9O7is90vjhUUjhu7PQwlHQybmvYkqLgcTZwMygnEdKbpxNE YGE2Upa0/tfik+b6dlOIxchrcyMl1PU17TszmpRu4XIiyNNE9t7XTYApE/P6OBqB6bK4 Gv1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=D25IdOYVvU7oZ4Lp0FfNkb1zKHRCdinNTI83d+BmPLQ=; b=Ba11k4rKUZFoSDsedogTAjNyTXUtSM6Ui9Ok45oI5XlhuXvti8Wqk7XL8hVIjfCfUj oerCSLZa/k92INrifssl0SiD8W02CM0KLXktUSzk3FI6Fux/3iEGLkiXU4h2D+VYd9gF 7VSWzkIfFHx+hxXGPHibiDLepDgfHcOm8b2Q3b3DPjaq3D6GS1PmLIS2/JhBhCHZx8QB xTHn+Q6HXpJLNs8EVB23FZ5OrumqpKVAzlz+8C7AnhL4iRu3lI7vjB42s7whmHv1ECRu m9JryRXN8XP2yORuGhMMvFEAMVglfcaLvsXxMGWD6L8b8zAD8Y0gsCoa/R16hAD+P3Z9 wmrw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a05651c11cb00b0026ad03edfd3si45738ljo.93.2022.09.08.15.31.04; Thu, 08 Sep 2022 15:31:34 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbiIHWZm (ORCPT + 99 others); Thu, 8 Sep 2022 18:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiIHWZl (ORCPT ); Thu, 8 Sep 2022 18:25:41 -0400 Received: from cae.in-ulm.de (cae.in-ulm.de [217.10.14.231]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 56A46A3455 for ; Thu, 8 Sep 2022 15:25:39 -0700 (PDT) Received: by cae.in-ulm.de (Postfix, from userid 1000) id 9E7A914002E; Fri, 9 Sep 2022 00:25:36 +0200 (CEST) Date: Fri, 9 Sep 2022 00:25:36 +0200 From: "Christian A. Ehrhardt" To: Tejun Heo Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH] kernfs: fix use-after-free in __kernfs_remove Message-ID: References: <20220907200811.654034-1-lk@c--e.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 Hello Tejun, On Thu, Sep 08, 2022 at 07:14:43AM -1000, Tejun Heo wrote: > Hello, Christian. > > On Wed, Sep 07, 2022 at 10:08:11PM +0200, Christian A. Ehrhardt wrote: > > Concurrent calls to __kernfs_remove can race on the removal > > of the root node: The race occurs if the root node(kn) is freed > > during kernfs_drain. The child node(pos) is explicitly protected > > with an additional ref count. Do the same for the root node. > > I don't think this is right. We don't support parallel invocations of > __kernfs_remove() this way. If @kn can be freed during kernfs_drain(), it > also means that it can be freed before kernfs_rwsem is grabbed in > kernfs_remove(). Point taken. However, the syzkaller reproducer reliably triggers the bug without the patch and the bug is gone with the patch. > The caller must be responsible for ensuring that @kn > remains allocated. Otherwise, it can't be made reliable. In this case the caller of __kernfs_remove is not kernfs_remove but kernfs_remove_by_name_ns and it fails to take a reference for the node that it looks up and deletes. Thus a second call to kernfs_remove_by_name_ns can remove the node while kernfs_drain drops the semaphore. I'll post an updated patch tomorrow. regards Christian