Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3204920pxp; Mon, 14 Mar 2022 13:18:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy84EYMXThY4WUrY/97X7yh4BWd2rxJ8144o/ucKRLCs0YzeqQ8np1mtUbcIMWRFs3J5qmM X-Received: by 2002:a05:6402:1590:b0:416:3524:1f5a with SMTP id c16-20020a056402159000b0041635241f5amr21753141edv.391.1647289084232; Mon, 14 Mar 2022 13:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647289084; cv=none; d=google.com; s=arc-20160816; b=qoZtdGw3X/1QeRaBc9rend1UxJghl/lBNuowqjuq6JaAgaq8Cs6MuAGp6nnT8dK8oZ 4UMoInSQTiUV17SMEN/27b6vwVhpBUeezzaFOvUhbLYaEuqBv5yaST/zeyXZ3WmN+nid n9I3q5ria5QcjRhfAAmILMQGkauGms0xWvl4nnwR2EYppNiqF77ScR/aVtw2yu6ldudq 1+I9jSC/I9vm0EATnqx9UeUfm3fXKvbhXRMmv7kO/dRm+yGksB0agGzyKZ/+DOPeljzK I04uqv73eUE8wn2ToVMHGQOluB746QwQBnWKwg4QZgj9X8Vza1kC/T80rbBRk0akJ0lN 7raw== 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=MYinJlJiLFrfF5ZTWkx7u6NGtJkjuXcJV6Ut/3zK8xy2jEPtU5c7SoWnuGce0ZVJgE /sV62YuBBiv5J9MGVyPMkp2vtfRSgm48a4G9Jk83y20uRE8PyZDbfz2QNeobz+mW4DeG OpHaqTAUhW0aasd4Ep78S/r7Bwij66fcuI8jQOMAUEVzx1j0jV756GVYhYJqU/SU3yea SqDfl3nrj1z+ZrLc+N6apjFepuNLHCrfocEZ3Pw7AwWzHy3wk3UHbH50ElaNXX1lqH6O CHINs92Mv2tbpnDuDw5SudRCyJ1HVY3ipNjFoNHu27S8pMe9mqmf2PGljaAXT21HJJEJ Aimg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x8nKBUCz; 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 b1-20020aa7dc01000000b00410b5ff6c72si10208983edu.67.2022.03.14.13.17.38; Mon, 14 Mar 2022 13:18: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=x8nKBUCz; 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 S242731AbiCNMTc (ORCPT + 99 others); Mon, 14 Mar 2022 08:19:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240430AbiCNML3 (ORCPT ); Mon, 14 Mar 2022 08:11:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C241033E0F; Mon, 14 Mar 2022 05:10:19 -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 580C96130D; Mon, 14 Mar 2022 12:10:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 329EBC340EC; Mon, 14 Mar 2022 12:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647259818; bh=EpphPjkJYLQvxtjYHWazgFohtokZXh676sRXQzOPIuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x8nKBUCzORACQTi+rqkC7iHyPNt+CaZWu822hikb3mF1oh3oVvyJ9sRdyoSzXFpJu CswoeGPXy2EGimb4v6MHeZJYwxEYPKBObWWsZpoQHGoB0UHjYWksLWTGrWpLEFWB9W LgJTR20DUmpzIgf8FqsZXizTLpxSfOjtIQEiCchQ= 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.15 096/110] watch_queue: Fix to always request a pow-of-2 pipe ring size Date: Mon, 14 Mar 2022 12:54:38 +0100 Message-Id: <20220314112745.706611364@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112743.029192918@linuxfoundation.org> References: <20220314112743.029192918@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;