Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp159812pxx; Wed, 28 Oct 2020 01:06:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0swLBhUfbLxC1OWBFlZyJq3rxXNzxgWtQKy4vAhqh75LInIAPLAa2WXnphdMbz6xqtCTu X-Received: by 2002:a05:6402:17e4:: with SMTP id t4mr6613732edy.118.1603872404173; Wed, 28 Oct 2020 01:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603872404; cv=none; d=google.com; s=arc-20160816; b=FCE5m8CUSBIYVTaM23EXt606q0ftKi+yDaj99/brc/Df/Ia/PvAB+KZiCEIHAD2WSc gXEk64bHfTNGl7+11HjYhz1vTDRG2ieJW6k/RKHDxbKeQnleyCeW77FQZo6NFCQvBFDx RIhbY43uTi2OsVoD6s1N5d3GKTi6ptcPBy4s0aVl1Yhrl0b35sVJ3ssHGBR3W3a0HagO hBS9XCg9zNKgXN4lr7Tj/Gm8C8Lb5mdv75CIqHfMOC11/pRE6ZSjbQUyeq5S2neZ2PU4 XIeMq8NsSQd8ojDwkDJ8sFAqGx1HGJe5Ga0sY1iiI1h7goVocoVirtAEZ8A9swOiMZKj mx6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xtHe0Jm4KZB+1dPxhLSp7OdQd+FjmLnCtx69Bk7LODc=; b=h9U0Qlw/SmvXJcI/ny576sA5GBPEb6E91rYMPzvJzzPS9ObKeHgrs52rQDuXUwm91r ubYjcikOA4Z693eXqb32ZoLzigy/5qL2WMCc8rS4JhDIHacHGUrR290E7VDeiAIXGU4x /eRBYQT6bsDA20QI4Fa8hbZaxiCXmzY9n3jNNE8ILrrxyi130CtIoJf6//k+dsjErYmr zD4vMzZLRwyMV0Or6pItnD5jd0I4hoFGnfk/wkbl1Hbppg8l2uiF+3HBDjT9JWYvi0vs mEpcFMjh3aKEeZyszR7+PB7VjkaSQhUlKyBF/01FTisGXHPyIPlU90PuTPD1QKYHsPED vALw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CdOLkOLz; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si2698178edr.173.2020.10.28.01.06.21; Wed, 28 Oct 2020 01:06:44 -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=default header.b=CdOLkOLz; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752964AbgJ0N5x (ORCPT + 99 others); Tue, 27 Oct 2020 09:57:53 -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 = \