Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3085056pxb; Sun, 26 Sep 2021 05:01:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEzbnr44lwOJIZdsO49yt1om3KcssViwWfnzbKEOvFoo98hPxlWvQdb47TBl9OHRLMShYn X-Received: by 2002:a17:906:3f95:: with SMTP id b21mr20818470ejj.368.1632657692467; Sun, 26 Sep 2021 05:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632657692; cv=none; d=google.com; s=arc-20160816; b=SvwrEm5Obx+deRC01eK7TKAhSK8nhqKrVZjwa+6fjEhhqqnqaDa/fIvfZYKnJZhrq6 8Mh6Aqmkzi9bD2u9SjS5yXy3pDPA4TmBeXhMMWx/kk8pvEqiTH2MeePmjrcXqcqyyQAg B8+w/C68VIZsltgbD9oWzOFC8Tyz3mUOh6nInpAfCfFdPZM3GqHnQguCHhnDiJqPGeBC 0DAxwoAyeMlA0jEaNX3Hrl9zbrXdpQyurR9PxakMM42OBIXC9S9fUTL9YJ/Z+Y/e4Ho+ w+hx9pLKfT7EYQ2Qf/JRktb8QPJA7i3cLl5bhZa+YJN8cx352AqiXy0MZn+6YnpsRuBX ALgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QXm0+90qqsAFw0H9snr4law85rQCkidUWDz+rcVWNbg=; b=q7jOb58YE1fjSumYZhnc23zD/69lwGED8ZWdFYqBuArXdDgIcQQKIJ0C3qTiRVFvqm ALTdXtecYnrqzkhhJqU01ojEeBG8L0o3762LHViR84YTujWI5AkQaS/28nHuFzv/c0vy dcCpBTu9qFLVLqWmQZFxVGSFDvADDEHzW/5gFLx4dCCwx+fNe1+6UXcVJNQhPdTQ3gzy Nl34dl5UibN47LxJvGnJMzIsL2GsLdk/rWm1xeKpag0M7m1INRyDaXTOj9WyrRyq9doO NRYhrm9PDxoGrkDoguFn4D0OoI/Y2F3YpBFw+tOPm5bI4uTZvf6fCPbSBR4JSpeETsXN 1LxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pxh+fFUD; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si16231692ejl.237.2021.09.26.05.01.08; Sun, 26 Sep 2021 05:01:32 -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=@kernel.org header.s=k20201202 header.b=pxh+fFUD; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231138AbhIZMBP (ORCPT + 99 others); Sun, 26 Sep 2021 08:01:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:48858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbhIZMBO (ORCPT ); Sun, 26 Sep 2021 08:01:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F3BE961038; Sun, 26 Sep 2021 11:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632657578; bh=JxAHqSs54HWLkzs8GGZKJGY7bzgrYrkSWME5INakZyI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pxh+fFUD1g/hRnnkLHEPpYjqqiYncuArFCrHTi931PG1iVh0J7kA2jONkBuRdolrI LvrVp3x4PT1MaHv/ZG2c+JKJYhQI2D2HdD9Qt8gXaaT0s1wzxKdJMi+1rafk9R335h rd6GSygsN+Xbg8q3IiPcHga74r7ykB63OXY8BLSgJzHaQDxDOtkAMF8JO1vcyyTjrw 9tzkdYpD7kE3Vm/GIc5Ee+B7THAxUw2UQveeIp0pMnXOPd9xz06DSJRzYtN92BZDsD QKxBgcLFRQZ1hPAnrkaMQlmOMzM+lzqbPCu7pYrVuJ/Qb8tcDwGzi/C02J/EedKkUP BssCo0M7lxZPw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 3F460410A1; Sun, 26 Sep 2021 08:59:35 -0300 (-03) Date: Sun, 26 Sep 2021 08:59:35 -0300 From: Arnaldo Carvalho de Melo To: Masami Hiramatsu Cc: Ian Rogers , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Peter Zijlstra (Intel)" , Josh Poimboeuf , linux-kernel@vger.kernel.org, Adrian Hunter , David Laight , Numfor Mbiziwo-Tiapo Subject: Re: [PATCH v4] x86/insn, tools/x86: Fix some potential undefined behavior. Message-ID: References: <20210923161843.751834-1-irogers@google.com> <20210925133944.a0648549c28b047bd9aeaeff@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210925133944.a0648549c28b047bd9aeaeff@kernel.org> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sat, Sep 25, 2021 at 01:39:44PM +0900, Masami Hiramatsu escreveu: > On Fri, 24 Sep 2021 16:02:33 -0300 > Arnaldo Carvalho de Melo wrote: > > > Em Thu, Sep 23, 2021 at 09:18:43AM -0700, Ian Rogers escreveu: > > > From: Numfor Mbiziwo-Tiapo > > > > > > Don't perform unaligned loads in __get_next and __peek_nbyte_next as > > > these are forms of undefined behavior. > > > > > > These problems were identified using the undefined behavior sanitizer > > > (ubsan) with the tools version of the code and perf test. Part of this > > > patch was previously posted here: > > > https://lore.kernel.org/lkml/20190724184512.162887-4-nums@google.com/ > > > > Masami, if you're ok, just process it including the tools/ bit. > > Hi Arnaldo, > > This version updates the tools/ too, so I think this is OK. > (do I need re-Ack?) So you want me to process it? - Arnaldo > Thank you, > > > > > - Arnaldo > > > > > v4. Fixes a typo. > > > > > > v3. Is a rebase picking up a fix for big endian architectures. > > > > > > v2. removes the validate_next check and merges the 2 changes into one as > > > requested by Masami Hiramatsu > > > > > > Signed-off-by: Ian Rogers > > > Signed-off-by: Numfor Mbiziwo-Tiapo > > > Acked-by: Masami Hiramatsu > > > --- > > > 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 058f19b20465..c565def611e2 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 c41f95815480..797699462cd8 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); }) > > > -- > > > 2.33.0.464.g1972c5931b-goog > > > > -- > > > > - Arnaldo > > > -- > Masami Hiramatsu -- - Arnaldo