From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF4D1C388F9 for ; Tue, 27 Oct 2020 18:27:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88ECF2068E for ; Tue, 27 Oct 2020 18:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603823259; bh=v8P6ZSRKnnsELgim7giWIaierPdmu0FAQLMPvm0bIjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=V0cX+2pExDEWZuZf14peSjwj3PJ4hBVDtuUtJ+yCPdDaO4sQP+03h95odaWCZAnv3 V1hVhehxHhmg8k6p6Vs/BTEntK6/5BmEPVqcDw4VF9Qsp2WcR6LEkFqItDl2YRlsuo P7tRlqObwXZD+zt7/tcltDnRImX2GrQCTXBTN+gU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752969AbgJ0N5z (ORCPT ); Tue, 27 Oct 2020 09:57:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:44956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752955AbgJ0N5w (ORCPT ); Tue, 27 Oct 2020 09:57:52 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 601112072D; Tue, 27 Oct 2020 13:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807070; bh=v8P6ZSRKnnsELgim7giWIaierPdmu0FAQLMPvm0bIjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CdOLkOLzuUi5TPFQ5jC5G3/9uJCG7h7cH0zAAqko3wdrTN+ISnyCFZGU/sl4vBnsE nk6Y9Na69QOC0BumZpX6tW8d1WndPJbb+JO2CeGD+4BqzmnFIA8h7QwrqxRHcq19gC hiiWw20ktbibb22/+4ahYt7whDmW4JwDwJI2LSCU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Ryabinin , Linus Torvalds , Ben Hutchings Subject: [PATCH 4.4 009/112] compiler.h: Add read_word_at_a_time() function. Date: Tue, 27 Oct 2020 14:48:39 +0100 Message-Id: <20201027134900.991495979@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Ryabinin commit 7f1e541fc8d57a143dd5df1d0a1276046e08c083 upstream. 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 [bwh: Backported to 4.4: adjust context] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- include/linux/compiler.h | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -292,6 +292,7 @@ static __always_inline void __write_once * with an explicit memory barrier or atomic instruction that provides the * required ordering. */ +#include #define __READ_ONCE(x, check) \ ({ \ @@ -310,6 +311,13 @@ static __always_inline void __write_once */ #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 = \