Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp464736lqb; Wed, 29 May 2024 00:26:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWxZFNJUgfcoZQOSXLOEF1DZf2QeyqHDJqWIgcQApUNZh7EksEKFym6rcyCjUN3WPYKoYyjIOJ6fWaoUyHihyNOoD4hTvhiM494+0YcGQ== X-Google-Smtp-Source: AGHT+IF0EglbpiulKscRWmDVVlJEHCzTVUL2tMR+lpAk4lxG3n20neQRj0glGt4iicxU/4/HjoAt X-Received: by 2002:a05:620a:4acd:b0:792:f70e:7fd with SMTP id af79cd13be357-794ab0a3167mr1804214985a.29.1716967588113; Wed, 29 May 2024 00:26:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716967588; cv=pass; d=google.com; s=arc-20160816; b=NsZfv2GX9V4sxIPQRl3lm8dVzItWHwtbukpQUkKZitmW9JNGWcuDW1NI7NV3E43h1f f8UYs3atKwLiKQj54fC/TUhMZaV8tFsLQxU8lNX8UHAKbSzK0nL6OtZ4pd5e3LKhJuiD AJ83X93cUlBOvyVJm1+m0QHQjqy4ilwjqb3feAc5azjGDZkejoVNUn/WssLhopGrwZmX HzQlYhh1pVTClHts71WuYcJtHPkmAN3PVXLL+rKwss8+O4ziitiOYRvSkMbeF5bxQpJa L1kg1/uBpndNvjhBB3oHT8bBIQ+DKLNHvWC7qlJCaFZUd3wTLEedOcUqetLJozSkYsmw 0p6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=nWzvmzN7ijIbCBaVTu7XEGtPfeKO3l3ACHDt/WVaHXI=; fh=BZMRrpFZTLI74JBb4q6a0L9l72GDuJFU2ux+cFRbZWE=; b=NFCmHsqezL4ncwHNGuQg/0JZUH++uNO1c/trq/62BmbQ6rW1tmr7FNye2/BnVpPnB8 SABRg+GNkbCJcs0FStvhgUon9c8Vf+jTNztEf5jQK19t9HFN3togl78xaqHA596uSISO rTG/0pEWMMxJk5iZ9vfBEOncFaPqdLrP90dVXS7NJpT0c44D2ZTvWDKMWnSstwZlDskU KVupp2iHVRoFbYowodXPMeSEV5Z1bZIDqE9T0pZIQVSq8nCYIsVCUldusMXvmfeyeuP9 PdnmGaa3x5kHqb0Nal7Kl1lLYmrIXv+Bf7ez3ApFiEiZBUhDtGr4m8YHDGfpbxE0QWWa xj9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=LuB82S6W; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-193577-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193577-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-794abd51d69si1192089885a.627.2024.05.29.00.26.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:26:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193577-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=@google.com header.s=20230601 header.b=LuB82S6W; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-193577-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193577-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 C69791C23CE6 for ; Wed, 29 May 2024 07:26:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4F4F167DAC; Wed, 29 May 2024 07:26:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LuB82S6W" Received: from mail-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) (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 386AA167D8C for ; Wed, 29 May 2024 07:26:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716967562; cv=none; b=BCwVfy5ILGWTSjJTUxnfLAfgejSv9IBD39RmA2BFTIo9LjHgPX5iAO23EG3tNIk0UnBzj6u9N2myekjZRp1slFB+Njvbc/MaaI94bm4mNdmsrjIXhsctxHdLgXmvbfIIqt66Ep8OJA+Jm4T1PY65TL/NHajvUVbkmrz3roWL9r0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716967562; c=relaxed/simple; bh=ZEVr1l/zLyARsxNs4P1butY5hWf3rmFo/maylE+sV1M=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=AgugjIHpaqCKDzO65MEcIBcfdhCGeM/lC1wDvWWya5myTIPlYw8Rqj1uJ+FauSnDjjIOqpbjUUbySXQ5ffXtroys3aZpxx6KiQVmZAsHfrEtYABnNkSvu3Q3X+GkE3UKWouD4sZ1yA2YeArEKZuvcSFwYnlHbPeLFg5zf6MUZvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LuB82S6W; arc=none smtp.client-ip=209.85.222.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ua1-f51.google.com with SMTP id a1e0cc1a2514c-804e3292412so517162241.0 for ; Wed, 29 May 2024 00:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716967560; x=1717572360; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nWzvmzN7ijIbCBaVTu7XEGtPfeKO3l3ACHDt/WVaHXI=; b=LuB82S6WQmX44POw5vy077+mYh3OFYpuPrUd48BRtutR+Fv41w1B1iTjjWm9ifBLGE BkNWDaRBxaRY9uvPcMACM7CB8wvcmenkrHVkP+PB/UrfvfvcGynn43/w3IEqLYV4ZTPE GFpnPRcjiddqBbZtS01emkha/YOZUK6IkdxWwcxwMR39sRqNILsndHEjqyzyYvYmfvxA XqD3+mZzQGUAdt3ezRk9IOsQbYIc0eStARi2FOGIARCsWlhT8yqbDz+7V6hyLPFmMY3I F7SE0FTzjEqmum0pL9TYnTw0nU8LE7sl0IgStUgHmzdaXSlxpuow4ZxIHIjdSigsE3UJ NJYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716967560; x=1717572360; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nWzvmzN7ijIbCBaVTu7XEGtPfeKO3l3ACHDt/WVaHXI=; b=o21K/gjLmVLYJs1Lo8PSM3PM2OmsV2J2dai/y1y+xeqigMeL4E3qQli0s0Y6msOpjW WrD0mSWIH9SIiq/3Zs21gyh0Cy/EwlNFK6LV64EYNGrEt7ydjG4Uhfy6c9rtt3qCC/NL hh1ImSGtNGtUbhVGVfOI2JJdkeciszY0P7eGJ5jJYwtk3ivrkl4uHOv28jig5RH6K96T zeLQbKyluE3kQGup6BHx3l/hNeEpeMyNCOwYIfoki6ppBXaHfiQiqz47uGfN1tlwcSx0 +HFgXjK9+0YsYM4dPuy/GTVF/VaiXTJofK+tPhFGXAZg3+Sr2lWLj0GuXPDpvrjfm8Y1 /anA== X-Forwarded-Encrypted: i=1; AJvYcCUPCiMx15q1d2vRYkUpVMJBfIqhS5NAxSUzPnwnrkETCwW4NlXZGTwR8s15TYJMHoUxavbyG6ih4xkeaE5d+A9NaB4rhj0vy1E4mOio X-Gm-Message-State: AOJu0Yy9tuUNekrjj8izsYFBlXhcxjYbiclJ4jx9YfZn0C7WnoN7xNHm L3OnnZ/7q3TPcGt3mUEibG+IDOWgYZ8FURVxCKfT6fe1RRPatO3JN5CoS9FtUKD0lTgZCeVwBjw PgMZOuTRJ0kaUWSziqVtTC6FrQ7oaBZwTC/67 X-Received: by 2002:a67:f4c7:0:b0:47c:2c84:4321 with SMTP id ada2fe7eead31-48a38575d3cmr13715697137.16.1716967560033; Wed, 29 May 2024 00:26:00 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240529022043.3661757-1-gatlin.newhouse@gmail.com> In-Reply-To: <20240529022043.3661757-1-gatlin.newhouse@gmail.com> From: Marco Elver Date: Wed, 29 May 2024 09:25:21 +0200 Message-ID: Subject: Re: [PATCH] x86/traps: Enable UBSAN traps on x86 To: Gatlin Newhouse 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 Content-Type: text/plain; charset="UTF-8" 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?