Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3295213pxp; Mon, 14 Mar 2022 15:48:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxdQioiMyQ4qYnSq+5RIyiiEG9rEi40NNSZk2UKbjUJ4XuPSiFdsqDWX8ozhE9ve4VE5zW X-Received: by 2002:a17:903:228a:b0:153:66b2:16d8 with SMTP id b10-20020a170903228a00b0015366b216d8mr8149067plh.62.1647298117099; Mon, 14 Mar 2022 15:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647298117; cv=none; d=google.com; s=arc-20160816; b=znfVn5GFZgZxBz9rPZm6Sd2y65PhhyCGbl7L3UYGP8FIcXulceZZziAiXFkSeSXsgA rG5jL5ALVTlorQH09cRXnFRnt1HCUeTvjjW7POlxNgbykIcYQxFuCnUC/vC6pG5+EV8P idE+VB5rlGVrio3CGcKmsYxjj1NSvzTeYNBPU2SkLXUyrRuJojPLB/zk3kGncZS3rIn7 lYfThTGVAGJ4cDuejsbj3QY/prDYSq2HVPsyMDlgEpkbhtQWLTIIWZoJ4FEp8ytMuy41 LRvdJ1AcqFC6+VmgYcIDh5DeCQFzPz0zEqom8sY5FhqQe0b8HQIQsvdQvXId7FmYQPRt apbA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=pnmlfyHr7HPPQj7/5zlXGi2amzWnjEUzVrKnbTNeSmc=; b=x1ThNUUl/0fvluFJd5HNsKMClgHaHdWI4hRZYv4sUbJg23LWUIvcQtDBDlYn5CDvDV iD8WlwNC52LaXD+VIa5johwHuXOOphU7sJ/44comIQk6bMekjFVTXnIq+0SFUE7tRquS 9EFuUvaK/2GrZUkuDLFJFQRBCz1TGmdZ3PGeOi6KE6YYQbxMJNgV7Y8p4dHM8y8RZGjL 2+1r/evjTM+P7bckw2aABaxn7zSuWfmchW4Xqn4dYOyK3PScsPbnduwWBKVoB465SHGg evhQ20YShNYn44DT4W6vlqorljDakPbwKGtvYCDFGyQWjLCdj4id6IaqiUIBjQReqOD3 2J2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V5ldQgIE; 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 s65-20020a17090a69c700b001bf020c5dafsi425218pjj.32.2022.03.14.15.48.23; Mon, 14 Mar 2022 15:48:37 -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=V5ldQgIE; 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 S245679AbiCNMdf (ORCPT + 99 others); Mon, 14 Mar 2022 08:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243960AbiCNMVZ (ORCPT ); Mon, 14 Mar 2022 08:21:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B67213E2A; Mon, 14 Mar 2022 05:19:46 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2EAD5B80DF5; Mon, 14 Mar 2022 12:19:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C3D7C340E9; Mon, 14 Mar 2022 12:19:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647260384; bh=jSQBdgjmG/0puOUtBTQLeaUF/iDNY/kxEsrAKEP7R2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V5ldQgIExWWnNNi2rbqK6wadbGkR0N1kkUFXJ8wL2PMRrksaNfo0RpyAxS52Vo7Dr heigFBZGfxjv+ilKftp3WtjJPQ2yn4U4DfNDiqm49i59i9jYMLShIRhHNHF5d/vypw o+iYdk5Tq0Ab/8AIf8sdxFI6I5f5cjIbcQXsaLSc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , David Howells , Linus Torvalds Subject: [PATCH 5.16 106/121] watch_queue, pipe: Free watchqueue state after clearing pipe ring Date: Mon, 14 Mar 2022 12:54:49 +0100 Message-Id: <20220314112747.070105171@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112744.120491875@linuxfoundation.org> References: <20220314112744.120491875@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 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,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 From: David Howells commit db8facfc9fafacefe8a835416a6b77c838088f8b upstream. In free_pipe_info(), free the watchqueue state after clearing the pipe ring as each pipe ring descriptor has a release function, and in the case of a notification message, this is watch_queue_pipe_buf_release() which tries to mark the allocation bitmap that was previously released. Fix this by moving the put of the pipe's ref on the watch queue to after the ring has been cleared. We still need to call watch_queue_clear() before doing that to make sure that the pipe is disconnected from any notification sources first. Fixes: c73be61cede5 ("pipe: Add general notification queue support") Reported-by: Jann Horn Signed-off-by: David Howells Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/pipe.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/fs/pipe.c +++ b/fs/pipe.c @@ -830,10 +830,8 @@ void free_pipe_info(struct pipe_inode_in int i; #ifdef CONFIG_WATCH_QUEUE - if (pipe->watch_queue) { + if (pipe->watch_queue) watch_queue_clear(pipe->watch_queue); - put_watch_queue(pipe->watch_queue); - } #endif (void) account_pipe_buffers(pipe->user, pipe->nr_accounted, 0); @@ -843,6 +841,10 @@ void free_pipe_info(struct pipe_inode_in if (buf->ops) pipe_buf_release(pipe, buf); } +#ifdef CONFIG_WATCH_QUEUE + if (pipe->watch_queue) + put_watch_queue(pipe->watch_queue); +#endif if (pipe->tmp_page) __free_page(pipe->tmp_page); kfree(pipe->bufs);