From patchwork Fri Mar 17 06:28:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13178579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FBFBC74A5B for ; Fri, 17 Mar 2023 06:28:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB3F0900005; Fri, 17 Mar 2023 02:28:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6452900002; Fri, 17 Mar 2023 02:28:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92D05900005; Fri, 17 Mar 2023 02:28:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7FDE8900002 for ; Fri, 17 Mar 2023 02:28:11 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3820681745 for ; Fri, 17 Mar 2023 06:28:11 +0000 (UTC) X-FDA: 80577410382.22.ACE4330 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id AA04DC000C for ; Fri, 17 Mar 2023 06:28:09 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=S5Y7ErLY; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of ebiggers@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=ebiggers@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679034489; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=ywR3C/Lu7A4DOKi5NIzVu4oI0T3hwv+hWVoYfKebKVA=; b=YrHGuRZlPp92YRssN4hB3Yg3DRTqjHBS17WVDU9RAS8L4z+24OaOMtqjMoQf+ZxwFEPTvU aYGHdVkLgLFiS2UfcKNADVS9/QfnprNSNs09Sw3+UbShds8H2fOvBIOlMmZoYIsH5VwRXr ffLs4Olwh4VPZHAHxbMwuLuNMNOPsvM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=S5Y7ErLY; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of ebiggers@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=ebiggers@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679034489; a=rsa-sha256; cv=none; b=1UzahbGN7CPKtkv484Ny4aXdRSceXiGryLUw3zB6G8fCFsahm75qLI9vUVOuA4/SiK8Jwq 59e0Dixq8BJbP0Y2+LufwEdY8qHFgrQTehUokGMNWEBHGPNQ2bZhrlEtRrZgTg7x/R/aje 2VYLQt4r01+iX7ex1fxwIRZpXF5plRs= 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 A6B906219D; Fri, 17 Mar 2023 06:28:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7228C433D2; Fri, 17 Mar 2023 06:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679034488; bh=2SxOdzm+r3/sPGp8ge5VqXjBoGywFgq+J+bF4fiT+9g=; h=From:To:Cc:Subject:Date:From; b=S5Y7ErLY7iKaRCzRLtpCdaWalRCgqodMisu1pTjrAdKLvnZDcaf/WXovvkUDmHQMo VDu+8gyhtmJEKqGD291pOiwzJuoA7q1c2t/R8EuR5ne0jxyyhiPl8lMPCfK2Wz5nGM PIYbp443w6HzWGomEzRXWbzZbyI21m9CmJ/p3rYU7PP52M7NJQ4OqiztE+ZIG26aFX gQta0rYAsIvSNFKdIge03+2nFg8qD8DQHbctwUnN8iL589+31NG6xV7l2RI6xka/ZM gqrSMQZXZwMPq5dBuhknmooOaQhrdY6mjKd31uCO76ykje3zexTyjC+Uqs5CLuQGbi B/A8wcylTOWsQ== From: Eric Biggers To: stable@vger.kernel.org Cc: Joe Perches , Lucas Wei , linux-mm@kvack.org, kernel test robot Subject: [PATCH 4.14] fs: sysfs_emit_at: Remove PAGE_SIZE alignment check Date: Thu, 16 Mar 2023 23:28:01 -0700 Message-Id: <20230317062801.313217-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AA04DC000C X-Stat-Signature: bmizoigo6qfye61xpfpn9i8kpef9t59u X-HE-Tag: 1679034489-701579 X-HE-Meta: U2FsdGVkX1+fJ+L252+xG2dOD4whCz+90HNzJ6JiieEe3r7IcQ3Ben+52DC1kc0wgxjlGPZhMMA8qlVDEOSlWbq2A+Mn8YcismgqCBkPagtoMZ/Q/DolsLfXLShET7yZUf6Ut7p31tefV0O4gamfR4Tmqrv8BcEB+tm5Sz6ft4FxDlojVrygN1ALsLA+P6OJRflYrE0cx5Me/HRsC80Fy3TFYEWT0wLWjfwIl55iMglLR6rrZn1F4SY5NaMerHD5v0rFRgi/i9icsI9dCplG5fH7L+0dbJwpsDq57AGhlfivGnT3F7qq2Wk6GDWTr+D8XoaGWFKsK7Zfhvep1mmxwJ0dXRC8rWRSEw+kAwarO+z+3gyN6R6bqrn+3t21TavRrucaVOtSo3X4jy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ender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Eric Biggers [No upstream commit because this fixes a bug in a backport.] Before upstream commit 59bb47985c1d ("mm, sl[aou]b: guarantee natural alignment for kmalloc(power-of-two)") which went into v5.4, kmalloc did *not* always guarantee that PAGE_SIZE allocations are PAGE_SIZE-aligned. Upstream commit 2efc459d06f1 ("sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output") added two WARN()s that trigger when PAGE_SIZE allocations are not PAGE_SIZE-aligned. This was backported to old kernels that don't guarantee PAGE_SIZE alignment. Commit 10ddfb495232 ("fs: sysfs_emit: Remove PAGE_SIZE alignment check") in 4.19.y, and its equivalent in 4.14.y and 4.9.y, tried to fix this bug. However, only it handled sysfs_emit(), not sysfs_emit_at(). Fix it in sysfs_emit_at() too. A reproducer is to build the kernel with the following options: CONFIG_SLUB=y CONFIG_SLUB_DEBUG=y CONFIG_SLUB_DEBUG_ON=y CONFIG_PM=y CONFIG_SUSPEND=y CONFIG_PM_WAKELOCKS=y Then run: echo foo > /sys/power/wake_lock && cat /sys/power/wake_lock Fixes: 390881843b4f ("sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output") Reported-by: kernel test robot Link: https://lore.kernel.org/r/202303141634.1e64fd76-yujie.liu@intel.com Signed-off-by: Eric Biggers --- fs/sysfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index c41e7f51150fc..cef9a469f73a8 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -592,7 +592,7 @@ int sysfs_emit_at(char *buf, int at, const char *fmt, ...) va_list args; int len; - if (WARN(!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE, + if (WARN(!buf || at < 0 || at >= PAGE_SIZE, "invalid sysfs_emit_at: buf:%p at:%d\n", buf, at)) return 0;