Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2169715ybk; Mon, 11 May 2020 13:47:10 -0700 (PDT) X-Google-Smtp-Source: APiQypIh56uyC05025/i43ENDVA+rlQuyrOLv5aVlIkJ5Ki63AZ58StU2xZQcY1VRBlSYJPiAAeg X-Received: by 2002:a17:906:1502:: with SMTP id b2mr15166918ejd.359.1589230030553; Mon, 11 May 2020 13:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589230030; cv=none; d=google.com; s=arc-20160816; b=FcYk38+PCl5r2ADsCDr4k9j9Z6j/ZG71NbV/kcX4QxawfjRk6LLLWAON9gNwNBjeeD CSoL9SiG0zNoT9amLt3OmxMJ28jAmJ3HoYt+9yfvdurajSbYhB1cYA9ljwSLyi1XXek8 RJW8TmhWqagFa4ulNaj8m/4+BxZxyLj9WJ4fEcqEsyXSCODWumAtlNUxhUjLe0Uhd8o2 i0UEGiXTXz6PU6nlQxAeE3LfoVbpvBlOShUmFIdTJhjqLlayouOLinwhqasus22VkWz3 cnZzAvtRD7riZd434fOTdd1VXSVbdU8sL23LeAM9Shgv97ukeJcs+IAfq81/EF15aJWc 5G3g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xfyGVqX26cFCZpIw7qQdfQmb4Nxk0NTwfboshAugXFA=; b=pCqIhu0vdKovJxXLjXXArTSdAPhm3Riow91BSe9PDv6AAem5Q/1xyxfAqr7RSujxv2 HN4CaOTsD+5LrWUjoxGz5revDWTfY5kQqbcd3cxDkiTiVpQcOv8ulyDNtU6pELTmUDX/ xx58lcUAg8lQF2nNs5jMaQ0fAWJbrfFHKbzzcFVcZPPZeCvi9xOHc9AfpT2TDJNg4CNv yVIB90eKbtivZc9leWF/qXUK2j23qH30H6lcKwIcw5vskChVxrr6iu1x83HQ73/8wNk+ uJqxRXP/6JHyQxUVvsQm+2DsrS3nHN4YHZGf45ywW42Au3QU+19nYxY1Rl3fzX0vucfM lbFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oZVwBbiX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j27si2565621eja.471.2020.05.11.13.46.47; Mon, 11 May 2020 13:47:10 -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=oZVwBbiX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731840AbgEKUmt (ORCPT + 99 others); Mon, 11 May 2020 16:42:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:54440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731845AbgEKUms (ORCPT ); Mon, 11 May 2020 16:42:48 -0400 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A5C920661; Mon, 11 May 2020 20:42:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589229767; bh=tpwiFonkVii08Wax+QRh0gYMppP9Z3QZFEwANTYrstU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oZVwBbiXz8kJHZ9kzAeBBlFcac9l8eIeNc1Fex6FAlOi9trBR3AE7TC/gL17puZP4 DHywMoKT8YOMzxr8zLoCN4ytT58gL8M9laHXMkriydGhdTWSea40Asx4rFro624iKy 2ieWVS2OWPepoBLfsLGJiRM3imwJnt/6tr1vD2iY= From: Will Deacon To: linux-kernel@vger.kernel.org Cc: elver@google.com, tglx@linutronix.de, paulmck@kernel.org, mingo@kernel.org, peterz@infradead.org, will@kernel.org Subject: [PATCH v5 09/18] arm64: csum: Disable KASAN for do_csum() Date: Mon, 11 May 2020 21:41:41 +0100 Message-Id: <20200511204150.27858-10-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200511204150.27858-1-will@kernel.org> References: <20200511204150.27858-1-will@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org do_csum() over-reads the source buffer and therefore abuses READ_ONCE_NOCHECK() on a 128-bit type to avoid tripping up KASAN. In preparation for READ_ONCE_NOCHECK() requiring an atomic access, and therefore failing to build when fed a '__uint128_t', annotate do_csum() explicitly with '__no_sanitize_address' and fall back to normal loads. Acked-by: Robin Murphy Acked-by: Mark Rutland Signed-off-by: Will Deacon --- arch/arm64/lib/csum.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/arm64/lib/csum.c b/arch/arm64/lib/csum.c index 60eccae2abad..78b87a64ca0a 100644 --- a/arch/arm64/lib/csum.c +++ b/arch/arm64/lib/csum.c @@ -14,7 +14,11 @@ static u64 accumulate(u64 sum, u64 data) return tmp + (tmp >> 64); } -unsigned int do_csum(const unsigned char *buff, int len) +/* + * We over-read the buffer and this makes KASAN unhappy. Instead, disable + * instrumentation and call kasan explicitly. + */ +unsigned int __no_sanitize_address do_csum(const unsigned char *buff, int len) { unsigned int offset, shift, sum; const u64 *ptr; @@ -42,7 +46,7 @@ unsigned int do_csum(const unsigned char *buff, int len) * odd/even alignment, and means we can ignore it until the very end. */ shift = offset * 8; - data = READ_ONCE_NOCHECK(*ptr++); + data = *ptr++; #ifdef __LITTLE_ENDIAN data = (data >> shift) << shift; #else @@ -58,10 +62,10 @@ unsigned int do_csum(const unsigned char *buff, int len) while (unlikely(len > 64)) { __uint128_t tmp1, tmp2, tmp3, tmp4; - tmp1 = READ_ONCE_NOCHECK(*(__uint128_t *)ptr); - tmp2 = READ_ONCE_NOCHECK(*(__uint128_t *)(ptr + 2)); - tmp3 = READ_ONCE_NOCHECK(*(__uint128_t *)(ptr + 4)); - tmp4 = READ_ONCE_NOCHECK(*(__uint128_t *)(ptr + 6)); + tmp1 = *(__uint128_t *)ptr; + tmp2 = *(__uint128_t *)(ptr + 2); + tmp3 = *(__uint128_t *)(ptr + 4); + tmp4 = *(__uint128_t *)(ptr + 6); len -= 64; ptr += 8; @@ -85,7 +89,7 @@ unsigned int do_csum(const unsigned char *buff, int len) __uint128_t tmp; sum64 = accumulate(sum64, data); - tmp = READ_ONCE_NOCHECK(*(__uint128_t *)ptr); + tmp = *(__uint128_t *)ptr; len -= 16; ptr += 2; @@ -100,7 +104,7 @@ unsigned int do_csum(const unsigned char *buff, int len) } if (len > 0) { sum64 = accumulate(sum64, data); - data = READ_ONCE_NOCHECK(*ptr); + data = *ptr; len -= 8; } /* -- 2.26.2.645.ge9eca65c58-goog