Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp816406lqb; Wed, 29 May 2024 11:17:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhnGkfOh5z02YPLsu7RHR7srMDW0Ei3oBEq1lKFv5JD5gGRiWheiADeYxim+ItI+aaj8pIU2nn/7oMg42ZeCJI1hCdaDgBiSLA3rKzyg== X-Google-Smtp-Source: AGHT+IH8nO8P37IUcbsbMV0s6yealb0PKZNoC9gqrxMSa6d4JY7ZHWNZuXe2H96XFQN/Yg0PGhlR X-Received: by 2002:a05:6214:588a:b0:6ad:7f30:f0dd with SMTP id 6a1803df08f44-6ad7f30f1b0mr105728786d6.17.1717006627565; Wed, 29 May 2024 11:17:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717006627; cv=pass; d=google.com; s=arc-20160816; b=NEMpyaQESr2jWQiAKenOhcFE6lH6wm1NKcdA0/RBkNY0XM2ajPMSvvvdfNptnX/IZE Tc3VvpISpbD42GjA1qA6clQMAjY1Ds13u50qiv+kS1lIPPETHFSu+DGmpnA0chuRLLfr hXTZlJR63/BCuTXNTIdeNsWnLejGHXY3Qcdc0oosN8+xIGzSjpcXqmjlfSaJEXD7ZXB4 ToU6mXSSkwAdSwOx0IpmgVyuw7eCWiSw5KUFE9fZKbgXEKeAqDG0w/yl+hiwNiMDZVRb UWHb3efbEis+DO+CDHLKlO5lrTww648hHBXH0kbRu1KMfo7WyZi60NNgsCuXFNv7Sft0 oXmQ== 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=iXEkR867jEs+moBzGXY8ULu3YeFsr12ik86Lu88hpJM=; fh=UfjqD+IgsxVM0rT9w/aDE9bPj1GOG2R0tW3h8qbnr0M=; b=0IhKhmR0Ph0L21uS8vDAOkIQ2tEvcVTASD2QDmsGv5bj10YW88M2dafDko4CeCWbQs BPrypQyvp479qIe6UVx2SBbqO1m/eTbz7FyKIGGVx4Y6TIdMsJ1Gfmf85E/Om8i85xTj mAs5SgDdd9cbgNQYDd5sWnnVujUNCTbZIcmaK04N7qZivV6dJmNBfA42OtKjqk9nwnTz QaJUc1QD1Dk0HJxhiK1ANstSwcDKXVZ2FocC/DJnwxz5d9/8Q8dAY2defIjaXKoBej8V gusYhgWQgkTUIEBHqs9G4l7tfhYEMM3d38NwKFYa5X7FvFuqWFxBDC2kfXnaqcpaMvKM KBmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Om1FB3e+; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-194560-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194560-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6ac06f5031fsi135351806d6.2.2024.05.29.11.17.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 11:17:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194560-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Om1FB3e+; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-194560-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194560-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3FF4F1C22203 for ; Wed, 29 May 2024 18:17:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DA7D15CD61; Wed, 29 May 2024 18:17:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Om1FB3e+" 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 CF55B15B575; Wed, 29 May 2024 18:16:57 +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=1717006619; cv=none; b=RIH8Xp8g6aneMw3swPEBMilkC1LqP9q5KPyVgBFUKzdc0pjb+fSE6BITQy6kpONnMX+ZbrYIsYCqeZvmELmGbB/XA91788daXmazrwVzsJX12dZrCaENgtv11sxNH0kaXSQrtCblpgCNxH695cg5qsNEPUauHtdiYE6UwEVho1Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717006619; c=relaxed/simple; bh=bBxK7oGH7Qc+v5OVBzgZ/gYfy8r6SkX1r3Lg7bTGGck=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rcAsA6WF1ivQcbBRbb6uT/hVjgnQsAghApk/J8Q/DsTLTzpQJxeg2zDj3dozzc9NcOQBCp+sP5L+Co3hcSi7Oftlgg9/mcdj29Q2nXLiYZ4blUDzTddKicV1ihuMiDxQOREm3SbQp0q1QpCCh3020f7DZJxwP+rBhft6hoqpMng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Om1FB3e+; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f44b5d0c50so308235ad.2; Wed, 29 May 2024 11:16:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717006617; x=1717611417; 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=iXEkR867jEs+moBzGXY8ULu3YeFsr12ik86Lu88hpJM=; b=Om1FB3e+VTMeUoOhnE7yMedx7f8rz9HQ/AvmptyH/LCZzpvEvQSAmkp+f2ar4YNLWC E9KDqj3vIRwmOZvrwDnEEZm0ndSlJR54B0C/Ol8FzQEQJdTaFN1tMXtqpMVVQnxR15ac MJBcUtyMi5gcGEhxux1a1jaxfihKdhdipYiQKKEfTitz5+MWW1NEGXxCSSvW820MHEYX XC0Nz8kF543N8PaWZBGK4Qn2zuiynKtF2/Snn+sErcqcTCgXav6hY1OJbz7rJqbinwch iL4LYD6Jh58C1ptSC6uDdCbJwBCaSxxpa4f7r8qd5UPlILngvUhOhW945xI6XZx/k85X ZLhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717006617; x=1717611417; 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=iXEkR867jEs+moBzGXY8ULu3YeFsr12ik86Lu88hpJM=; b=fpjXDCEXy59ex1BURNRV/ODl2prESX/O+oVlPYIxg8ATVBXP+6xwBAJoej8O1Rozfe R7XZQIwIJJCBUETqI0NNrAKeITO/qSbmwKsblpml6FtryHG+M1ISRp4vf2u+XMlP9a0x BPG4iXykf1xR+azUrgfmhmZ3zqkfGmc+ovmF9L/j6sDKkENeKo+6NKndnAbt8TrpjjUp W9oLU3y2lLqMMg3R6CCADB6sGJn+DVhmOAupzKTrbJhG+lLxb58nIpfa9RgQ1gx5PKZl sUfmHh7ey7rdVD9BWyxVkZwIOUPh1aqhOtZIdr0eutagKu3SeWbP5aqi7BWNjoiNoJH7 gidQ== X-Forwarded-Encrypted: i=1; AJvYcCVkIl5hH343Ld2WHBq4jqqxgQ/ZilhhU8T3otIIso4BMJxo24yQBsj064DjXhtVIoO+h99gu9GsNWaSq+FWrxRjb29dlgvjTg30fOoXUyeKdC43n+1yiXktq0zNWL8cOJj0qLXGbPSuWvQWmyeK X-Gm-Message-State: AOJu0YwRsRiH3+GvQI7WEluQp9cMlyrVTU1tg9kgeV+dYUDxJrB3G2Fl 2p2SHkHBTbeHNdAZAiLKRZCboaCd+6QhDQWWkISA+YYmNFEXtAlO X-Received: by 2002:a17:902:dacc:b0:1f4:be9b:d306 with SMTP id d9443c01a7336-1f4be9bd71dmr75508835ad.31.1717006616911; Wed, 29 May 2024 11:16:56 -0700 (PDT) Received: from Gatlins-MacBook-Pro.local ([131.252.142.255]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c7592e6sm102718815ad.45.2024.05.29.11.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 11:16:56 -0700 (PDT) Date: Wed, 29 May 2024 11:16:55 -0700 From: Gatlin Newhouse To: Marco Elver Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Kees Cook , Andrey Konovalov , Andrey Ryabinin , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Baoquan He , Rick Edgecombe , Changbin Du , Pengfei Xu , Josh Poimboeuf , Xin Li , Jason Gunthorpe , "Kirill A. Shutemov" , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] x86/traps: Enable UBSAN traps on x86 Message-ID: <2j6nkzn2tfdwdqhoal5o56ds2hqg2sqk5diolv23l5nzteypzh@fi53ovwjjl3w> References: <20240529022043.3661757-1-gatlin.newhouse@gmail.com> 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 Wed, May 29, 2024 at 09:25:21AM UTC, Marco Elver wrote: > On Wed, 29 May 2024 at 04:20, Gatlin Newhouse wrote: > [...] > > if (regs->flags & X86_EFLAGS_IF) > > raw_local_irq_enable(); > > - if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN || > > - handle_cfi_failure(regs) == BUG_TRAP_TYPE_WARN) { > > - regs->ip += LEN_UD2; > > - handled = true; > > + > > + if (insn == INSN_UD2) { > > + if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN || > > + handle_cfi_failure(regs) == BUG_TRAP_TYPE_WARN) { > > + regs->ip += LEN_UD2; > > + handled = true; > > + } > > + } else { > > + if (handle_ubsan_failure(regs, insn) == BUG_TRAP_TYPE_WARN) { > > handle_ubsan_failure currently only returns BUG_TRAP_TYPE_NONE? > > > + if (insn == INSN_REX) > > + regs->ip += LEN_REX; > > + regs->ip += LEN_UD1; > > + handled = true; > > + } > > } > > if (regs->flags & X86_EFLAGS_IF) > > raw_local_irq_disable(); > > diff --git a/arch/x86/kernel/ubsan.c b/arch/x86/kernel/ubsan.c > > new file mode 100644 > > index 000000000000..6cae11f4fe23 > > --- /dev/null > > +++ b/arch/x86/kernel/ubsan.c > > @@ -0,0 +1,32 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Clang Undefined Behavior Sanitizer trap mode support. > > + */ > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +/* > > + * Checks for the information embedded in the UD1 trap instruction > > + * for the UB Sanitizer in order to pass along debugging output. > > + */ > > +enum bug_trap_type handle_ubsan_failure(struct pt_regs *regs, int insn) > > +{ > > + u32 type = 0; > > + > > + if (insn == INSN_REX) { > > + type = (*(u16 *)(regs->ip + LEN_REX + LEN_UD1)); > > + if ((type & 0xFF) == 0x40) > > + type = (type >> 8) & 0xFF; > > + } else { > > + type = (*(u16 *)(regs->ip + LEN_UD1)); > > + if ((type & 0xFF) == 0x40) > > + type = (type >> 8) & 0xFF; > > + } > > + pr_crit("%s at %pS\n", report_ubsan_failure(regs, type), (void *)regs->ip); > > + > > + return BUG_TRAP_TYPE_NONE; > > +} > > Shouldn't this return BUG_TRAP_TYPE_WARN? So as far as I understand, UBSAN trap mode never warns. Perhaps it does on arm64, although it calls die() so I am unsure. Maybe the condition in handle_bug() should be rewritten in the case of UBSAN ud1s? Do you have any suggestions?