Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3785756ybi; Mon, 29 Jul 2019 12:35:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjObOwP5UVSgYIRpj5/5Vchks9t16tvPCuA/gbkAdaaOX6x7JZ0LYZYrq4yDiVNalHDb2e X-Received: by 2002:a17:90a:2ec1:: with SMTP id h1mr114353565pjs.119.1564428913458; Mon, 29 Jul 2019 12:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428913; cv=none; d=google.com; s=arc-20160816; b=b5T0cqJeb1Hm3Qan9INyiJurHoTtNDetxxPifV7807G9pcFlneCO3YoJAu7uwFcrj7 Teund+Dz0IKWPbOunmwcSJ2TKH25vcGGvwvCAb9ARBMi+X+2edoMK+EiYeWtIpcTR4zR NY3mtJkYfza2W6TsgvDPLdybdBdgB5BEH2fImpg8yJ3sfpvdL3HaQ7vA57dKy+c0moHh vEGR9mUsZIL3x3UbT/QygyOHxizov50opTBfjlWCBtH7esl5TLHEhqAiHafzDw2SNb5b 8x3kcocygBlUIzY+OUNijFZeW1BI6+AV1y9y6cnLce+qakPx/USsvhk+Vbo9zOcluXY6 Zraw== 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=4PGHKkP75MmhvrumvNB/LI4jpcnsSw16bA3K1xpBgKU=; b=j6VPeoC1BfkR6UegDX5ECGcsdzYfMI0hfGbYVnUi7IOld7Fjf3Lbvh6hf/YjmUXKlO +7TTg4SXhqLw9IJk1Lj8bWifQ6da6ziowtqwd8luhykv01cafhgrp7c+1HXhSiPf2JVF pkqiZ6frtnnezgmcBbZzrZg0gAs+lev59OebIlNyTAJFg3VnJ3gUf4MEHyh9h88zS3GW xZPLRzSa/dp5WYh5j0T2Snp5Ib337tk6hPOnMz35JI7aIi4YiMzsG0KeaYWmtJJIGEEP nZmZJsCBxtSiEltLAbIuZjXAiLpaiHy96w1lXE7mbdc8Baph32aPET//CRL0/MaN5p6Y ll8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MPH+yUZY; 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 x13si27714518plr.111.2019.07.29.12.34.58; Mon, 29 Jul 2019 12:35:13 -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=MPH+yUZY; 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 S1730289AbfG2Tcz (ORCPT + 99 others); Mon, 29 Jul 2019 15:32:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:46634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729378AbfG2Tcx (ORCPT ); Mon, 29 Jul 2019 15:32:53 -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 BDE0C21655; Mon, 29 Jul 2019 19:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428772; bh=mlkORtITjZxHISIqZaxJ4GJmJwbK0kDZ++DsPoE+vRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MPH+yUZYzXCwyeMWjL2OqGxrdIxhdN/KB82Hww3ZmfMzLNt69Oitln5Gek+1JIMj7 UKAEYLT/MV4Q7KBDbbFiIiCCeJr6dRhI7aeCyuUjAgtrPz3jwysN4cflN/SSlZ+T+d mxBho6p/7APGdwxwvVCiF0d0f1aGJls3XPYKY+x8= 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 180/293] lib/strscpy: Shut up KASAN false-positives in strscpy() Date: Mon, 29 Jul 2019 21:21:11 +0200 Message-Id: <20190729190838.294287303@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 1a3241ff10d038ecd096d03380327f2a0b5840a6 ] strscpy() performs the word-at-a-time optimistic reads. So it may may access the memory past the end of the object, which is perfectly fine since strscpy() doesn't use that (past-the-end) data and makes sure the optimistic read won't cross a page boundary. Use new read_word_at_a_time() to shut up the KASAN. Note that this potentially could hide some bugs. In example bellow, stscpy() will copy more than we should (1-3 extra uninitialized bytes): char dst[8]; char *src; src = kmalloc(5, GFP_KERNEL); memset(src, 0xff, 5); strscpy(dst, src, 8); Signed-off-by: Andrey Ryabinin Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- lib/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/string.c b/lib/string.c index 1530643edf00..33befc6ba3fa 100644 --- a/lib/string.c +++ b/lib/string.c @@ -203,7 +203,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count) while (max >= sizeof(unsigned long)) { unsigned long c, data; - c = *(unsigned long *)(src+res); + c = read_word_at_a_time(src+res); if (has_zero(c, &data, &constants)) { data = prep_zero_mask(c, data, &constants); data = create_zero_mask(data); -- 2.20.1