Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5130115rdb; Sat, 16 Sep 2023 04:25:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFncXoSdQZN/OWWMJYPZy1UGVTpfCCK7SCNCwVhdPI7SrcLQdAS8rJJfpzdmgY6IYXTxCGa X-Received: by 2002:aa7:88d3:0:b0:68e:380c:6b13 with SMTP id k19-20020aa788d3000000b0068e380c6b13mr4362433pff.15.1694863558857; Sat, 16 Sep 2023 04:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694863558; cv=none; d=google.com; s=arc-20160816; b=c+ZaQnrS8e9lb0CI0rOnJxAzGWUQoKUfZJCjFr1AldkcZMRJ6hg/xeRG3wyafSxFId DHSBLmd3+S0XFtGE54u03FHnclJvpx9P67PDRMywMwaSMzb8WF6dZz41whj1Pty0kkpb glc5SzGeSATlp383ujYVR29r5XXZOC6CWu5plv7ErnN35SDliE/dnLLziBbm3r2nMn32 1QqDgsV0gGHeoR7H3iucrOLIA1NUfU/4ifmXw8JA+MNdyzURC2P5j9Bg/S8IkQC0LE9R BMp2vN+nbZXJWXrx6w8dL11HU7K1sgYSPu14inxgmgnPLQZU+5+W5HCQ6YkPlh5+IIY2 1EXg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=cA7WgRDiydPCuNf/SfhbEh7C8ImUKHG5ugsQxiw8lwY=; fh=m3UyueLH4KDy0H9ZPaSnoQRYWYiD76Xl1Jq/Gorb8Ss=; b=g+ZydQB0mRAQWnahJFA/VRAMcT3HrsXlEt48iPDgkSKKfi1DLRUKkHFMCZ/Mc7mFX8 w62RqXmRQByVnBlfkM0bxvEHAlVXvtSWgzM0bvQ2hAfKKDajluhCvGPtWU9aUXizVgC6 M/IPhVe2sArUdNPjporw4cMxEqBJPx1N8X2euGEfIP/b79joxLJFiDPtnhbB1/xNhj4j rWHRiBGmdTPkS9S0gHdLkBrcH3M2grcx59x85K1nc2b96uGcMotnxIMzd8YYeW+0vY0X iUu53plR268XUhsjvgzbkCzvzWaBXGdLIt9JL5Kj1qBw2gkbNKYKyBrWLzJ+nLGFIhIy ggjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=PXR0QG3l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id 5-20020a630d45000000b0055be9543340si4680554pgn.872.2023.09.16.04.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 04:25:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=PXR0QG3l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0CDF0836B0E3; Sat, 16 Sep 2023 01:50:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235502AbjIPIpo (ORCPT + 99 others); Sat, 16 Sep 2023 04:45:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjIPIpe (ORCPT ); Sat, 16 Sep 2023 04:45:34 -0400 Received: from smtp.smtpout.orange.fr (smtp-27.smtpout.orange.fr [80.12.242.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A774E6A for ; Sat, 16 Sep 2023 01:45:28 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id hQvcqqzCHBh1whQvdqxVHj; Sat, 16 Sep 2023 10:45:26 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1694853926; bh=cA7WgRDiydPCuNf/SfhbEh7C8ImUKHG5ugsQxiw8lwY=; h=From:To:Cc:Subject:Date; b=PXR0QG3lTF7N9XgySHtDSVHe2gdPAui/WnZoRa2jD4u6bFFju0FxGWZXXpgOZ1Zub KaQs4MkZCze4W+AMVDuwKYr8+oaTF6byXp83/WAYzoRA7GEmubQr/z9h8XQRMwjXWM fjsxpRFwwwIwS2+9X0J2TCLn7jaeTuWD6s/P92SYMiBYo3C5UIu6gZctUDQpTC5GC7 U+E0x0M+VWXIphkCqGJq0xN92+f7T61PVW7QbcGpbAVX2jlrOajoTJ85Slb9rkos/6 uhyGVLXfiA8veXc5cyAJI0m/+LI7VNsa4fkaaGCwPNFc2YT45zm+pcgSPs/R6DTD15 4VJ86sWwTPdUQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 16 Sep 2023 10:45:26 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Kent Overstreet , Brian Foster Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-bcachefs@vger.kernel.org Subject: [PATCH] bcachefs: Avoid a potential memory over-allocation in bch2_printbuf_make_room() Date: Sat, 16 Sep 2023 10:45:23 +0200 Message-Id: <2e6a82a83d0ddd9ce7f36ea889dd7ffc30f5fbc9.1694853900.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 16 Sep 2023 01:50:01 -0700 (PDT) kmalloc() and co. don't always allocate a power of 2 number of bytes. There are some special handling for 64 --- fs/bcachefs/printbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/bcachefs/printbuf.c b/fs/bcachefs/printbuf.c index 77bee9060bfe..34527407e950 100644 --- a/fs/bcachefs/printbuf.c +++ b/fs/bcachefs/printbuf.c @@ -28,7 +28,7 @@ int bch2_printbuf_make_room(struct printbuf *out, unsigned extra) if (out->pos + extra < out->size) return 0; - new_size = roundup_pow_of_two(out->size + extra); + new_size = kmalloc_size_roundup(out->size + extra); /* * Note: output buffer must be freeable with kfree(), it's not required -- 2.34.1