Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3785797ybi; Mon, 29 Jul 2019 12:35:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeEGb0DCIBzJ0CRL+PKdNhGMBVk0XQfh33wRjzDR6G3D/ltOoKLz7BaJt+79KvqsJGoAQF X-Received: by 2002:a65:4808:: with SMTP id h8mr104635663pgs.22.1564428916064; Mon, 29 Jul 2019 12:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428916; cv=none; d=google.com; s=arc-20160816; b=QBr0SpU7fvbQ7DJnJ95Baf1lA0b4W4PQM/7J37ybEmXe/EvpjbLdYopgm0wqu54UDH eL3mZPPy8eqMwypdEuGT+FnMXyklYk7gQi/JF178t5xfcOTHc/3t0KAcO/05nQB3fX/K gZgkEjB9Bi0XUcT2Apf4vS5dfayps9kd8diqYOPWReuxtdb9T0233ZKxGsSnGXNyDRB5 a6X6blE1d0M6WpbVlZ5n20k7Qt1Qxx9BltQexh7XE7KMnlRAH8Szbxwzz2ULALg5wV/H 46pWu5hIYiVr/Zetdh4he6morZQjcXpuRiRc4hbOlDHjv6zY9M9jUTJuG2IHeILpeqmk jMew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wQm2fltfRsNucNNsKDraNkUjS/8zUOxu+mwSFXMgd/0=; b=EiZswSvf1VysUYVPwuDSHAHbRvQFClaBNEYJUhEoCOk8ug4QzyCNMmJFNJ6UmkWOS3 SiH0eSqVCj9sG4E9PnI615p656jav/r7YrjvcHfxSIBQRlvIyvDOBuAs6yrNJMcbpREO wBjP8/lb+5xVPlVtQEy1lp0RCp1z7Vx8TyClREJSmn4L9ZdMLAfm/gJrwVFhCM7YSTlw PSeB17nndlxvzumqxAejCIyfRmtpeEDt4s8wRjF04RUILNXeRiIfXl9qM8Qg+g6HA9sI aazCOkYcvVd9sD7WaP8IxdN4G9pjMV0SyfcFR9NAEmcZk77FbdnKKN8asOx5E82tDud9 SLRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gCVgdSSy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b41si26084109pla.409.2019.07.29.12.35.01; Mon, 29 Jul 2019 12:35:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gCVgdSSy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729627AbfG2Tc6 (ORCPT + 99 others); Mon, 29 Jul 2019 15:32:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:46518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725975AbfG2Tcs (ORCPT ); Mon, 29 Jul 2019 15:32:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A3127217D6; Mon, 29 Jul 2019 19:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428768; bh=LiGSuNB9y2psHrp6HAu8WaKeI1QQ1uvdJ9SRX8Bhp54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gCVgdSSyGSijNLKk9q1gBlIaPLHMHgbKrsDVKScpSRKsqMtWEbQZh41pWcT6S8R7f 5nEMQICSBqLwkEXMBpHqDs1yY/fMGd30SPQKZcZe+t0S1M8lr5AYPssrdURwaOilO0 mraMVmmTNKvezILyAxNT8JJXKjt5+69g9MX4nFqo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Ryabinin , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 179/293] compiler.h: Add read_word_at_a_time() function. Date: Mon, 29 Jul 2019 21:21:10 +0200 Message-Id: <20190729190838.211695661@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 7f1e541fc8d57a143dd5df1d0a1276046e08c083 ] Sometimes we know that it's safe to do potentially out-of-bounds access because we know it won't cross a page boundary. Still, KASAN will report this as a bug. Add read_word_at_a_time() function which is supposed to be used in such cases. In read_word_at_a_time() KASAN performs relaxed check - only the first byte of access is validated. Signed-off-by: Andrey Ryabinin Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/compiler.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index f490d8d93ec3..f84d332085c3 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -238,6 +238,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s * required ordering. */ #include +#include #define __READ_ONCE(x, check) \ ({ \ @@ -257,6 +258,13 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s */ #define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0) +static __no_kasan_or_inline +unsigned long read_word_at_a_time(const void *addr) +{ + kasan_check_read(addr, 1); + return *(unsigned long *)addr; +} + #define WRITE_ONCE(x, val) \ ({ \ union { typeof(x) __val; char __c[1]; } __u = \ -- 2.20.1