From patchwork Mon Feb 5 09:12:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13545114 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 52FE611CB6 for ; Mon, 5 Feb 2024 09:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707124356; cv=none; b=NfGbdTr/j4qeAWXgj/UVj5pFt8QaUaMQgXToLtY1iLefjvoBKvWjoF1s7OUF/sNNO74sswCM+TZg5ZAUDwz4uDee0q2XYGsY3MjpCLi+B1BGP5fJCaN6ZUT1rC6rAnjY4+KdtoD3ovn3tiu1nazjtsYf3+dMBY5mEzo9Lr0Q+NA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707124356; c=relaxed/simple; bh=760BS4AYHlS+7APUtQ8ZE5dhudg+2LRRSReX7Wgj0Uc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=fLw/QZM1vvOXEYcNP5hNoz0if7Zh7QUkjurtD6tt8tNYTVCGQiov7D3Uw0uZ43CtufdYpLDjJmWsWgvw/Gazz7SxKQT+3noorB/ejFGGhUdTsnvTFTNTXdRtfzIc6q2PM3NJ6i7hqNRmF+En5WySnusqhwkSLFTHqnArN6MDbBI= 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=APci+XTF; arc=none smtp.client-ip=209.85.214.180 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="APci+XTF" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1d9b2400910so4061005ad.0 for ; Mon, 05 Feb 2024 01:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707124354; x=1707729154; 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=XYWUAgEEnr1pXCEFzb/tx17d+1YCXeUfaMMfEveY+ng=; b=APci+XTFC6KesbeBl1rT2w2/QGPyfTuxzY8L5cCsU8zjKTHv8IWv71QKlOcVePKgy+ Ovg1CCJyRZumR/px7rcY59ScaKSnQVptb0PIlCK2RT8icKzHFIWHrK0OuUZ7Ulkse3KM UtvUO7gQA4z3kCLUrga31BER4rdiWpldfFf5A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707124354; x=1707729154; 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=XYWUAgEEnr1pXCEFzb/tx17d+1YCXeUfaMMfEveY+ng=; b=Ep/uMl+YVObkdEi98cHsCmVsIUoE0RlJNsF9f20Ha31KmRqlbKEehn9IEQKJSSp8b+ OfT3S9ltn+jEE+8PCpKzKnnxP0lA9BgbfRjf7UtxR2d835NUbUlK6lfoL/P54yuxpNCj CrJYWgVqZlOwoA+a+4m7xVNUpNFPer2Ojn5NX2IbAN+50D+eqPiArKjDqMQrpQTrf2Y5 AfnzhrrIkwVLeEcPZ3XVz1jD36H702Nr7S6LdUurKIJJZB6UcK+jveFhK0OKHwFLGmpq 4vQytssTyQK39YVM6ISo68X9xrlRLFK5+P4zbFVj5xkUzg7I0BUr6uxPEF3tLU5XYRqY 7q9g== X-Gm-Message-State: AOJu0Yzw4+snRCbhBjQOHeicnrDiTEsjrOpvsLM325uxQUifDVYjl376 S8ubsh7DXSykFJLKuYoqd2YZW7wfQ4yiM5irOSJKHcVm3OXH8vOkWwky9qVUZQ== X-Google-Smtp-Source: AGHT+IH66VqUGkatm1uMetl8y/UtE2gkAq45ydhKPyLzIK/EnRUC1ZOwcGbvNAQJxde79gjYhIxP0g== X-Received: by 2002:a17:902:ecc6:b0:1d8:cfc9:a323 with SMTP id a6-20020a170902ecc600b001d8cfc9a323mr7797777plh.34.1707124354619; Mon, 05 Feb 2024 01:12:34 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWgSNahtLSIgi1oJactmW9CzmKhGIeggdJCMbvIAO1oFLET/U42l1zNWd013Q+ibSRvNrDdKs8waJXDHI4WgVffxL33sN8OJFAoU+t3kpZ+Mh4lMLuJjUkWtfr26ZAyEJ4H/bUdk7UJVZ+1SsjGMcfIgFMh5Ove5ghFIgm5Azqe4Dms0tHmf6IhbEG2T8MYN2JdD0dTp3aZI8wDFknfpFxUHA0hBXxXVg== Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id iz5-20020a170902ef8500b001d8f111804asm5806487plb.113.2024.02.05.01.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:12:34 -0800 (PST) From: Kees Cook To: linux-hardening@vger.kernel.org Cc: Kees Cook , Rasmus Villemoes , "Gustavo A. R. Silva" , Mark Rutland , Marco Elver , linux-kernel@vger.kernel.org Subject: [PATCH v3 0/3] overflow: Introduce wrapping helpers Date: Mon, 5 Feb 2024 01:12:28 -0800 Message-Id: <20240205090854.make.507-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1424; i=keescook@chromium.org; h=from:subject:message-id; bh=760BS4AYHlS+7APUtQ8ZE5dhudg+2LRRSReX7Wgj0Uc=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlwKZ/jXO8LRx9LKVfIpgLMA3HnC9RB3QapN1aA E6+Ua64vueJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZcCmfwAKCRCJcvTf3G3A JuynD/4spaVIpyJgrv36zn6RAwRgIkf5r8K6RyH+nDsnlwsos2S/01Q3qqMdCT2oYXJq4I59XOy TQXT5p4T7EQhDViZjlRDTvKc0urPTQlFTy5DRDZmCa0Mcw5IGrleMSK8IZObean190vqwESAnLj TOGrsopb0TGZ7nmU1NIav8+KLp35bv5Xlzv6AdxlH8oBzn/Sy2EAFpHOlP1eRK581CZyjJMaMvt Ui3wohwjU8c0zjPgOjuAKG5VSx9nNP5KTwCWkgUYNoCBhkUZ6/kgt0FLaV+iEpePwkUQFAf46n8 BOtxf4Cwhxk4Az7uEfEV64t4MskJWd3N/CL2hlV9W3qa/KR/JEgk8waWVeMDmuRV5RA1c0tfdTo E1DzbPB3EZyua1nCLw54cYp/cv+/Cy+sPJkJDrUCht1+cIdv4qHwrw3zSumudSqVCQjfZpvkOlV g4rWMwxOWMRZDG1s6F0Si48YRuiBYgCoklaEkXAhUCCG2EywiMnP5J2Tweag3PlKWEQ/ARL0kx8 kSoDMS+9nK2a5As7A0ZZ+v53htMX2PPdAA+YsM8SiZEKFcbCrG1Zw9WuOFTCQX0clAtDITKTZuq SofIXJFtT3jCWSLgGStkEQk8MX7LX2hcIHpADV166wQd/wq/UAVdRe5XkaE1J5ouVQ6dWBtQrA/ uh45CBG wK8vAF6w== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Hi, v3: - reduce patches to just docs and new helpers; we don't need pointer fixes yet. v2: https://lore.kernel.org/all/20240130220218.it.154-kees@kernel.org/ v1: https://lore.kernel.org/lkml/20240129182845.work.694-kees@kernel.org/ 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 *_wrap() 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 add_wrap(), sub_wrap(), and mul_wrap() overflow: Introduce inc_wrap() and dec_wrap() include/linux/overflow.h | 100 ++++++++++++++++++++++++++++++++++----- lib/overflow_kunit.c | 65 +++++++++++++++++++++++-- 2 files changed, 149 insertions(+), 16 deletions(-)