Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1528575imi; Sat, 23 Jul 2022 08:25:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uITy0YocxkJsorQHu7yv9l6BEVjWa1/TGVCndCcWUMHfia+w9nR5XBLzclQX95aM8R940n X-Received: by 2002:a17:907:96a4:b0:72b:647e:30fd with SMTP id hd36-20020a17090796a400b0072b647e30fdmr3709739ejc.723.1658589944483; Sat, 23 Jul 2022 08:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658589944; cv=none; d=google.com; s=arc-20160816; b=F3qtWE6ZHNTTA/95Hx1z7zvBlRdkkcZW1UNhs6643G4C0zbMvwQZJCSLwCg+b1uwBe Bu69UGft9/FSnKlCyxZCD96qFOtNvun9E9VdlOOCmejfeYzLz2CUwhcXk6BTNG4Fejex A0HyjVLYOn2Nq3ReKkS9wZyOyCeFUUEjHenNxAVxb4QV3XSOcLlmcEeZFr6DfwQyCw2J 8zpSGUWOxmoHCRmEOQMnSi8hdP7KHn1hs1MlvKUU8LswN696N1SaAldmohCG9nIcW7v2 zJa0Qu/svq7xXZag/ztGaTdYFh6J+QekHc08WVbKooBeLsC0WLZQJqV2G/KP/KbLT6Tu Zr6g== 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:dkim-signature; bh=ei79Vr8qHSguM8kIs0V18VB2uSyUAzc8kNnk2XM8u4c=; b=PpXJjh+3LbANZILkSJFsp14vE9qU7xbhEKEF3YUyxZdRIhua7nBdFflEZ1vDjp9vkD XUGGfn84VFL/V1X+nqfubXC/Snp1WylQViGatxRw3G14FLHA9CISvzXLfsW92/InwOHv 3A9srnHyy1oFe6mgHYwCBaLQ/5Fuddy1R1Av3po7QaFYz0OHrp5EGrLpWW4lUvToBTMl q/1K6uh2OP4w0/gS729Bm1jxuYu0JhV1aUYOu1H6molFvU2v2W8fIO/uWiL/pcKLvWpe ONb7+gPVjzYiE6BOQKNvfmtqO0STLQFpq5ghOO0843qcQXNAKG5OWuxXxWLBv876ArFV KZ1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HCcdBKY2; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne5-20020a1709077b8500b00726d677eb6csi9601338ejc.539.2022.07.23.08.25.19; Sat, 23 Jul 2022 08:25:44 -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=@linuxfoundation.org header.s=korg header.b=HCcdBKY2; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238365AbiGWOnU (ORCPT + 99 others); Sat, 23 Jul 2022 10:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238328AbiGWOnT (ORCPT ); Sat, 23 Jul 2022 10:43:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2752E1C915; Sat, 23 Jul 2022 07:43:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B5CCA60B15; Sat, 23 Jul 2022 14:43:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CB44C341C0; Sat, 23 Jul 2022 14:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658587395; bh=K8azZb2qkyv6voRZ6WF1fjauRYoudrM7tfG/bw1s03g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HCcdBKY2vICpMx1OoWFd+YSvcsmnePg56LwozW2WDLrRKMPZd3OBSvjuIx2bsyshJ DvTDIHSvZLRyQ45A2C+i4WbsfUhmYpBWD5MejPbqZrY2ZF3t9UO4NeTw3pHfO6HzZP +77tmypez5z4rah/9I3tF7mm55oSAA5jcxi86Mu4= Date: Sat, 23 Jul 2022 16:43:11 +0200 From: Greg KH To: Siddh Raman Pant Cc: David Howells , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , linux-security-modules , keyrings , linux-kernel-mentees , linux-kernel Subject: Re: [PATCH] keys/keyctl: Use kfree_rcu instead of kfree Message-ID: References: <20220723135035.199188-1-code@siddh.me> <1822b7c129a.14411444236159.6380883938307880248@siddh.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1822b7c129a.14411444236159.6380883938307880248@siddh.me> X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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, Jul 23, 2022 at 08:05:27PM +0530, Siddh Raman Pant wrote: > On Sat, 23 Jul 2022 19:35:16 +0530 Greg KH 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. You need to explain all of this in a changelog text. Don't say what you do, but say why you are doing it. > > And how was this tested? > > It compiles locally for me, and I used syzbot on this along with testing the > other `watch_queue_clear` patch, which generated no errors. How does the watch queue stuff relate to this keyctl logic? Again, be specific as to why you are doing things. thanks, greg k-h