From mboxrd@z Thu Jan 1 00:00:00 1970 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 929F0196455; Tue, 10 Sep 2024 10:08:42 +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=1725962922; cv=none; b=niNSGR0tNEOZGXmeW1QKfEcvHRjwa+S8/cuLbid8jTjFgOzNJ7bq13ae9vvp/VPw3DR1Uga/wn8dB1cnPnGK7dWZo0r1sSSzXvPhlC8bjFHAx6KmFgoSEpRJviDFM0eIcPisFF3NzZFTJMv07kDOG4oMsrchCIkDEsBndFtPvLI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962922; c=relaxed/simple; bh=Cgwxu4SBjmLn/G289GKjdV3ulvk8hDUbeHtqU+jzDeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fByVcvKeVwfGcnJ1bm0nH+XnD/TmKh4o4ZCEZGe3LrXJrNyRiLeFSf9OnIwey+7lj7QKG2WfsTUzNjhuBL5bCGE1LUKwGyTYhDfpRHOy5/+8ckrIsucfumVOUOstPAhSASHiOcE/cs5dD+kpYeowM/zlyS6puRDhEjeVVTes0kw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Co+ABKTo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Co+ABKTo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBFF7C4CEC3; Tue, 10 Sep 2024 10:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725962922; bh=Cgwxu4SBjmLn/G289GKjdV3ulvk8hDUbeHtqU+jzDeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Co+ABKTooxd0VCzjkhMiUSZx0vuf+687RlTeHLfAJPlS3osM7TJCdOEoEl0IakD85 q0u8XXDAj645rjxc4D8cJ/Dlu4GGiIXZKDTQbo+qlafdQTI+TmtXTroMYdlerkuLMa SSgJxpUMaL+xv4uRV1gNtoMw2EXbsioEZKO+vSZU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Brian Johannesmeyer , "Borislav Petkov (AMD)" , Alexander Potapenko , Sasha Levin Subject: [PATCH 6.1 048/192] x86/kmsan: Fix hook for unaligned accesses Date: Tue, 10 Sep 2024 11:31:12 +0200 Message-ID: <20240910092559.969193249@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092557.876094467@linuxfoundation.org> References: <20240910092557.876094467@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Brian Johannesmeyer [ Upstream commit bf6ab33d8487f5e2a0998ce75286eae65bb0a6d6 ] When called with a 'from' that is not 4-byte-aligned, string_memcpy_fromio() calls the movs() macro to copy the first few bytes, so that 'from' becomes 4-byte-aligned before calling rep_movs(). This movs() macro modifies 'to', and the subsequent line modifies 'n'. As a result, on unaligned accesses, kmsan_unpoison_memory() uses the updated (aligned) values of 'to' and 'n'. Hence, it does not unpoison the entire region. Save the original values of 'to' and 'n', and pass those to kmsan_unpoison_memory(), so that the entire region is unpoisoned. Signed-off-by: Brian Johannesmeyer Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Alexander Potapenko Link: https://lore.kernel.org/r/20240523215029.4160518-1-bjohannesmeyer@gmail.com Signed-off-by: Sasha Levin --- arch/x86/lib/iomem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/lib/iomem.c b/arch/x86/lib/iomem.c index e0411a3774d4..5eecb45d05d5 100644 --- a/arch/x86/lib/iomem.c +++ b/arch/x86/lib/iomem.c @@ -25,6 +25,9 @@ static __always_inline void rep_movs(void *to, const void *from, size_t n) static void string_memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) { + const void *orig_to = to; + const size_t orig_n = n; + if (unlikely(!n)) return; @@ -39,7 +42,7 @@ static void string_memcpy_fromio(void *to, const volatile void __iomem *from, si } rep_movs(to, (const void *)from, n); /* KMSAN must treat values read from devices as initialized. */ - kmsan_unpoison_memory(to, n); + kmsan_unpoison_memory(orig_to, orig_n); } static void string_memcpy_toio(volatile void __iomem *to, const void *from, size_t n) -- 2.43.0