Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1188759ybi; Fri, 2 Aug 2019 10:48:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4yFPuOD+gOnG6L7oXR1J+nJIi6eSazzpY1o44AayLU9HzfTjQM9E+cxxvRcGP9JMp98V0 X-Received: by 2002:aa7:93a8:: with SMTP id x8mr62811449pff.49.1564768093379; Fri, 02 Aug 2019 10:48:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564768093; cv=none; d=google.com; s=arc-20160816; b=oW47mE8vW6JsJyYqv6dN6GL1KmO51P+hTNIOOb+pFrPIyT6XD+awRGeKBdsMla+6k+ eQlDP2/RN6/QMvkmyxqXpDMES05Vh36GEr6KC+dd6tLQs9E8mR5VRHBomtF6Ia958mwL kMTtiPQnsDTS++PUOnLuTVyfDQBrn8WgehLWHAa7O5H+2ZdaRodJsPkWHFkB7cVT8+NO tJnMHj4iZZiXxv7XhTKLPF9pFlx7imNxBjyKRyJMLwbUM7tSNTqnoq41loivnMWclbrS 83nlBYNv8Y+eSJuqIlbUv4pOOE7tKiuIk6xIAFGHJbJjzQQOcBTv9ij5pjdXm2eKetEZ 2z7g== 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=EhOBvjr74NIDCcuoEPN9nD0C8e3/mH09nITk15AhnJM=; b=aCesrv4DbnN59DxLavf/phEjbI+ja1xPYZoFrQM5cjYFgHwL1EeCCBLFtsp7Bay6OG kmNXOVIqMbNWQksDBcvNlfIJm8b3a5Jc2QHJqoteLEEXCMlAOP+WopEOzsHWyBM1ZIMB 1XDG6CFFsVRHk++hghOQtZwXZeGl1qoPry2oagjMOPBwniuqZ286MCxPqif49BMSdxUT eSQpcQJUnKyJucatNMmHxhsWIz1p1V/AJWbRCkbLAjjawmc9bQ5D9DrRnlD9+JRApcN/ Se/p+nyABDAV8OccO/F9Eqab23+4nKLkiJuuAmA4bxL89lFIBSJ5PNEjnUAuX7Gt+dlz KVGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J5r1jH9f; 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 a10si39451899pff.277.2019.08.02.10.47.58; Fri, 02 Aug 2019 10:48: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=J5r1jH9f; 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 S2405670AbfHBJu1 (ORCPT + 99 others); Fri, 2 Aug 2019 05:50:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:49422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391942AbfHBJpi (ORCPT ); Fri, 2 Aug 2019 05:45:38 -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 86C2C206A2; Fri, 2 Aug 2019 09:45:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564739137; bh=mIUD1UpAOTEIUTEwksaaIW6EKVZYhNbc1zhEQXcWRns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J5r1jH9frJgid6CO7xmzTH568bkJB4s8QrRfYLYI6gRyDJ+mKvCAS+W52hurI/veL XeoCq8lqsHUgtUy22qM/IbQV/AiSPHykBUsWeyEEheHfwnfxqLvP4YeSL/DN0ngTYb jqeb5oUy4WzYI1TMlkSTmfspZp1n/zhx36m11I/A= 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.9 127/223] lib/strscpy: Shut up KASAN false-positives in strscpy() Date: Fri, 2 Aug 2019 11:35:52 +0200 Message-Id: <20190802092247.281302082@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092238.692035242@linuxfoundation.org> References: <20190802092238.692035242@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 1cd9757291b1..8f1a2a04e22f 100644 --- a/lib/string.c +++ b/lib/string.c @@ -202,7 +202,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