From patchwork Wed Feb 14 19:46:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 20390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1458295dyb; Wed, 14 Feb 2024 11:48:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVokCOS5EKIqcyaDpZWmZfBHIsKGibJmFH5Lw1vIadxq4SEGaDrUITEtrTv7gezCstPuvefpZGSuPU/IMYpxiPJXkbMJQ== X-Google-Smtp-Source: AGHT+IFJhVMG0p6kiZ2WrHexlKBUkTgKi4uqAHMUf0UiHKkFXbV6nNqvEgbdoJATS2YC3l57FdUC X-Received: by 2002:a17:902:a589:b0:1db:2b8b:49f3 with SMTP id az9-20020a170902a58900b001db2b8b49f3mr3584285plb.38.1707940102524; Wed, 14 Feb 2024 11:48:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707940102; cv=pass; d=google.com; s=arc-20160816; b=Mx3NIACU1G7ZIavnTUeve5Y4A9Nn5GlJZWa8p3SimybBk6nLtM6dvVtCTuQwq5xv1m WGRG41i8q0ZtU6FTbb135/2NPD3Ou/l15Z5Q1+s1JCVokcO3x+irsWx3eYseT3+TpuYq bb3LlmNcA7b93xDG3fIEZ6WltH25cje/qv6uv1e+I6IMPzRr9KoePQLnrPG3e7WXwWYr kdTfdkqOeaBKWZZrvk3lBzyLgUiFygImB/KOyeTRnSxK/Sdb2KdxrUSAuLXVs2wL38nW fm9gQ4XmIbHn97J1T7BLafcnIk+0uX9g/9ZyfLZJihXvQJmof1dunQoMq7NNbkWZAALv krlA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=RQAKDqTR0lInodj89i/VDK6/vi1P72VYaaN3v1N7SL0=; fh=AxMpotvAAg3Mc6iSE+eRJJRI+ihI+/vBKRUZZCTAdUc=; b=jp/5tJeNLBbFsQy5LHGSoL8OPThkcJjpMpI2BYTlKZyCwk6CEkrHy6UtOg+MiiJso0 xUN01mU1rRDihk8OplHDJQ6Bviu31GqeCK0orFrE2m+n7KGs67pxsXosoT8n1UsXtiaK 2ZKw+dBH0BX39rt4cy1g/35KUCA5qJBnejIJ/C9qcNMphvWF4ILewD4AGZKarvKM7x1H hSY4V641zCzfHlAEJrH3Xg9HrpYjhdIgnSzsVokaome2UiSZW3Y0JyGP54TgguFNa+5A wk0fZP6RUR7DGR812sMlqxlSFkEXS66iS9nMWDHtmVp9qxT7ZF/lsjGspQH4EwTlDoTP TI1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=D8xuBx7I; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-65891-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65891-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCVAPOB3SfFx7XBfBu7hiOLdSObiIZkgKntBt2a967AjL1Ft6XiHu8G9sQ5jd/D+v4K1j0ccolFQWLUuSN17PcOfZQ5z9A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e8-20020a170903240800b001db5075940csi2137546plo.485.2024.02.14.11.48.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 11:48:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65891-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=D8xuBx7I; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-65891-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65891-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B4D8C2903EF for ; Wed, 14 Feb 2024 19:46:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E063813EFE7; Wed, 14 Feb 2024 19:46:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="D8xuBx7I" Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 DC98F7E767 for ; Wed, 14 Feb 2024 19:46:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707939969; cv=none; b=ckcy5KLpRLHP9unlRNDEnQQ3WMAxdQ+j7YZ0wzDevG26DHe0uefltw8IppE2HoEZUaZvrR3Tj6mISVAJIxQ5o5FiB8vnx4ltoMVuP54J/1wtD7md/1KsHxkCdvH/9snlqNvbOgRTReC3uQQ2NAjpYFpEFEKJSv//JyvQCeYVark= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707939969; c=relaxed/simple; bh=uQwFw+Mvb5FS+5R3O7Kh53oqRz4mjeatqrTjC8hEZtQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=FAZqtf708+4OoO2DGQUN4EjR686qE/99g7SqJ3IYBcuULOIYworQAq+20zwb6S/6nbjoSFc1y1YmaQwN7NY1b8Pc1eiBg4OYrrEKNKII6KmSvS2a1gwXfHTRoDbOXHRKJnDFOrAdCDSaS1R4gcMsEvNE12zSvaUbPlESDv6PA5s= 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=D8xuBx7I; arc=none smtp.client-ip=209.85.216.54 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 Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-296e8c8d218so130903a91.3 for ; Wed, 14 Feb 2024 11:46:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707939966; x=1708544766; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RQAKDqTR0lInodj89i/VDK6/vi1P72VYaaN3v1N7SL0=; b=D8xuBx7I48V/7OH6w4xZnEVtQbXRC3j0733USZL7WMhODA5jIUVts65t01IL2BY1YW Oewqdf+mEgrWBtiA7ENKCnz7Q9HXYiWYsMgDneRW3PaKjOnA+Rm4DkkuqieGSBcdEcqA AELFNBNXNt59AARNxYSfIkNgOTxholfTyljuI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707939966; x=1708544766; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RQAKDqTR0lInodj89i/VDK6/vi1P72VYaaN3v1N7SL0=; b=enZMwA82/Oo0B/F6A/p3hoqpEQI50LbfG/jCSC8UemgDHASnpRVEB1trVYgZfGiz76 5h+VLSOhHfF4Rni2tC/Us1gnLYyUy16/kfjfYdmjcXsZjW8SfWgjAMJTxwxbCMRHh5FH mMVOEVEuYaAloqT6S0hFw6L6mmryHw3gkAMjM5dNOsEqAXmrblemnRogtm+nUuMa4rsI uGIEVL29NsA/v98yPE/ID9IxMWHdmq/g/h8W6c+9caTmhVwdE/eFAfejibXnDuV6mpxP nqU+pYV1fnLjPb26rfGvqNPXJGTnGLOeXF0EvTvKa/zNj9DVTk6b3HqyC2UZieKwbR3f DkHg== X-Forwarded-Encrypted: i=1; AJvYcCXSBFz79410uonoaqqH3R3lVej542pmGKmNA86saeD1VEw6aBfQuTBGlKixjVAU/TfQNF/MuX1D2J0LlF8yzeUJYZ4F/o3kViMfU12u X-Gm-Message-State: AOJu0YwraUVRbqyVcvxmQwI6ua6sJOkPibgMHtnzhTNoHxK3qBkoXWRS Br+SawdfoZmvdrDki+J37xILGgww922c2z0bNacg9LKsP3Dd6lh35Xuf1F1qsw== X-Received: by 2002:a17:90a:c204:b0:296:e2bf:3936 with SMTP id e4-20020a17090ac20400b00296e2bf3936mr3585859pjt.36.1707939966221; Wed, 14 Feb 2024 11:46:06 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id m6-20020a17090a34c600b00298b9f662ccsm2035619pjf.1.2024.02.14.11.46.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 11:46:05 -0800 (PST) From: Kees Cook To: Andy Shevchenko Cc: Kees Cook , Rasmus Villemoes , "Gustavo A. R. Silva" , Mark Rutland , Marco Elver , Eric Biggers , Andrew Morton , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v7 0/3] overflow: Introduce wrapping helpers Date: Wed, 14 Feb 2024 11:46:00 -0800 Message-Id: <20240214194432.makes.837-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1708; i=keescook@chromium.org; h=from:subject:message-id; bh=uQwFw+Mvb5FS+5R3O7Kh53oqRz4mjeatqrTjC8hEZtQ=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlzRh7JItobawvLT4rE2d1cpdHERzHGwXC9I9xs qRALXG1AQSJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZc0YewAKCRCJcvTf3G3A JhrrEACQsJK01x9xNqIWqiN+g7wsA5PyZYBoCWe2XUFapCLB759/GdDKBEKBcOJLG45k2wkbClT ImuFShGbsHTl146bYDt+tB05yrXftONqA2LJ4PO88nB+0Y8vhYjobHFU41qPz0ga5E5Dcv/7RpB 1Rl0vZ5gNzI50wj0G8/f2sb1MYCn+b2zcFbbL2mowb87QmXk8GYNsGxVxWkX4QpDWIx+5hwtUeD JQ6heHQ4X1MtO5XLu3c755Wc/OhRBR1ery6Gj4fjZVX2+up4rv9Jjqzz9Bil9M00+rBUjjMS9CS bjSX0twnUU3vicu5H/18FPuYE0hoG5t0UMtabOtaKWFfl5P63QS1aJwR6tjh7vi9dOuz7zYkrdy Ylrnr2sRbU+XlvilOVJiC45SNabbgBIugLp+3tVTt5WARekcIEKEzG9y2klvWErdKSQneNaIqOL D2RVGimkB1Pcc95fKDWRN0J9xiChzvjy4GS/dLpcIT/uD6TfGnc1Dg+AaHcdhYIDQXsSNKLe8WW DmsGg5ISbmZrIDEhxttKAjxG5eheHZ5SPW67FSXFiAcahYfV1uwvu7HnZb6KFivGz/PZNTUmNbp nwxqFLc52D28c6stg0+IbBh8zrtIAWOLkSjrU5mMSIexoPyujbeatubSBQKbeStf9oZ2JJhCvt7 vFL0ycE knLSqdrg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790905000907017118 X-GMAIL-MSGID: 1790905000907017118 v7: - further kern-doc cleanups (Mark) v6: https://lore.kernel.org/all/20240213220844.it.345-kees@kernel.org/ v5: https://lore.kernel.org/all/20240207152317.do.560-kees@kernel.org/ v4: https://lore.kernel.org/all/20240206102354.make.081-kees@kernel.org/ v3: https://lore.kernel.org/all/20240205090854.make.507-kees@kernel.org/ v2: https://lore.kernel.org/all/20240130220218.it.154-kees@kernel.org/ v1: https://lore.kernel.org/all/20240129182845.work.694-kees@kernel.org/ Hi, In preparation for gaining instrumentation for signed[1], unsigned[2], and pointer[3] wrap-around, expand the overflow header to include wrap-around helpers that can be used to annotate arithmetic where wrapped calculations are expected (e.g. atomics). After spending time getting the unsigned integer wrap-around sanitizer running warning-free on a basic x86_64 boot[4], I think the add/sub/mul helpers first argument being the output type makes the most sense (as suggested by Rasmus). -Kees Link: https://github.com/KSPP/linux/issues/26 [1] Link: https://github.com/KSPP/linux/issues/27 [2] Link: https://github.com/KSPP/linux/issues/344 [3] Link: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=devel/overflow/enable-unsigned-sanitizer [4] Kees Cook (3): overflow: Adjust check_*_overflow() kern-doc to reflect results overflow: Introduce wrapping_add(), wrapping_sub(), and wrapping_mul() overflow: Introduce wrapping_assign_add() and wrapping_assign_sub() include/linux/overflow.h | 101 ++++++++++++++++++++++++++++++++++----- lib/overflow_kunit.c | 67 ++++++++++++++++++++++++-- 2 files changed, 152 insertions(+), 16 deletions(-)