Message ID | 20240123002814.1396804-82-keescook@chromium.org (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show
Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DFEF7F7E8 for <linux-hardening@vger.kernel.org>; Tue, 23 Jan 2024 00:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705970760; cv=none; b=UvvpwNzLdZQ5XXGSBWrzZyQK9tSEYh6epL8gDA5cyybqpG3FZcl1mxq0byXY0c1GC4cb81kFXKPvD9FDY01WOtbD+fWYQ/wBWFExp63RHEbmPC65SXny1j9rECnXB1/ghQ/BfzKHtE+VS0yLb2kkAZ2no058lk6RyijTe7PHNXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705970760; c=relaxed/simple; bh=otrmpo4br5ciuWiM78a/Ceyb2KdAR01tXk9aBpC8wMw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QEnvWsG32TUhwD2u3DdaSnLsKoC14/QbVWQCaNQUTZzh89C0BPQCOvBXOj8Tw9JUrXYxrLhMm+uaFyUjXXFYHWzuNPJ2W+bJUuDudKuC4rffXRKuqOYlYC4xpBI605cfK9DVMVHAgIDYugVpye7R7GhkeF3cW1mGeu508DoIbAI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=eisSFIOg; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eisSFIOg" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6da202aa138so2923481b3a.2 for <linux-hardening@vger.kernel.org>; Mon, 22 Jan 2024 16:45:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1705970759; x=1706575559; darn=vger.kernel.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=S7qeKC064ZzlHJa5msLrHHdCXg1stkKcC4+dJKmdneQ=; b=eisSFIOg4fJ3vz+bS/iu3KnkrgcvtlmfD/uWTb7T5vEdGsjqRSMe86hoDv4U/tNV+Y 4Vj4tG2KD3+v7KuRhIlPs7aYoprJNO0SANxUOoVQPNyca6DmEvSB9eGQvrL3ij81cGQa r3jFVmpg6E4I3ga+Km1hyGgbM2j2k2pJdlKr8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705970759; x=1706575559; 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=S7qeKC064ZzlHJa5msLrHHdCXg1stkKcC4+dJKmdneQ=; b=QIpiBnir5LpfeGAUYN+8okJusbDS84AC24dCxn4IZZpZgjK/qxCzctyy1QPkAUZX8F yLHN+Y69AKEKYq8GKLpJHkR2hCw+u/Bvp+1SjRZbTVsZLXzMrPVSjHjtG9j1k7pbWj9f pOz3JbbBqeff4nvHfO7SiNYhB/SJwYhnDtC9Vf+sdsUbK6jvxXuaQgFg+OH31h7pE/4z htHyNoFxcCHVYfOKmrABE4L+MEJbBdHU+E82inJt7vZqON0MZok89VTUdQm9pygl3XC8 c0UrNOfSuWgvxoOQqTBKRejxYX8o9DHibj+j+RQcCHGn6v9ZN7NGJdgP1ZOqxfHXTGVr RpYw== X-Gm-Message-State: AOJu0YwxzL9syg5jj0k7xh73SjxMgFWhHKeAaQAhoqvBlsjqvWeot/Wo xv0E0orGtKcgxoTF5VR4AvmlET0VODv7Ito0nY2gX5z1bjhyngqUIHj1eI30L4yBVZRXCmXD+I4 = X-Google-Smtp-Source: AGHT+IEfPSCAfbNkrsnvfNR/6lrRJTvzZ8aFbU2AhLJiZvXczWMg97ditkNX3fZkM39QiMucgiQfyA== X-Received: by 2002:a05:6a21:32a2:b0:19c:30a5:5c54 with SMTP id yt34-20020a056a2132a200b0019c30a55c54mr4120604pzb.28.1705970758815; Mon, 22 Jan 2024 16:45:58 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id dj11-20020a17090ad2cb00b0029051dad730sm7733772pjb.26.2024.01.22.16.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:45:57 -0800 (PST) From: Kees Cook <keescook@chromium.org> To: linux-hardening@vger.kernel.org Cc: Kees Cook <keescook@chromium.org>, Christian Brauner <brauner@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, "Eric W. Biederman" <ebiederm@xmission.com>, Dave Chinner <dchinner@redhat.com>, Alexey Gladkov <legion@kernel.org>, Jeff Layton <jlayton@kernel.org>, Waiman Long <longman@redhat.com>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, Bill Wendling <morbo@google.com>, Justin Stitt <justinstitt@google.com>, linux-kernel@vger.kernel.org Subject: [PATCH 82/82] mqueue: Refactor intentional wrap-around test Date: Mon, 22 Jan 2024 16:27:57 -0800 Message-Id: <20240123002814.1396804-82-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> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: <linux-hardening.vger.kernel.org> List-Subscribe: <mailto:linux-hardening+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-hardening+unsubscribe@vger.kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2072; i=keescook@chromium.org; h=from:subject; bh=otrmpo4br5ciuWiM78a/Ceyb2KdAR01tXk9aBpC8wMw=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlrwgMplzxY/SLj9+bxbGPriiBi7drTq3OXWSJm svPwIQ44g2JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZa8IDAAKCRCJcvTf3G3A JkmCEACY37o5F1LgKmBQ/X+GY7t3DI3LwjJCZxndVTmZbmKfVSOia2DA4d7XI1UV1bLDavheiOD ZspAXfK1XmENeXellFyMfyPquNHRcsarUQ1eWVcWnrDOE0opNQOc0QFe+6R8uveX/n9ivxN6Wa1 hOaIRaYdtaG0pl0/p61larNEe0AnWHy+RtEMHuE39N9gWCpwcPqHoA5mCo1dxrD2K2uh/qlF7ES OzWJchorCRsC5GNs9Ui0GFKsf6zpgZU/FyCbyLayRLUF4nfFP2LiO3h9b6WRp0vltQF54wKsTNu KqLuPuvIO0elWbihDwdLbI8EutfMxrfBmbbk7MzP7yL8iwl37lrpoXTKwF75rDVE1n9y0I33Z3e kbO+/3Rj0fjARWduA04Taqd3iu+/l1YaEl+sm0k+KsXXpau+AtqNR9KyrfyBDpM8DRtqXNx8mvs P4VT9g7ZVTJqargqoTFlGh5dcyq+u0cZGRvguOrlRuIGifiAE6HPv46NzI8V4HCRdFKqGQ/5XR3 guih4Ak2DS4ygw8ba5mwnBdRsQiwDjfWRY9xwAc10W8T4ZikUx8/kDV0HnL2+ZQNa1zKFuQvnaK AnAki/aXhT0xQPUk4ZlJRdVZJ1v3xn7aOA4UscmWvvlFVA4Yj7/ScJZKtoGdQI2rcgZYM6BAU97 FairA3wiIkm3Fdw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit |
Series |
overflow: Refactor open-coded arithmetic wrap-around
|
expand
|
diff --git a/ipc/mqueue.c b/ipc/mqueue.c index 5eea4dc0509e..7ef9d325183a 100644 --- a/ipc/mqueue.c +++ b/ipc/mqueue.c @@ -366,7 +366,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb, min_t(unsigned int, info->attr.mq_maxmsg, MQ_PRIO_MAX) * sizeof(struct posix_msg_tree_node); mq_bytes = info->attr.mq_maxmsg * info->attr.mq_msgsize; - if (mq_bytes + mq_treesize < mq_bytes) + if (add_would_overflow(mq_bytes, mq_treesize)) goto out_inode; mq_bytes += mq_treesize; info->ucounts = get_ucounts(current_ucounts());
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: Christian Brauner <brauner@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Dave Chinner <dchinner@redhat.com> Cc: Alexey Gladkov <legion@kernel.org> Cc: Jeff Layton <jlayton@kernel.org> Cc: Waiman Long <longman@redhat.com> Signed-off-by: Kees Cook <keescook@chromium.org> --- ipc/mqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)