From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43292C2D0DB for ; Fri, 24 Jan 2020 11:30:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A47F20838 for ; Fri, 24 Jan 2020 11:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865426; bh=CSrVAb92O7NkKSIvRYu1HQ4EwpqAhXkYk2ZUtsyk3G8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=IgX1jKiQQwtAx6XAQuhoi4yiYauS3o0WGZQBGPUUDiFt3bQPvok7nBSXQ+0aU3MQa lebGsL5LwPevWxxJbr+WEl5o9INesNy6A+WOrJsRxUFu8sGRQ4IoUMz2Nr0dOJZ2Fl 2f0sBRbly80SZhhjJ7Zx+zR6Njeg51hIs36sKLAA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404219AbgAXLaV (ORCPT ); Fri, 24 Jan 2020 06:30:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:47870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404198AbgAXLaR (ORCPT ); Fri, 24 Jan 2020 06:30:17 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7F28D20718; Fri, 24 Jan 2020 11:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865416; bh=CSrVAb92O7NkKSIvRYu1HQ4EwpqAhXkYk2ZUtsyk3G8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PVTrELsQO72wCKOBungOHz54A1akaDKgw6W6PmQsWLb5X+X948YDEdwB9ljqatD+W +T37vQvv1uXTfyX/AaAnMN5NE3VZJTV0MgI/FqUtPUTMeNFYNZTHg2gf3wxkYygcZ4 mK/9Q6c8yvkhz9Eymj3AUdqkcwJetVl87qODap8c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, laokz , Stefani Seibold , Andrew Morton , Dan Carpenter , Greg KH , Kees Cook , Will Deacon , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 527/639] Partially revert "kfifo: fix kfifo_alloc() and kfifo_init()" Date: Fri, 24 Jan 2020 10:31:37 +0100 Message-Id: <20200124093154.822644212@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Torvalds [ Upstream commit ab9bb6318b0967671e0c9b6537c1537d51ca4f45 ] Commit dfe2a77fd243 ("kfifo: fix kfifo_alloc() and kfifo_init()") made the kfifo code round the number of elements up. That was good for __kfifo_alloc(), but it's actually wrong for __kfifo_init(). The difference? __kfifo_alloc() will allocate the rounded-up number of elements, but __kfifo_init() uses an allocation done by the caller. We can't just say "use more elements than the caller allocated", and have to round down. The good news? All the normal cases will be using power-of-two arrays anyway, and most users of kfifo's don't use kfifo_init() at all, but one of the helper macros to declare a KFIFO that enforce the proper power-of-two behavior. But it looks like at least ibmvscsis might be affected. The bad news? Will Deacon refers to an old thread and points points out that the memory ordering in kfifo's is questionable. See https://lore.kernel.org/lkml/20181211034032.32338-1-yuleixzhang@tencent.com/ for more. Fixes: dfe2a77fd243 ("kfifo: fix kfifo_alloc() and kfifo_init()") Reported-by: laokz Cc: Stefani Seibold Cc: Andrew Morton Cc: Dan Carpenter Cc: Greg KH Cc: Kees Cook Cc: Will Deacon Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- lib/kfifo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/kfifo.c b/lib/kfifo.c index 015656aa8182d..6320ab91e3431 100644 --- a/lib/kfifo.c +++ b/lib/kfifo.c @@ -82,7 +82,8 @@ int __kfifo_init(struct __kfifo *fifo, void *buffer, { size /= esize; - size = roundup_pow_of_two(size); + if (!is_power_of_2(size)) + size = rounddown_pow_of_two(size); fifo->in = 0; fifo->out = 0; -- 2.20.1