From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Numfor Mbiziwo-Tiapo <nums@google.com>,
Ian Rogers <irogers@google.com>, Borislav Petkov <bp@suse.de>,
Masami Hiramatsu <mhiramat@kernel.org>,
Sasha Levin <sashal@kernel.org>,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
x86@kernel.org, gor@linux.ibm.com, jpoimboe@redhat.com,
schwidefsky@de.ibm.com, peterz@infradead.org
Subject: [PATCH AUTOSEL 5.14 36/40] x86/insn, tools/x86: Fix undefined behavior due to potential unaligned accesses
Date: Tue, 28 Sep 2021 01:55:20 -0400 [thread overview]
Message-ID: <20210928055524.172051-36-sashal@kernel.org> (raw)
In-Reply-To: <20210928055524.172051-1-sashal@kernel.org>
From: Numfor Mbiziwo-Tiapo <nums@google.com>
[ Upstream commit 5ba1071f7554c4027bdbd712a146111de57918de ]
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 <nums@google.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Link: https://lkml.kernel.org/r/20210923161843.751834-1-irogers@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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
next prev parent reply other threads:[~2021-09-28 5:58 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-28 5:54 [PATCH AUTOSEL 5.14 01/40] spi: rockchip: handle zero length transfers without timing out Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 02/40] afs: Add missing vnode validation checks Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 03/40] platform/x86: touchscreen_dmi: Add info for the Chuwi HiBook (CWI514) tablet Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 04/40] platform/x86: touchscreen_dmi: Update info for the Chuwi Hi10 Plus (CWI527) tablet Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 05/40] nfsd: back channel stuck in SEQ4_STATUS_CB_PATH_DOWN Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 06/40] btrfs: replace BUG_ON() in btrfs_csum_one_bio() with proper error handling Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 07/40] btrfs: fix mount failure due to past and transient device flush error Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 08/40] net: mdio: introduce a shutdown method to mdio device drivers Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 09/40] xen-netback: correct success/error reporting for the SKB-with-fraglist case Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 10/40] sparc64: fix pci_iounmap() when CONFIG_PCI is not set Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 11/40] platform/x86/intel: hid: Add DMI switches allow list Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 12/40] platform/x86: gigabyte-wmi: add support for B550I Aorus Pro AX Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 13/40] ext2: fix sleeping in atomic bugs on error Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 14/40] drm/amdkfd: handle svm migrate init error Sasha Levin
2021-09-28 5:54 ` [PATCH AUTOSEL 5.14 15/40] drm/amdkfd: fix svm_migrate_fini warning Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 16/40] scsi: sd: Free scsi_disk device via put_device() Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 17/40] scsi: elx: efct: Do not hold lock while calling fc_vport_terminate() Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 18/40] usb: testusb: Fix for showing the connection speed Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 19/40] usb: dwc2: check return value after calling platform_get_resource() Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 20/40] habanalabs/gaudi: use direct MSI in single mode Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 21/40] habanalabs: fail collective wait when not supported Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 22/40] habanalabs/gaudi: fix LBW RR configuration Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 23/40] selftests: be sure to make khdr before other targets Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 24/40] selftests:kvm: fix get_warnings_count() ignoring fscanf() return warn Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 25/40] selftests:kvm: fix get_trans_hugepagesz() " Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 26/40] selftests: kvm: move get_run_delay() into lib/test_util Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 27/40] selftests: kvm: fix get_run_delay() ignoring fscanf() return warn Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 28/40] Xen/gntdev: don't ignore kernel unmapping error Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 29/40] swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 30/40] nvme-fc: update hardware queues before using them Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 31/40] nvme-fc: avoid race between time out and tear down Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 32/40] thermal/drivers/tsens: Fix wrong check for tzd in irq handlers Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 33/40] scsi: ses: Retry failed Send/Receive Diagnostic commands Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 34/40] irqchip/gic: Work around broken Renesas integration Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 35/40] smb3: correct smb3 ACL security descriptor Sasha Levin
2021-09-28 5:55 ` Sasha Levin [this message]
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 37/40] io_uring: allow conditional reschedule for intensive iterators Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 38/40] block: don't call rq_qos_ops->done_bio if the bio isn't tracked Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 39/40] tools/vm/page-types: remove dependency on opt_file for idle page tracking Sasha Levin
2021-09-28 5:55 ` [PATCH AUTOSEL 5.14 40/40] kasan: always respect CONFIG_KASAN_STACK Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210928055524.172051-36-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=bp@alien8.de \
--cc=bp@suse.de \
--cc=gor@linux.ibm.com \
--cc=irogers@google.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=nums@google.com \
--cc=peterz@infradead.org \
--cc=schwidefsky@de.ibm.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox