Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp35152lqj; Sat, 1 Jun 2024 07:07:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9Qp21Ylp29cfHFRmjampkMt+tluUmLoUs6wpmZxX9Tg7iugYfNeUFHLm/keflFou+NyikN9G7loN/UZ60uUWkCTGLBTpcJ+gpJ+VfAQ== X-Google-Smtp-Source: AGHT+IHmu6S0l7eMKyrr6KlAQtsqTOaQn1PnQWJie/6vwjNpiUIFrBJDjfVzBW3bsUuKnO64CFQA X-Received: by 2002:a05:6a00:2408:b0:6f3:e9bc:7ed5 with SMTP id d2e1a72fcca58-702477bd8c9mr5209372b3a.4.1717250849505; Sat, 01 Jun 2024 07:07:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717250849; cv=pass; d=google.com; s=arc-20160816; b=glosigU8TCjszCaPWwOqgCKojN2lOVQdSpBDb/90lVqwyrkilkx65/bhU74w/55E7j RM2Rd4viQ5lwRPttCfs2RTYf+nKdYZcf0e7wh3hiACGn9NOvgaB09783vYHXEXdEZs6L Ek2uavIhhlSqT2XnaeaJ796X/iy55Q2wJGi4v36It2Q9PPSeGbRDd15GJREmtUfiI7ls S0uR6Phv6RynyYc7Y97mreSjjyDndnfyCqfYDWlE/Q9Zknz46qeZwh4NMOz1jmfiYq1c //brn52PXM6dClkBLe5glJdcAb/BwYXZLigaXyiK2KWRxT3bG8LnMkkIBMtwXCOoi+OM Ds1w== 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=2YrNxlAfm8atSSMWUuO/bV9+KAJblkjpZJhGMH5prSI=; fh=QLazlS7EGh5PYxYf9NzlI0mDL+ZY77OPKlGcX7oWOmI=; b=KYqzm+bC1QAqkThmnoWtzXeNZiZDvpH2T06yopO3YpDmbZlW2QUiEnS+YkyRzZ1lA9 eBILDg7+TwjSqNej4Y73mAiCwd5JX9ZqfH0ApXVLnO24fwcqs3ZP/mJT1TzVx3nUxpUU 5ULpAt2kFrbB7S0cJqfnjV5zc48GnJDxBFifUgl4bxuPvaCRWqzOc1ZJq1ZN+GWuhJlc U5spBeFRjJE24QpIBTsDE/gg+UzaGh0p4pkQq639CnPkbTg/31TfrPYTlPg915mb0nQ5 6HI6ebHcHj7tTyc3W4svv8h18J0H8z0H+pxAh/CveAm3XErXngyFDNqJvtrFsz5PPATJ pYUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=unBUsn8O; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-702558d3663si1418152b3a.104.2024.06.01.07.07.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 07:07:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=unBUsn8O; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E885C2839BA for ; Sat, 1 Jun 2024 14:06:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0891F15217A; Sat, 1 Jun 2024 14:06:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="unBUsn8O" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B7851E871; Sat, 1 Jun 2024 14:06:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717250798; cv=none; b=lcISbNyJDTwuqHL3mL7lsDjRJA7nioP7mbgp+WF4Oz3NxoJkuOWXj97BomYEgPO35vhQUdlwNqKRAUToyP4wcSvNmYNhzO1Uhamh+4aHWzV62NaehBg7vaA3UWz4Ofd+xaGHJGmfuiYovtW7nMXhyKy2OJAr4bNKb45hIZ+wX0c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717250798; c=relaxed/simple; bh=/j5ILFtMpjiIaAV7H+hfiVW/2tt6sQJV0z9kL5h7blc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RU+tzlH0Aic9Ry3vA1O3vMIof87VGVHejRdDJICVtqIY+u6qkSK2pAGYOiie7jX7O47TJ7cKHQLGFSJA0TiLPajRIppakxzlmAHZ5cK+ffvvjPCe4WckZNVKsnTwz1M6vhzbbuM1OiKYCF/D5Ia+owhCDzyT8QDHWvxUTSEbiaI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=unBUsn8O; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E446C116B1; Sat, 1 Jun 2024 14:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717250797; bh=/j5ILFtMpjiIaAV7H+hfiVW/2tt6sQJV0z9kL5h7blc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=unBUsn8OXnCRHHFbp1bQ5L3fAmmACope/0sfX8QPNVMYsbcSoMivByMZz7ky1L2IW g3uQfvzBBoRVOqvt9t+5aCi10VUBLqUp35B9CwVmEVvp9AhfwOIDk1wRsqRb3O+jhP RmnhhtpADfAAVBHmEanVQ+PrJw4mjhRUvixLFIbKgmNG9fFhNjOzfX1fCaMCc8qRL3 Y5AmIsWUuJSm/ogD3wc0/RGSGg06LTy+v/PPfmkme+Q0E98Cp0S/0ofIudzlGoU2Bl ky1UXb5KGs4CgA9ltXovNUsf6rCapRU8Yve3PQ9+ZOm3xxIWU8iZilAQ7FWv21ETvt u5CfNTB2iXIBQ== Date: Sat, 1 Jun 2024 07:06:37 -0700 From: Kees Cook To: Gatlin Newhouse Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Marco Elver , Andrey Konovalov , Andrey Ryabinin , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , Rick Edgecombe , Baoquan He , Changbin Du , Pengfei Xu , Josh Poimboeuf , Xin Li , Jason Gunthorpe , Tina Zhang , Uros Bizjak , "Kirill A. Shutemov" , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v2] x86/traps: Enable UBSAN traps on x86 Message-ID: <202406010700.39246BA@keescook> References: <20240601031019.3708758-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: <20240601031019.3708758-1-gatlin.newhouse@gmail.com> On Sat, Jun 01, 2024 at 03:10:05AM +0000, Gatlin Newhouse wrote: > +void handle_ubsan_failure(struct pt_regs *regs, int insn) > +{ > + u32 type = 0; > + > + if (insn == INSN_ASOP) { > + type = (*(u16 *)(regs->ip + LEN_ASOP + 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; > + } The if/else code is repeated, but the only difference is the offset to read from. Also, if the 0x40 is absent, we likely don't want to report anything. So, perhaps: u16 offset = LEN_UD1; u32 type; if (insn == INSN_ASOP) offset += INSN_ASOP; type = *(u16 *)(regs->ip + offset); if ((type & 0xFF) != 0x40) return; type = (type >> 8) & 0xFF; pr_crit("%s at %pS\n", report_ubsan_failure(regs, type), (void *)regs->ip); -- Kees Cook