Message ID | 20240123002814.1396804-56-keescook@chromium.org (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 1E28BC46CD2 for <linux-mm@archiver.kernel.org>; Tue, 23 Jan 2024 00:29:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A908A6B0074; Mon, 22 Jan 2024 19:29:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A405E6B0081; Mon, 22 Jan 2024 19:29:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 907BB6B0082; Mon, 22 Jan 2024 19:29:16 -0500 (EST) 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 7D7FE6B0074 for <linux-mm@kvack.org>; Mon, 22 Jan 2024 19:29:16 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 17D41C0809 for <linux-mm@kvack.org>; Tue, 23 Jan 2024 00:29:16 +0000 (UTC) X-FDA: 81708691512.30.158342C Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf11.hostedemail.com (Postfix) with ESMTP id 284864000F for <linux-mm@kvack.org>; Tue, 23 Jan 2024 00:29:13 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=dNnNIlKb; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf11.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.171 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705969754; 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:in-reply-to:references:references:dkim-signature; bh=4kSZcErhkvLURXFhEcykitt7q+k1IsSKXy6VMnrbEx4=; b=aFsDxMojXQB94vBEhe7uivEzsf3aLkDPZlVDUnhWvxJ0qTW1xVGJEG5dfw58bi00JJCeuH yWYS69xQ6cFp2rrekh3qDoKufcYus7/6NxZvP1QKiI/PsMALmF4MGcL2Sor4fGbJB9kSjZ oK0gtk0oOcCdMpbT/MBPrysMS+YHelQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=dNnNIlKb; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf11.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.171 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705969754; a=rsa-sha256; cv=none; b=ymeYe0COOd4azGxyAgDhRQlfIgnpaZqeH5AgWZLeex8xHW9soPWu3Kmfuik/nFcTj7t72e biLP/8En4FzFZjfvi3e8OOaWx6Y4He+I8XG6Hl+lQQrGmw84/fLWQIlWvTJX/5TAdEhPCD ZJQjZfKi5p9fraZDqZcg3FTSxcGGEck= Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5cde7afa1d7so1761975a12.1 for <linux-mm@kvack.org>; Mon, 22 Jan 2024 16:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1705969753; x=1706574553; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4kSZcErhkvLURXFhEcykitt7q+k1IsSKXy6VMnrbEx4=; b=dNnNIlKbM8Xe5sfoWrKlZxk7nYgTSZu+Cihc03PMkh6IYttGsBL0Pqwd8O+IGveRVG yisUgcYdzgY9wx0UemaVCNpvpeS0SDZProI8VHak7KVtxLb7nUbyUg26QnoP+KRGn/p4 7eiqIwX3c5XdeIhLvwVTbQx2/w0S8CNQRQOho= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705969753; x=1706574553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4kSZcErhkvLURXFhEcykitt7q+k1IsSKXy6VMnrbEx4=; b=bcE1FI+tUcwW5E77RgRYVcgwO9CdZxSenMcLZ3cBdetUlD5lneyelKabJsloCWbVc9 58JcSaTa/RTohXtSpdL3pPQa+zww7QC17kMu8Dy4PNTRTfCLQeWaMVGSL1BgE+wH3KoL k/TGvuB3h2rLy2Q4W+AXAXvzMPy6hcjlI2QFwsYIUZXJk9AC0CXdtVlBu2AJB3LfQl6b BLLVJJs4bRfMcEaowHxCAcdbymcRnlF8YIFMN5zJ3DKQbyAAI7heP1A4j+w1kL+x0lYE xyzTfOhvv/41oCpNEc1J7wRbNyfOAH47NXeYj6qyvjj5RlswnoX+Mt+BZOusE6xnkuwU fpww== X-Gm-Message-State: AOJu0YwdcSeSgtPbxHa9CmWzgldvp/u13d1/gQsDIdESIVX2vbEVHlvp CF90wu+zs1kxTe+rG6azuCmnLaRi6I1gDIok4ddMsY67Bx1TAhxHAwppjbQOjA== X-Google-Smtp-Source: AGHT+IG3RDfq5susdGGtZ5t8hNNXczrgazB2fai6AkFle9yipHha6eOEWBtXrxnRKsK0nSd5aI3KHw== X-Received: by 2002:a17:902:c946:b0:1d7:ad4:7d9 with SMTP id i6-20020a170902c94600b001d70ad407d9mr2794072pla.60.1705969752949; Mon, 22 Jan 2024 16:29:12 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id b4-20020a170902a9c400b001d74b1ef56fsm2652747plr.271.2024.01.22.16.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:29:08 -0800 (PST) From: Kees Cook <keescook@chromium.org> To: linux-hardening@vger.kernel.org Cc: Kees Cook <keescook@chromium.org>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org, Bill Wendling <morbo@google.com>, Justin Stitt <justinstitt@google.com>, linux-kernel@vger.kernel.org Subject: [PATCH 56/82] usercopy: Refactor intentional wrap-around test Date: Mon, 22 Jan 2024 16:27:31 -0800 Message-Id: <20240123002814.1396804-56-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122235208.work.748-kees@kernel.org> References: <20240122235208.work.748-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1952; i=keescook@chromium.org; h=from:subject; bh=Le2cw8/EMeZDvyWiTZfIKGAqobpbeo1xxbxe1eKIEog=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlrwgJFBcLI030OvWlIdf+JlEl9ZpGqp2xZrVGc OF5/tb3LLKJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZa8ICQAKCRCJcvTf3G3A JlAfD/4hK8oQxeilJy5M1BswN23KROlrOk+00GSMbycYwZKmxQcAxh0DnW23pgXbeUgj2xRlH7k /F+1z4vu9eaAj8Y/Y9hBh2STz4jydgyEv7WtfzL7Jw1BNKRrtbBNLwAwKJ0huo8jHVSKWwPVexP H0dsQTMPDxMkMaS77DgFrqDnf83+cga/jJS5LHAev1F3Rt7Vzx4KZTVfeW2Dto3dvVvaDA7Mr1W zclIJH/mqpfAZHnTuBX0Lc9+8RKLG4qO+2/IUsGeLKMWwR1WVPmDTM2bkl/aMTUuS9zUOBkJ+kz KOHdKKXC1Rs12cJXs6FaDHdaa14Rs0A4hpkuD5hOdyzaS307IhV5depO3u68Tj2Uik5iOAg0Sd+ mbpV425cNRUyFHClpds5aX3e702vMEC0hgaOLiRwlk5K3u6RQW1N7GluN4un20Sn6BhkHSH4U+N YixLEE2YDQcd7gaZZwk6n5ylkZBndaXc6h2B9qpnebQVrz7cHnXCvjJ523k41Bmm1MZTcW9H7Np ST8joAjzTwXfRq5dJvhigwFDMdUGFtxsZ2soh6RZ/+fTiuyYL+m8B2frhQ33eS/G9AbMn6WFBxK EFYGaKAJmKlp3x8HgzZyfaTqO4BFToZOSpxteo584SQH5dsfYvS3kwiZW/3iIX05kIzLTWTZTqU IgI+hkYy5CRcMww== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 284864000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6asoegfn4bxthmqncbjy81yghztapcob X-HE-Tag: 1705969753-119588 X-HE-Meta: U2FsdGVkX1/6TSY06kW0CrwfX5wRGvZSgLlXOnhyGHgwPQcSrAhEC4Ee2ypl/aKIdHXAQM8YACjD20hZe0xZRtn77VFdha0+8tr3SKcL90iwcTx1nWxudhEYPvEGuxbYh6h7b8mct54UE2Nwm6ubf/x0tRU2IX6FxcvNv8DR0uPbaYbq7MV7CVvsB2C7ZxkMzfpl/mbKZbzZkZlAzfG1aqkvJ0XaNWVtQrRD9nejt+fbh/SVNPoI20j5StOb1VIYPGTg19hkn1bQPrKgLfJuL9AF2as5zMUJFcIvz/jiX4DZ218pPXtuk+bIQAqcmpVWqgKBbaNSYnfM86fDRIesafaY/EsNVmM2+E5859CJ6jXkyAzQX2vmPwKBDXKnnxlRo67JTHVxCDHTHGqIdCCCXsuUFTZa12E9RhCpKVjfivl83GvrBZ8PRZyCZw5isP/WtR3X8043UES4j8PsJcBAwQhfgqLnkSfNY/OmyhiLofRFqPlgmoG7JOA+5aCmwUIOtkKqn5uoP1ZX6F0mS/Vif1aDaYElTSvuLSzV0zYmXZRNcXiafTR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002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
None
|
expand
|
diff --git a/mm/usercopy.c b/mm/usercopy.c index 83c164aba6e0..5141c4402903 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -151,7 +151,7 @@ static inline void check_bogus_address(const unsigned long ptr, unsigned long n, bool to_user) { /* Reject if object wraps past end of memory. */ - if (ptr + (n - 1) < ptr) + if (add_would_overflow(ptr, (n - 1))) usercopy_abort("wrapped address", NULL, to_user, 0, ptr + n); /* Reject if NULL or ZERO-allocation. */
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Refactor open-coded wrap-around addition test to use add_would_overflow(). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: https://github.com/KSPP/linux/issues/26 [2] Link: https://github.com/KSPP/linux/issues/27 [3] Link: https://github.com/KSPP/linux/issues/344 [4] Cc: Kees Cook <keescook@chromium.org> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: linux-hardening@vger.kernel.org Cc: linux-mm@kvack.org Cc: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> --- mm/usercopy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)