Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1671560pxb; Fri, 24 Sep 2021 09:23:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdCMV8eW/BP8G4d+eAu9OWK0YTEcSVKFSgBSeZQ1QBHbWXUmtadqaMtoI+xoWGEsTQQ50j X-Received: by 2002:a02:601f:: with SMTP id i31mr10281366jac.80.1632500590859; Fri, 24 Sep 2021 09:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632500590; cv=none; d=google.com; s=arc-20160816; b=d6VBxoHs7Nr+zyfgKkY0l80So/QWZeJxPhCy1WF/E4n8RvBX192s2UcTHxC86bmYA9 TlQRYI9ChVzuoApdlL3wCgPxaxSQ6wX0Q4D+DTtjiaq78SFr2620o23iRNy8sd9UF7w9 kH5q8Prnrg1cyBg6KmlZtvnxkzxzwedTh31PpWh4UzS6Q1iDQc62eBXUYo9XizuAa09F T/97ADKvSrabWgwYSpfXFZuMqxRDUgRr8e8V+r6WKo1fqBUR92YT6pVrHchimvBcNqWy sRfpgIoUQCfvEga/CP1zTE2TfQaqVRdFmRm916L6iybMVHSRzGkkmjiga8ev3FTzvwpW THAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=QC1Zmi/OXCL9LTXdUwZ7DHvcDGZgdrX8haxzTkA8RnM=; b=TPyOCxVh0uKaDYQgknaB/t28lEVD8HvqD99q6TYn0yAcBzt8DcNX7xtxbgzovwrX/T bo4L2FCoNIUY2P/3pzGI2YWCqc6a3Fkst/k8pwjKLA+CD4PRwZ2in0Hg/Tmc6grYQEa6 zUJ7GmXoY3JL5151GJZ2yIBTc1C1WlwS/DsJlUfec+/y2j1IxMlAR8Qn2d4yrGxs6zqE SA8LZSqaoWXxdE18lKgI70rtPYqTApKgk9RNAJHNHs5loOALV/8uGVPXavCvX1uskwVf zGGKiXIM2tjVCihGkaA3aPC16cZWUiIT5ugmFVjKVrrS+J65LjGW0le/fwshZEkkx2AC bOKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zRbG4Tzk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si11454938ilv.110.2021.09.24.09.22.50; Fri, 24 Sep 2021 09:23:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zRbG4Tzk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244696AbhIXKq4 (ORCPT + 99 others); Fri, 24 Sep 2021 06:46:56 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:41190 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbhIXKqx (ORCPT ); Fri, 24 Sep 2021 06:46:53 -0400 Date: Fri, 24 Sep 2021 10:45:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1632480319; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QC1Zmi/OXCL9LTXdUwZ7DHvcDGZgdrX8haxzTkA8RnM=; b=zRbG4TzktzzZuNLhdEbGasFOXx0MSxfWAnlZ9MivNZqIK27Vv3WPyJi10I8jgWtCEiOF8f A7EMSVTKsEk5p3FQuvJwSmBfqRC1gSZ18obzzWOHeDjTropRP3f69cD7kmD8eFRERrG0pr dj6/vi4eocnplYEvQBSS8ULLAhxv6DpaSw2M5QtWf5O0oKOW16CPs99AQChRTXl4k/E3Tu cBKZK6wqnjeNAI9ph7KqZgYgzXIgmZH7rDFG3UiVHQYUCyDU7HnMkEnxhhb5k2twRU97Sa KS0g8mGaoMXeSpL84H7l2To3Xwo64AfRIV7bwpPdrhH01kElZFGZ2vUSNBhT4A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1632480319; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QC1Zmi/OXCL9LTXdUwZ7DHvcDGZgdrX8haxzTkA8RnM=; b=GHloRE7zfaNW3c3G4BO+DaW1aGgh7ylNIyjPMwhBPbaTdvKfXn4SUjFz2n/27RBLAsC/72 ngBvHFKXmNAXt6AA== From: "tip-bot2 for Numfor Mbiziwo-Tiapo" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/insn, tools/x86: Fix undefined behavior due to potential unaligned accesses Cc: "Numfor Mbiziwo-Tiapo" , Ian Rogers , Borislav Petkov , Masami Hiramatsu , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210923161843.751834-1-irogers@google.com> References: <20210923161843.751834-1-irogers@google.com> MIME-Version: 1.0 Message-ID: <163248031804.25758.7658032205520387028.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 5ba1071f7554c4027bdbd712a146111de57918de Gitweb: https://git.kernel.org/tip/5ba1071f7554c4027bdbd712a146111de57918de Author: Numfor Mbiziwo-Tiapo AuthorDate: Thu, 23 Sep 2021 09:18:43 -07:00 Committer: Borislav Petkov CommitterDate: Fri, 24 Sep 2021 12:37:38 +02:00 x86/insn, tools/x86: Fix undefined behavior due to potential unaligned accesses Don't perform unaligned loads in __get_next() and __peek_nbyte_next() as these are forms of undefined behavior: "A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type. If the resulting pointer is not correctly aligned for the pointed-to type, the behavior is undefined." (from http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf) These problems were identified using the undefined behavior sanitizer (ubsan) with the tools version of the code and perf test. [ bp: Massage commit message. ] Signed-off-by: Numfor Mbiziwo-Tiapo Signed-off-by: Ian Rogers Signed-off-by: Borislav Petkov Acked-by: Masami Hiramatsu Link: https://lkml.kernel.org/r/20210923161843.751834-1-irogers@google.com --- arch/x86/lib/insn.c | 4 ++-- tools/arch/x86/lib/insn.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 058f19b..c565def 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -37,10 +37,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr) #define __get_next(t, insn) \ - ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) #define __peek_nbyte_next(t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); leXX_to_cpu(t, r); }) + ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) #define get_next(t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); }) diff --git a/tools/arch/x86/lib/insn.c b/tools/arch/x86/lib/insn.c index c41f958..7976994 100644 --- a/tools/arch/x86/lib/insn.c +++ b/tools/arch/x86/lib/insn.c @@ -37,10 +37,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr) #define __get_next(t, insn) \ - ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) #define __peek_nbyte_next(t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); leXX_to_cpu(t, r); }) + ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) #define get_next(t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })