Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3320472rwb; Sat, 12 Nov 2022 03:38:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf7aVX0bkhbO3e6VpPfsaNWgZ3DuP/dI6gnVG68iLfNhHyDNER3jNjO1hfnIbOAuwNFy+YDi X-Received: by 2002:a17:906:a057:b0:79e:4f34:a8e1 with SMTP id bg23-20020a170906a05700b0079e4f34a8e1mr4860312ejb.194.1668253094067; Sat, 12 Nov 2022 03:38:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668253094; cv=pass; d=google.com; s=arc-20160816; b=YNy24Prap/1niOU6R5pVdfPv7KpAh7kQxvqSq8J1scaav/mYR1YtoW9/K4HxtI+LyG lLYLvbzLDv6eiX6zzXWAICkLRhzn01PoykuOXr/qPBVX8KovFneXWzLTcQwW49K1Wa9W P08kJvM4o7fycXtW01ntyn7dbbf4XRbUpfNVyxJIsm6D7wc3p1KKZxHR+620+WIFnKQ7 cW+bIekC3+UPSIsEqhIs4sk+8f8Uk3dzLEfcmSigzjfRFkpRyOH4EwKbeqB2ey4QrEh7 Mar7VfwoiCJJjyU/I5k2bJstUA40JRqcXs2/uewYUiqpNEerozEHo8Xyura5qRUC/16D fQsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:subject:message-id:cc:to:from :dkim-signature; bh=CciC0JA+1Sl6P741HLOLO7oPE18KzPzTWUnJ9g4NcCY=; b=jtRk28m5HDrLVGU6xcBs064AURn0u7vcTLpWDObU2tHF5SzhdQC5ppmq0TH1VEA/D4 XaH/Mf1xd67KlWEMV85nPyvQGbZriYWzhG6ckHHFkpgTsiEJyStV2J/zdnTEMpmj/hYA EBV254easGoz90u80bHUL87Ozd/V88PyGNOKsCEGFn8WGSiuTPyTevEfKsWHW7co4Zqo JzR5zaTg0TH2UJ24W/bmF7v8izl/Jw1GyxXvugcwwVtNvkdXQsbW4D0NZeWmH88duIYu g4d0/RDfXOhQEkzyOEGyQTucedtf6kfh63U/7AUgg9xfb72gcJ9+JcNSiWUR3o0w1v62 Frzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=KeYri2bD; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a13-20020a05640213cd00b00456eaa4fb1fsi3967026edx.223.2022.11.12.03.37.51; Sat, 12 Nov 2022 03:38:14 -0800 (PST) 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=@siddh.me header.s=zmail header.b=KeYri2bD; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234850AbiKLLRm (ORCPT + 90 others); Sat, 12 Nov 2022 06:17:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233681AbiKLLR3 (ORCPT ); Sat, 12 Nov 2022 06:17:29 -0500 Received: from sender-of-o50.zoho.in (sender-of-o50.zoho.in [103.117.158.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE9F31F9DD; Sat, 12 Nov 2022 03:17:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668249073; cv=none; d=zohomail.in; s=zohoarc; b=WvjIxDY9DG6YuzcAwCxhgC+1QeN+Or0Glx//RDKFYJtEKRoUf7s8ly6xpRvOkbm4JCKwyvfi36jQ9RxZGpsamB1ePt4gIVxsbGfTg3Yzoa9Vsl5IVaZjroRHh4b8gNZ6DiQDkakwI4asbsZtm2Tcgaf65o+nt1ADLspU7xnX8aQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1668249073; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=CciC0JA+1Sl6P741HLOLO7oPE18KzPzTWUnJ9g4NcCY=; b=degMBSnd9mGkKSPgdaapCdnzUPijGJ/a4MH85DcCllqX8o8cQ7EUSMFVg9m+rqFcL741P6czQkys9PXclLmJvjWnjpb4YTFGsJsBqMm3Cjy6FVgykzkQGl+i+APFF6LZHe8Frz9chLNlQlV4aSdB1t9LIhn4igYi90O7buSdj6s= ARC-Authentication-Results: i=1; mx.zohomail.in; dkim=pass header.i=siddh.me; spf=pass smtp.mailfrom=code@siddh.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1668249073; s=zmail; d=siddh.me; i=code@siddh.me; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=CciC0JA+1Sl6P741HLOLO7oPE18KzPzTWUnJ9g4NcCY=; b=KeYri2bDEYsjQ5ROrUNLIT/BtrfEBjYg5D/Aot2N09fxzzzUpkethOo9sk1RFEvl y3KvB3tbeR+0Q8wdSe5EcX2+0D5TxFJX4wsOz0MK6aAPHU8MS/tJzI5zx9afafbQBfw hI5vrRMIzBt/na673W7ByHSPaQoNAXhD6lCgS4hg= Received: from kampyooter.. (110.226.30.173 [110.226.30.173]) by mx.zoho.in with SMTPS id 1668249072566411.90214034857365; Sat, 12 Nov 2022 16:01:12 +0530 (IST) From: Siddh Raman Pant To: Mauro Carvalho Chehab , Randy Dunlap , David Howells , Jonathan Corbet , "Fabio M. De Francesco" , Eric Dumazet , Christophe JAILLET , Eric Biggers Cc: keyrings , linux-security-module , linux-fsdevel , linux-kernel Message-ID: <21ea7a96018db8f140d7c68ca75665064361ad1b.1668248462.git.code@siddh.me> Subject: [RESEND PATCH v2 2/2] kernel/watch_queue: NULL the dangling *pipe, and use it for clear check Date: Sat, 12 Nov 2022 16:00:41 +0530 X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset=utf8 X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLACK autolearn=no 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 NULL the dangling pipe reference while clearing watch_queue. If not done, a reference to a freed pipe remains in the watch_queue, as this function is called before freeing a pipe in free_pipe_info() (see line 834 of fs/pipe.c). The sole use of wqueue->defunct is for checking if the watch queue has been cleared, but wqueue->pipe is also NULLed while clearing. Thus, wqueue->defunct is superfluous, as wqueue->pipe can be checked for NULL. Hence, the former can be removed. Signed-off-by: Siddh Raman Pant --- include/linux/watch_queue.h | 4 +--- kernel/watch_queue.c | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h index 7f8b1f15634b..d72ad82a4435 100644 --- a/include/linux/watch_queue.h +++ b/include/linux/watch_queue.h @@ -55,7 +55,7 @@ struct watch_filter { * * @rcu: RCU head * @filter: Filter to use on watches - * @pipe: The pipe we're using as a buffer + * @pipe: The pipe we're using as a buffer, NULL when queue is cleared/clo= sed * @watches: Contributory watches * @notes: Preallocated notifications * @notes_bitmap: Allocation bitmap for notes @@ -63,7 +63,6 @@ struct watch_filter { * @lock: To serialize accesses and removes * @nr_notes: Number of notes * @nr_pages: Number of pages in notes[] - * @defunct: True when queues closed */ struct watch_queue { =09struct rcu_head=09=09rcu; @@ -76,7 +75,6 @@ struct watch_queue { =09spinlock_t=09=09lock; =09unsigned int=09=09nr_notes; =09unsigned int=09=09nr_pages; -=09bool=09=09=09defunct; }; =20 /** diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index a6f9bdd956c3..a70ddfd622ee 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -43,7 +43,7 @@ MODULE_LICENSE("GPL"); static inline bool lock_wqueue(struct watch_queue *wqueue) { =09spin_lock_bh(&wqueue->lock); -=09if (unlikely(wqueue->defunct)) { +=09if (unlikely(!wqueue->pipe)) { =09=09spin_unlock_bh(&wqueue->lock); =09=09return false; =09} @@ -105,9 +105,6 @@ static bool post_one_notification(struct watch_queue *w= queue, =09unsigned int head, tail, mask, note, offset, len; =09bool done =3D false; =20 -=09if (!pipe) -=09=09return false; - =09spin_lock_irq(&pipe->rd_wait.lock); =20 =09mask =3D pipe->ring_size - 1; @@ -603,8 +600,11 @@ void watch_queue_clear(struct watch_queue *wqueue) =09rcu_read_lock(); =09spin_lock_bh(&wqueue->lock); =20 -=09/* Prevent new notifications from being stored. */ -=09wqueue->defunct =3D true; +=09/* +=09 * This pipe will get freed by the caller free_pipe_info(). +=09 * Removing this reference also prevents new notifications. +=09 */ +=09wqueue->pipe =3D NULL; =20 =09while (!hlist_empty(&wqueue->watches)) { =09=09watch =3D hlist_entry(wqueue->watches.first, struct watch, queue_nod= e); --=20 2.35.1