Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2967799rdb; Tue, 6 Feb 2024 03:21:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEO1GgLiJUeN5vYQlEDIY7q9VRVRyXRGNnYnoCPyxE50uDSPZRP1iuiRo57Ms/RfHezRysF X-Received: by 2002:a17:90a:e648:b0:296:94cb:4cfd with SMTP id ep8-20020a17090ae64800b0029694cb4cfdmr7843475pjb.11.1707218476348; Tue, 06 Feb 2024 03:21:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707218476; cv=pass; d=google.com; s=arc-20160816; b=SihYmk7TMJkmsGDrLjNvSqqniabhXaRpMsinfHUjKgTrnpykDRuibafBOZz5n8yJdA g3jPYbIjYX7/UIuoHFrcfqnw4+G30L+DyYfE1XmBGZ9aGhwXA+DJLch8f8p/zV+3IZeD mMP5h578OdaEToz/yA5eaTmoebsJVAzHbk5YpI6X5cYmiC6fC8HHraapuo1YPH/dgGPn IfCckAEtTJuVCKnTDig1ltr+wZUlR9PWGG31bICNEkOL2LY9qqjtPysrKp2W67MxAVDY LQFlPCJ0kLZJxkZ+HGJyepTBKTWgmFPxVdPkhJ+Njnk5HIoJ3YRyPOHlQuQ46ePcqTaM p5ZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OK82JrlJXMGwOCPdhn7BsC/hEWZwW73rbUs1KIvU8rY=; fh=b3ekSIErPM9btd8aWQbv1M4P/0GbUpqmv+VsEQ/RqtI=; b=UI5lcPSc66W+TsP0e9lqK3EoUB/9Mn5aLj8OkdebFU/OGbpM/d4IjzQCMfXZXuC9bh LKsGDTTjgW+T3HNhgRNC2l4/6hF1GjUjIWedwOjjjEFcxaOkI08D7F5GRIUYMHxTeFmD WMDh4BJdge4R5KN9E9Sdh6gIZAy+OsPLJ6OL0ri5CP7fgr5/KlcOW69SEXCtENyhwSRv JwMXXzipE+ISmJOgCUEMUErY7Np9pV/sdLmWz85bESxrZv9IJC02jfJo/ieUdaf6C80a COD3nnPC9xnqLljfJtfFL7ce2HBfU2RJQAigDBwjwMlHYpytdxtug7yzHL+lbzk/Urbb O7PQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vq4Z37rB; 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-54751-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54751-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; AJvYcCWqbDVs+NXaapSt9dhpv5p3X8lKxyQsqcwTKCD5XTm8wniN3GwW3Y0bGY4OEe60C+5UfoKWZ+2R5ygqHxkAbN+ZqAh3OTpsKWbSwdrklA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id mj15-20020a17090b368f00b00296377bb025si992879pjb.55.2024.02.06.03.21.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:21:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54751-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vq4Z37rB; 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-54751-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54751-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4631AB22F8A for ; Tue, 6 Feb 2024 11:13:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 104D412E1C2; Tue, 6 Feb 2024 11:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Vq4Z37rB" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 E0D37131735 for ; Tue, 6 Feb 2024 11:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707217761; cv=none; b=b1yTarLeqDSFbNLkhXGZ3eMWSA8iSmdlYfw/JiAnYF2FJCJcKVS+URe26P2cc3t0epfqskuYtTBcDPqAlWQN1FemOaaJw8IwrIbj5BodEnSzCWxJ/qoOXkV2f4iamRpnv2jT2LSw5rZNvL1F1dM6QvfLV1TBqwzPmnfefdBYgAE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707217761; c=relaxed/simple; bh=I88T9DtBs60ZimAuUeMEtUlCdBG0kCHidolckOt/nWs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cmOTrSx4rDL7fnFd4pVQ6CdLX2Rrwd8It2RjNbo7u6IdiJNhldQ/WlOODc4DkKa3GEGRvZLPIMLk5smtAyg/+W7m8nTXko01G3YccVSxe1g5+7ZMjmKjDB79IOALuCOTu8zSnWv6ruCKrKZMwtN95YGMdAOPdaQP+tnAk1/jQVM= 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=Vq4Z37rB; arc=none smtp.client-ip=209.85.214.171 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-pl1-f171.google.com with SMTP id d9443c01a7336-1d9b2400910so3202335ad.0 for ; Tue, 06 Feb 2024 03:09:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707217758; x=1707822558; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OK82JrlJXMGwOCPdhn7BsC/hEWZwW73rbUs1KIvU8rY=; b=Vq4Z37rBi7PL1kQKcFf5EBnXkTg86f0AJmrk8NUN+WFmvNSwKyZyerIbB9plgJatLB jPx14d6FO390Lryg6xenrONBlC9PM6QNUWzxXIrTNJQPtrQjI9WBXVm0+7CQQm1eurx7 PW6Hn9cNE5IliOA0uQuEI/mRydkzsb+8mJFUA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707217758; x=1707822558; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OK82JrlJXMGwOCPdhn7BsC/hEWZwW73rbUs1KIvU8rY=; b=L42Wbgvt3RsVf45fC+kGowzNcWoZMAWczF2JYmTewg0nY1FvlsQNHBqCZXjNl01LtL MV+SKK3ko/eQUeCDu6ZzB3EFix2hi/laXXwS/vVX493wMk+Qoo80lBbXFmNk+sAd87ia GyWIoCd4ToxRnRAOi4rrmwXha3g/2qGNNxXwkvx4Fkfy59OStVBDD3AO1md2F+BuaZLR dggkPcvc6xHRV/K0grKbuulC+2RJzT3vu/UOvfZAOvMXHlXk4LRw58zRP0kqoyefIbmI o+higYdff1ip2dBXT8ArjV0niGnHlj2QTeNKhMcY+2Y0TkJ1saLoQbGovvJIQ01N24Ok /dew== X-Gm-Message-State: AOJu0YzgbtNQdwFli+wBU3tT3Ja6q3aizCo+Gb5rHwlgUDVFe5Pt4Xzn 8XQ6/kDVO7WgVNP4MgESpusLN21a2bmg1B/gJSREq+O2oeCwMTfLF6guqzEThg== X-Received: by 2002:a17:903:25d4:b0:1d9:803a:8b0b with SMTP id jc20-20020a17090325d400b001d9803a8b0bmr1488044plb.33.1707217758211; Tue, 06 Feb 2024 03:09:18 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWD41BFbjj/gA9nr3hzGLWEWc28wGikJIa+U3DfYEG0+mhZav6ryva2TaZi/PuT+gDRDu3oPFfGLLauKK2I3iwCMOOkLmbqbllaBeIcb7Jfztp+AIIejdbl7TaDPuKZyAJU3Zi5oI6VCIuOR0uSOxs55kiSlmmhTdpw4iWIbnlbmzKnAeeNTRVdyMD7WLOMTJAfzFjLt4dlDx2gWwQ0SSli+08lhSJDOfaZFkSyqEAt9idPS4K9IBA0bgPei7tlmp98i5xFYyFtsvuMAFsnGwbcitjdhkSk+JjhPwTXPc+Cak+xGP930Q9GxgzYqvrScLmRHHswhkoOXiHfz4WS4FJoAGCXIak+7iFyl0/WnvOkBBnM3i6klYaN+gxVw2oLmoaLby9mJ7FioFHl3o/t9zZ+56J3jOuURB9oveQrlghN2XOHfRIUQQik1XssosFvbH2oCK4J8AIOnScjPQLuVjEoogGC0ZFii3Y9DUS2TkzP3HEy2L0NKH9YVD7LfyD6xOJJw93kac5+ZT1HEJ3MaTAhCkQKaaY/KQ8THpgBgZI= Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c14500b001d9557f6c04sm1567758plj.267.2024.02.06.03.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:09:17 -0800 (PST) Date: Tue, 6 Feb 2024 03:09:17 -0800 From: Kees Cook To: Marco Elver Cc: Andrey Ryabinin , Justin Stitt , Miguel Ojeda , Nathan Chancellor , Peter Zijlstra , Hao Luo , Andrey Konovalov , Andrew Morton , Masahiro Yamada , Nicolas Schier , Nick Desaulniers , Przemek Kitszel , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-hardening@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: Re: [PATCH v3] ubsan: Reintroduce signed overflow sanitizer Message-ID: <202402060308.0FF75100@keescook> References: <20240205093725.make.582-kees@kernel.org> <67a842ad-b900-4c63-afcb-63455934f727@gmail.com> <202402050457.0B4D90B1A@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Feb 05, 2024 at 02:10:26PM +0100, Marco Elver wrote: > On Mon, 5 Feb 2024 at 13:59, Kees Cook wrote: > > > > On Mon, Feb 05, 2024 at 01:54:24PM +0100, Andrey Ryabinin wrote: > > > > > > > > > On 2/5/24 10:37, Kees Cook wrote: > > > > > > > --- > > > > include/linux/compiler_types.h | 9 ++++- > > > > lib/Kconfig.ubsan | 14 +++++++ > > > > lib/test_ubsan.c | 37 ++++++++++++++++++ > > > > lib/ubsan.c | 68 ++++++++++++++++++++++++++++++++++ > > > > lib/ubsan.h | 4 ++ > > > > scripts/Makefile.lib | 3 ++ > > > > scripts/Makefile.ubsan | 3 ++ > > > > 7 files changed, 137 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h > > > > index 6f1ca49306d2..ee9d272008a5 100644 > > > > --- a/include/linux/compiler_types.h > > > > +++ b/include/linux/compiler_types.h > > > > @@ -282,11 +282,18 @@ struct ftrace_likely_data { > > > > #define __no_sanitize_or_inline __always_inline > > > > #endif > > > > > > > > +/* Do not trap wrapping arithmetic within an annotated function. */ > > > > +#ifdef CONFIG_UBSAN_SIGNED_WRAP > > > > +# define __signed_wrap __attribute__((no_sanitize("signed-integer-overflow"))) > > > > +#else > > > > +# define __signed_wrap > > > > +#endif > > > > + > > > > /* Section for code which can't be instrumented at all */ > > > > #define __noinstr_section(section) \ > > > > noinline notrace __attribute((__section__(section))) \ > > > > __no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage \ > > > > - __no_sanitize_memory > > > > + __no_sanitize_memory __signed_wrap > > > > > > > > > > Given this disables all kinds of code instrumentations, > > > shouldn't we just add __no_sanitize_undefined here? > > > > Yeah, that's a very good point. > > > > > I suspect that ubsan's instrumentation usually doesn't cause problems > > > because it calls __ubsan_* functions with all heavy stuff (printk, locks etc) > > > only if code has an UB. So the answer to the question above depends on > > > whether we want to ignore UBs in "noinstr" code or to get some weird side effect, > > > possibly without proper UBSAN report in dmesg. > > > > I think my preference would be to fail safe (i.e. leave in the > > instrumentation), but the intent of noinstr is pretty clear. :P I wonder > > if, instead, we could adjust objtool to yell about cases where calls are > > made in noinstr functions (like it does for UACCESS)... maybe it already > > does? > > It already does, see CONFIG_NOINSTR_VALIDATION (yes by default on x86). This is actually a reason to not include the ubsan disabling in __noinstr_section just to see what ends up in there so we can fix it immediately.... -- Kees Cook