Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3351373pxp; Mon, 14 Mar 2022 17:28:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzT9FzutxtozQuYZWUiMCKxqo0eLLr/Te5R9RBo0OGArJuzpA7QkgOGtze1WlXh28fACdYa X-Received: by 2002:a17:906:30cf:b0:6da:9da6:b360 with SMTP id b15-20020a17090630cf00b006da9da6b360mr19644808ejb.743.1647304084074; Mon, 14 Mar 2022 17:28:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647304084; cv=none; d=google.com; s=arc-20160816; b=JDm9o3p9zd1yC8LNF93nYpfs2atxJUJAHqaOqU0ZMv1ZWf3Y5OTtfHAz2iUtp0w+10 uX4KYBp0fAbXYp2+fMm69lMvyUfdbBLzNtIw0U7goBWGAr04pBSQqdpz6WN/KN+2mqJ6 RHNMbhn6m6swjmsrM/WbsXZaizWdXhR5N0Qaq7qo5gBYFlXBT9cAk/Ipl8CkyF2/pG7f 07LZTTnGM90x4bGVFw2FN5YHl/niweLUTqIxMoMkBcROa/jfR4Uc86R8j8yDAqHIsN7i JeiZgbt+Wq/AJ4hM7aiz8ZHj0VO1JmXMCP+PHhw2q4dNBM0j+BgZ/V3ejLvoIyLiSkJM yLjQ== 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=wW9L6Gl2XfsdXHS+5I6SDrcCcT6DjrT/zMq/mbGr++8=; b=A0EccDyCGfu8+oDEUb+qHBj3SvGVuOs+jG8auy/snnfdCB3T9xZyhTK1dHUYXcOnoa b+NdbT7gavrkw/3bV5mutEUR0CS1UDrTaXMMsCtI6P1fSDslCglUr0SmOGlARRu9lPzm sy/LamVBdolimpyeaHMK9jBuznkr6PANhNwHy5Snq6PMj+TmPZu6NLsrmitvd6C8V8rg VP9lzs79LZU+RzoHnmdeEtThA1welIZG2PDxxQhob1vGj01qTTs6R7VVEkVd+Fsazq4o cspvCmFXc1sqca0+3coyXP400LIaXXz47sg5XbsXVNdYUJibW4+e4FLk3w9QIe3QvjFt +Cyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cvlO3Qbb; 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 e1-20020a1709062d4100b006d209a97bd4si10188666eji.410.2022.03.14.17.27.39; Mon, 14 Mar 2022 17:28:04 -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=cvlO3Qbb; 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 S245564AbiCNMdM (ORCPT + 99 others); Mon, 14 Mar 2022 08:33:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243944AbiCNMVZ (ORCPT ); Mon, 14 Mar 2022 08:21:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D445F13D31; Mon, 14 Mar 2022 05:19:13 -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 884EFB80DF5; Mon, 14 Mar 2022 12:19:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B62D6C340E9; Mon, 14 Mar 2022 12:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647260351; bh=EpphPjkJYLQvxtjYHWazgFohtokZXh676sRXQzOPIuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cvlO3QbbvI04hZhtXtHTbnW9zdFi5y1v62bfYMoTkolmdHF0vDMcGRvFbDnwrKGcU u8QlQFMO0k8FKo0GPJYyoV184EiK3FoqJMxQ9mfZaSDm5cASN6+tE60mLa3caWhaKn VYs2tLJoA45QCi5tegWK004mrnNC2WalEIWyHp4w= 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 108/121] watch_queue: Fix to always request a pow-of-2 pipe ring size Date: Mon, 14 Mar 2022 12:54:51 +0100 Message-Id: <20220314112747.124927943@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 96a4d8912b28451cd62825fd7caa0e66e091d938 upstream. The pipe ring size must always be a power of 2 as the head and tail pointers are masked off by AND'ing with the size of the ring - 1. watch_queue_set_size(), however, lets you specify any number of notes between 1 and 511. This number is passed through to pipe_resize_ring() without checking/forcing its alignment. Fix this by rounding the number of slots required up to the nearest power of two. The request is meant to guarantee that at least that many notifications can be generated before the queue is full, so rounding down isn't an option, but, alternatively, it may be better to give an error if we aren't allowed to allocate that much ring space. 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 --- kernel/watch_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -244,7 +244,7 @@ long watch_queue_set_size(struct pipe_in goto error; } - ret = pipe_resize_ring(pipe, nr_notes); + ret = pipe_resize_ring(pipe, roundup_pow_of_two(nr_notes)); if (ret < 0) goto error;