Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1523269imi; Sat, 23 Jul 2022 08:14:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tOiROWwl1FMBvC8K203gLgwNSfTvQijB7FRQpKpl2T5honXx59EHD6CQFMp+gaHKFFq4Or X-Received: by 2002:a05:6402:1350:b0:43b:a40f:3b66 with SMTP id y16-20020a056402135000b0043ba40f3b66mr4935096edw.173.1658589292669; Sat, 23 Jul 2022 08:14:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658589292; cv=none; d=google.com; s=arc-20160816; b=fuNbXDCmotGpSXw6YdVZwjkw2miFMjbSYUHc/ZAh2A4EgKT61dWl6jIhSuUQMoPeFb h13BEEny0BLr1ZkpiB9GSwWBKuwjfFX1+bjdVMFEtsX+idAZSEsva2r77+u5/fS2XEW4 HaSZtxm1HLaVwQtJ7X3jCd9FK2XhY76IS8CZzuXpTziYsG+Vretg9GKnAwWoCkMlJGWN 496UNQqRvpLfF0KadwluRPlpgM1YIosFHPQ19pQ0u5TypbJa3jKd22Qs7umPGOQKbkLV zsYE9urKehgHPZMFRAUpod25D6H8xuP1aMH8JKU9STAXKDkte5G1nnoWtQTQvUADB7X+ m9Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature:dkim-signature; bh=lAbC+X2Tel8SrTctAmEvcjkDg8Fkist45sWaOSUuvZg=; b=NJDpHpY8UQDMGQvegeih+Vts2G7t5X5N6/AcMcVxoddUcElfgjQYzs2r6HscfHw2YB /aKao1GJYKi80kgz/M9kzDIL6je2VwrL58WVAH5AagfqryY2Wg4RzznwO5vBA+byCv3c h9/eqIhGCEa+VmGa9E3jnL4icesyPTPgMB185B6fEU68Rx5sUBfYLCpipug18R/rY6K2 OgP+dXZG1PqA4Jy9uKMUM/dYjsJ1Xvi3ZxsrOSmhNzqYgKuRKaHsHPH9gcfSspJrf89P nly2m03812FTuohUAOr9mM9n+75E7SbYppKcreVVJzRwIsexFHHh0c5k8VQqB5byg92z 252Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=VffJB7Ml; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=VffJB7Ml; 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=hansenpartnership.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a056402274b00b00435c7cf30d4si10777710edd.27.2022.07.23.08.14.27; Sat, 23 Jul 2022 08:14:52 -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=@hansenpartnership.com header.s=20151216 header.b=VffJB7Ml; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=VffJB7Ml; 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=hansenpartnership.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231381AbiGWOuz (ORCPT + 99 others); Sat, 23 Jul 2022 10:50:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbiGWOuy (ORCPT ); Sat, 23 Jul 2022 10:50:54 -0400 Received: from bedivere.hansenpartnership.com (bedivere.hansenpartnership.com [96.44.175.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4732E111B for ; Sat, 23 Jul 2022 07:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1658587851; bh=rdXu9LN/zAdNX0uOk+wFkFqFAj3SIkSwTTiQs3IjqvQ=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References:From; b=VffJB7MlpUC4ZDSW4HI075M4hgSq6XZbAusnUaKXWfrVDZ2tXtxmJgwqfYWTzzOjc iM5qmHBmLY6uWrhswXWgyDoYowFmMJHYZPQymLJgwJDrClidXLbz7HNv7rPjf4QhRq IauO8NssFtEJlgzKkvXAbR78fRoQwvlaQUPI5pUI= Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 90EA91281845; Sat, 23 Jul 2022 10:50:51 -0400 (EDT) Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JVY4S5aeAk8F; Sat, 23 Jul 2022 10:50:51 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1658587851; bh=rdXu9LN/zAdNX0uOk+wFkFqFAj3SIkSwTTiQs3IjqvQ=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References:From; b=VffJB7MlpUC4ZDSW4HI075M4hgSq6XZbAusnUaKXWfrVDZ2tXtxmJgwqfYWTzzOjc iM5qmHBmLY6uWrhswXWgyDoYowFmMJHYZPQymLJgwJDrClidXLbz7HNv7rPjf4QhRq IauO8NssFtEJlgzKkvXAbR78fRoQwvlaQUPI5pUI= Received: from [IPv6:2601:5c4:4300:c551:a71:90ff:fec2:f05b] (unknown [IPv6:2601:5c4:4300:c551:a71:90ff:fec2:f05b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 85F79128182C; Sat, 23 Jul 2022 10:50:50 -0400 (EDT) Message-ID: Subject: Re: [PATCH] keys/keyctl: Use kfree_rcu instead of kfree From: James Bottomley To: Siddh Raman Pant , Greg KH Cc: David Howells , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , linux-security-modules , keyrings , linux-kernel-mentees , linux-kernel Date: Sat, 23 Jul 2022 10:50:49 -0400 In-Reply-To: <1822b7c129a.14411444236159.6380883938307880248@siddh.me> References: <20220723135035.199188-1-code@siddh.me> <1822b7c129a.14411444236159.6380883938307880248@siddh.me> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS 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 Sat, 2022-07-23 at 20:05 +0530, Siddh Raman Pant wrote: > On Sat, 23 Jul 2022 19:35:16 +0530 Greg KH < > gregkh@linuxfoundation.org> wrote: > > That does not explain why this change is needed. What problem does > > this solve? Why use RCU if you don't have to? What functionality > > did you just change in this commit and why? > > We can avoid a race condition wherein some process tries to access > them while they are being freed. For instance, the comment on > `watch_queue_clear()` also states that: > /* > * Remove all the watches that are contributory to a > queue. This has the > * potential to race with removal of the watches by the > destruction of the > * objects being watched or with the distribution of > notifications. > */ > And an RCU read critical section is initiated in that function, so we > should use kfree_rcu() to not unintentionally free it while it is in > the critical section. That doesn't apply in this case, does it? watch and wlist are locally allocated and neither has been made externally visible if the error leg is taken, so they should just be locally freed, which is what the code was doing before this proposed patch. James