From patchwork Fri Mar 17 06:27:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13178578 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 27968C7618E for ; Fri, 17 Mar 2023 06:28:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81C4A900004; Fri, 17 Mar 2023 02:28:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CBC6900002; Fri, 17 Mar 2023 02:28:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BA81900004; Fri, 17 Mar 2023 02:28:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5BB09900002 for ; Fri, 17 Mar 2023 02:28:04 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 23955161614 for ; Fri, 17 Mar 2023 06:28:04 +0000 (UTC) X-FDA: 80577410088.29.ADA43F8 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf13.hostedemail.com (Postfix) with ESMTP id 1AD5C20013 for ; Fri, 17 Mar 2023 06:28:01 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Olo84xcv; spf=pass (imf13.hostedemail.com: domain of ebiggers@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=ebiggers@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679034482; 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=c0JDgMnBzCqdBgTUnK3VMjMcir1ySBasseXgHmIxDBY=; b=lx1UU5dCRQarGQgv4S/okk6QJTkaGr02grqwebGEL4/VzMcbD3O1SRoAYpGDeAp2m/m6nH wtnEgzuJSreVYnqYnwJrZEgP6fMpm+VhgXNgvuNQ7GCFz5AjZOWSXDk5geKBH9+buKLEpk tQFoSeXaTv5R92j/IV16AwmSjdopdUU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Olo84xcv; spf=pass (imf13.hostedemail.com: domain of ebiggers@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=ebiggers@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679034482; a=rsa-sha256; cv=none; b=qjagKD/bQ8K/1mHmNw2kSVW249aY2DaPLEMAiMJM2/szs/r4aFc4isMDNhNp7RwWHigPHr P9tr0UDhitpSd7R46a5qVGYkcbe2woR1PQi3jXBY4YglDoceletATryJbl1w90rM1C7Lnp GF1zQFy2e0CiZwrpII3Oh/0dW1agP6E= 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 5E6E2B82454; Fri, 17 Mar 2023 06:28:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1835C433EF; Fri, 17 Mar 2023 06:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679034479; bh=3fkBr6DnHDeN/eXMdVoTQG5MehQUBo0jqCpgw9J1SVk=; h=From:To:Cc:Subject:Date:From; b=Olo84xcvT+7gC1s0ywQRSZuyhmzHQSgUTG+v3gUF4xWVtfoHylH+rjsT8Lm8h/Kkl CXw0dTIeMeJzYe60EImYatdHpiFOtZsL0Kyqcj//upGrdUYORlz3vt/TrJYRBu28eS 7OsiQtlwMIM/u2fnpk8rJYJERF5nM/9IbQD5aH2uZ/BPZCb4CrcywjU7+3J5IlZkbn UbsJcnGx1taxT+0XroGqCnRLovZ5S+MJ+tJKm4yuQ492rIXzvV+z3AUxw2ADOv5WrC s+zB68XbbW9/LSy3pUXrosgwvLETsoJiD+Pq9rhWRYKlnxVQoUwBLpfJfgPGE4EKKg PVk5jjpUYIJxw== From: Eric Biggers To: stable@vger.kernel.org Cc: Joe Perches , Lucas Wei , linux-mm@kvack.org, kernel test robot Subject: [PATCH 4.19] fs: sysfs_emit_at: Remove PAGE_SIZE alignment check Date: Thu, 16 Mar 2023 23:27:43 -0700 Message-Id: <20230317062743.313169-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1AD5C20013 X-Stat-Signature: nrfupkowoq9qeuw449eqy593ec35s43r X-Rspam-User: X-HE-Tag: 1679034481-4725 X-HE-Meta: U2FsdGVkX18U0XyAOhDwSjcWdvWuqa5YCXWqa0c4G3hsL/p4rg6n2reqETC6nfKgTP2WgKqQn9BKiECHUcDglvWrEuXeRDrHH+8qEZfIA6fVO6Qy3h6YOvz9Wm8E3gZN9yK0a0OkTZhLk6T1ewMYiMsJMoxIr2v+ebFN8rxAGBWAXrpfnII1xqImbuPXzx31Iks/7V5eDlPUUBh7eanvRymdGIxpAf2W4YRa/tQJ+tFgdyS8EAOB52zcfjdB3Y+8MuXtImNArmlpQJtd9Za0fiTsBh687LL3sWdNBmMuAIlzYvihsZ04KfDyn2X1GX12JW9HjVn6LraFdSL1mqjRjtJUjnIWILrDYjE0dhq0WkFfvlWN5iYUkdyIYmaed7oTXTbbDjnV0g0N86B/558YP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sender: 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: cb1f69d53ac8 ("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 011e391497f4e..cd70dbeeab226 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -599,7 +599,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;