Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp378936rdh; Wed, 7 Feb 2024 07:24:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBezOIQEdYbaQuolyZRJOGUNw4B1kbPEwgJZDLW5BwkFYnr/GRwKNFvQWLqCYol+FylbXy X-Received: by 2002:a17:907:78c1:b0:a38:83b2:c955 with SMTP id kv1-20020a17090778c100b00a3883b2c955mr1217893ejc.30.1707319475996; Wed, 07 Feb 2024 07:24:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707319475; cv=pass; d=google.com; s=arc-20160816; b=iS6DY8bJyBxck9zCv/0E0CgoMb7tAXBrwG7KScZvuVxPQP38Sd1Q6mDmovXrwO4iRo nWYUe4MXgUWGXOdjyO+7C/45gkv678ySTfu8bufk9v2g9XNtQJZP2FawMgONO161lS7O YQorewKTY6xJ2fuvW67fyJ4m4bS3GrWf89cc7usmHGfx40rb2VUPx6szG1i1mcM5QRd+ XYNco8+fPo68cOcM+84dhHWt7sF1dVJtNOwtcq0pkNC4Tj97MdlNPUKs+yZh8ApQGabX yXNEGHBwfP3lQvTBUvDjJHVdH1nAb/XNAekHUrChRFEjUJ32sn/m9DPHT7n8wrhRtaYW pCRA== 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=oAK9OrGZjXzm8EXOs5XutKZoyM3A9aclYEfT/WMb9pc=; fh=GwE5wgADprwiMEABu17mBQWObCLpULApEQhdm2+vm/M=; b=nxgOjTzDn+JwK+V+TS2/oN33yImMmR/92Q4xiOZmA1HdxUNs4SYi/pbwuRuyMeRdBh iCiY1288BF/2pTS3ootwsUSofG1jRJbxKM4+giUWelz839WLn6pQDpB+H7cNRdtCewKU Xav11zPumS0frJPSpVj7iwPlQZVd7NenR6GydAxZr0Ic/JilLcn5a/rLfaxuX/7tDcu6 P8n3YnUw6iH9cNaSh0CG0+ZbPlejquk6n3qO6cQZOjvd41cTn3PT1r3MbYX9emSEyBAu xvSGFZfekexb5KUa7ML/+puZNseFgBwNfe06YbCdstkTvBg1vKJCCJ9J1DhGPgvvf3g3 sApg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hvJLEGYi; 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-56711-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56711-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCVcn78www0W+LOKQMhvR4XVwIXytT4CWFBbgv02BBipa64pnDCH7Tb8jOosAKtzHTFFsPZSoEZXge14CORiHxNvXC0KVhYaN+oBCZxs1g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i13-20020a170906a28d00b00a35bdf269dasi1015674ejz.624.2024.02.07.07.24.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 07:24:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56711-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hvJLEGYi; 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-56711-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56711-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id BADD51F26392 for ; Wed, 7 Feb 2024 15:24:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 141517F7FD; Wed, 7 Feb 2024 15:24:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hvJLEGYi" Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 D179E7A713 for ; Wed, 7 Feb 2024 15:24:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707319466; cv=none; b=c3kxzPVSGj4VpAIOlpQZi7GbrSE/qpQseDoT/vnWnSaexF4M5oVx8f0N6vgb6EDBaqP33jl+DZmK7+FAMvg2jOaDi09PoyYjbz2B40hfkT7gDYfOeDKPQR2On3GPZ5gGEdNorQPFySJw2tmrvPXzW4zccywFYewtyaMmObSusI0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707319466; c=relaxed/simple; bh=4p2EQPheTGW1muNZPNy/adJj7bHOmG0Cp4WlpE7Yd4c=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=m0JhiHcGKDqJLeDJPG/u1wdiCNn03x9uIr6jz0dRinJ88sT6TpRa3EGBL9jN8PtKBkIybqWgVSniSOOOAgl6OeM0MhTuyw+iDeM7gx1Qn8IRylLhC3wS4VX65TcbkGN81+0+jtyfMaZlGGk6C8si6MlmifMSEEEFPB58zFrOtx8= 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=hvJLEGYi; arc=none smtp.client-ip=209.85.210.175 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-pf1-f175.google.com with SMTP id d2e1a72fcca58-6e071953676so96391b3a.2 for ; Wed, 07 Feb 2024 07:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707319464; x=1707924264; 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=oAK9OrGZjXzm8EXOs5XutKZoyM3A9aclYEfT/WMb9pc=; b=hvJLEGYil06EihX0tnY4bKR2kH+f+mQjw4biIheIErsG9Jup/9uCuOPe63WJ1IozTE Ji3sB8O96i562co6d0PnprOrXEPvinkEepVUYWYfIEY+URrYk6PprGSqa4yPtCMnu9fS pAYn97BeZZm3fg+AbcB1zjarb7NNQicCchyAw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707319464; x=1707924264; 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=oAK9OrGZjXzm8EXOs5XutKZoyM3A9aclYEfT/WMb9pc=; b=IdwsQVJZcKNd2iNe4d7vRJAyAgQkrB/pZ5SqROHf4SdsEc4/R0xlpIxzocIkCgJGAN CuAQ2AWByPLOVDefxKmw8TaHs7k+YURLeXmjOQed/O3Ex1Qz4HEpk79bZdLWBImmSbyN 8XsuUiuPA9exjJE8+crt3xMuSGjgeL39aY4CgT26ngc2cCovJdBD7SOuEYis7rA5nLx1 RcZniFS+Ct83xMx2EMzuWbLf1fEFZZytPFSu3rWt4cc59HtXA1hemh0Nbe7poiCXKjRP dyPCNhB1MOO5Tf2pxEuFERrpR2kZskYxva/Hh0Gt/YA+YqHKlUoZ6U5S7cqx0vOdOcvz 1Fbg== X-Gm-Message-State: AOJu0YygJ50uPRmxaAasJYqpIf5BiqTR9yg4C+Ek4NiBKNIs6udeC0zr dv9VehPNcWMih8RqQEG3/h6BDAgDCQjmdPGYfZmJhQ3kmrEiOWXsBeerINeXEQ== X-Received: by 2002:a05:6a00:cc6:b0:6d9:bb2f:3a69 with SMTP id b6-20020a056a000cc600b006d9bb2f3a69mr3441777pfv.28.1707319464108; Wed, 07 Feb 2024 07:24:24 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCW9jFJsT5ownCtSUmO/shqpRpWsX9ZXP2HyGJcyowQ/DPHBFvs7CeclJdTC6Mz6utqy0Lz/mrymx/Wui/2twMrt55RBtTQkDaKXzQJ42Hp2rqYhQ4/6qsLTUoVm257UqgYDT+jHs1G62/RcDfIpGC6c971GuqdtoCajHBTJrJNQ1Q0gjrkPx/JSisGWwWA/ElK9ZDUBRS8JQEG6OHIObUTQKjPWEhf9qpDGzCgwvdHrzIV66lWssSncI3+KXs+gm24b1O/fqbfwWP0KdBBAA+01cK0IpxOV6Q/KOEbnQNnCDc+8vJPdAxpLBrEjNRLtsp3C17yZcrm1RA== Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id lb4-20020a056a004f0400b006dde18ed7dbsm1762170pfb.170.2024.02.07.07.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 07:24:23 -0800 (PST) From: Kees Cook To: Andy Shevchenko Cc: Kees Cook , Rasmus Villemoes , "Gustavo A. R. Silva" , Marco Elver , Eric Biggers , Mark Rutland , Andrew Morton , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v5 0/3] overflow: Introduce wrapping helpers Date: Wed, 7 Feb 2024 07:24:17 -0800 Message-Id: <20240207152317.do.560-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=1282; i=keescook@chromium.org; h=from:subject:message-id; bh=4p2EQPheTGW1muNZPNy/adJj7bHOmG0Cp4WlpE7Yd4c=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlw6CjkfkdfRS6eRsgDPzLkc+pAsOKiFWEGvoZD bRHJ+LSx4OJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZcOgowAKCRCJcvTf3G3A Jm99D/4mEeW8nnw7WOCR71kBtI0IIM0RueXokgZGNjpwAVOWPW86MPEI6byvsphrXynFdNYf3u2 zUDukAaJYiixTumjPpQBy2nZjmlyRMaUJN1j8pQUUlES8MnVH2iqf2e26wJzEjDrKoPZtNUn8Lv YA7GQchdB/JS6FFzak5OgrIUP5gPmcfirpmD9qJMpGU+MBa/YBx0TVEswGwuE3xNLs85FJy9PpU ih36Jov7LjkzKgZeWWF7aHluyCZh9RZ2SnNCKu6eT15cGzP5/DzV/YDngxGAOMTUmnsnv10CVCw EQAqWX6LAd/ikWkMBZiscvFLfiBWT2DPU9TW75QcgETILt0qowsqXPawhz7NLgzwsTIFvZ4nik1 FCUhtkZOuk210Eh1lTGAYpyEl0D8dCd2LZVFLoQFZedEXFMagXjpTlNY3g40xjfwhoTLoLfkt2V /DQoQRGemo93jtG4ivHvYezH9huvo5wesYjrLju95KEwyEAFtBEJS5ZE7qpY9HoLZ/PwYfVBwe8 X46lQKAk0DtOhcRigkTb8tBM7nRKw6vZNcB1DAG0GHcVO05cgvsO3/RixOCsQaWmPrFjPyc8W+X 9n+2JWJ3niyIMW7RyZUJGOtgdREsshrRlhB4NFa2iCY/0UhNqXFXrTqmuyMekiEUjEOgENccD1A PCZ0QPP CI6i53NA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit v5: drop redundant checks (gustavo) v4: https://lore.kernel.org/linux-hardening/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/lkml/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 Kees Cook (3): overflow: Adjust check_*_overflow() kern-doc to reflect results overflow: Introduce wrapping_add(), wrapping_sub(), and wrapping_mul() overflow: Introduce wrapping_inc() and wrapping_dec() include/linux/overflow.h | 98 +++++++++++++++++++++++++++++++++++----- lib/overflow_kunit.c | 67 +++++++++++++++++++++++++-- 2 files changed, 149 insertions(+), 16 deletions(-) -- 2.34.1