Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4145830rwb; Tue, 8 Nov 2022 12:47:16 -0800 (PST) X-Google-Smtp-Source: AMsMyM4gDztMBXVQnsUmYuRr5odYGCli9koQOinMo29kypsWafaYnblsXfdlWWnSWnMMvkXMzuSU X-Received: by 2002:a17:906:9c82:b0:781:5752:4f2b with SMTP id fj2-20020a1709069c8200b0078157524f2bmr53399291ejc.561.1667940436613; Tue, 08 Nov 2022 12:47:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667940436; cv=none; d=google.com; s=arc-20160816; b=AdHA7P7OB5tKOC4wPlqllaYvmq0hxqZg3hkIb+LWcq8QQTSWCQAtMt5HaQew6ggfej p3xxKyQI4ZRmrq1KZDAGo1nm/mOikrXUKySs9W+dQJ0TT+8orTe98evJq3i5SiWHiiO6 qom7Tx++LfF+/Nv4M00Pb0REvbRu47Homerv9NCXyikvJ9PpchtZVX0dTjX3W+buafyz y6bHC9mI5Hm+VYBAGsjfVCRj2X9HMWiwyk8dc2kOjrz0uo+YuJAvtutkCnM9Iq1vERKB NXt/T+mDCpMOrjIVat5bmSCSIHxZxSwExDaHohw87djd5OSVwcPl6AH9KiJ/33V91zRv vu0w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=aV1rbRcoT8elrIFvcswWnTb6/2G/r5XMttMTu6HgEWE=; b=Fx8NROwRQeKRGafw4Usf8hfSOAX1M3mW/NhD8uKuIH9her+AmT5w1prIyicY6LRGCB 7Vw1NZHWVVyOvagzzgQFQ6OPPReDmd80XsVHM4VgWF609+v7Afl9v4vjc5OuWSTztOR4 jy7OWFzzYySWys2fokZYHAgXwWGnVDXg4BMoEHnboCrLIfzgt4q9B9PNRJa0UTFi7OSX OmFSkrzjZ5yg0x7b31wxmfBh91Qla+q05aD9NwR18tW4f6u7pvm5SiAgBoQAz74GxUgD MUoeUcWogwnlM6zIxCfuhjWAh8bM1d2/AdtELwYeTapBmDNmpRaCyOdVG57IGv51WJ2O zbLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=rNA91l5N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb7-20020a1709077e8700b0078daf101aa1si14056312ejc.813.2022.11.08.12.46.55; Tue, 08 Nov 2022 12:47:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=rNA91l5N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229798AbiKHTw7 (ORCPT + 91 others); Tue, 8 Nov 2022 14:52:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbiKHTwz (ORCPT ); Tue, 8 Nov 2022 14:52:55 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 120F67057F; Tue, 8 Nov 2022 11:52:53 -0800 (PST) Received: from pwmachine.numericable.fr (85-170-25-210.rev.numericable.fr [85.170.25.210]) by linux.microsoft.com (Postfix) with ESMTPSA id 100FB20B9F81; Tue, 8 Nov 2022 11:52:48 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 100FB20B9F81 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667937172; bh=aV1rbRcoT8elrIFvcswWnTb6/2G/r5XMttMTu6HgEWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rNA91l5NyZRNSqXKVvrOFtfVRTnClAzSHuIB0O3Egn/SS6gqzKq3v7ZKmQBR/jCpy mgmLPKxd59MfGA18pKlh2CT9mEP1YYypTZe/p83XNEV2xlMr6zqKrK9/5hjRy1klb0 USlF3Ft41AuAO7/QWRSjFyu3ezjq7SIq6BQwfc2U= From: Francis Laniel To: linux-kernel@vger.kernel.org Cc: Alban Crequy , Alban Crequy , Francis Laniel , Andrew Morton , Andrii Nakryiko , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , linux-mm@kvack.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH v1 1/2] maccess: fix writing offset in case of fault in strncpy_from_kernel_nofault() Date: Tue, 8 Nov 2022 20:52:06 +0100 Message-Id: <20221108195211.214025-2-flaniel@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221108195211.214025-1-flaniel@linux.microsoft.com> References: <20221108195211.214025-1-flaniel@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alban Crequy If a page fault occurs while copying the first byte, this function resets one byte before dst. As a consequence, an address could be modified and leaded to kernel crashes if case the modified address was accessed later. Signed-off-by: Alban Crequy Tested-by: Francis Laniel --- mm/maccess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/maccess.c b/mm/maccess.c index 5f4d240f67ec..074f6b086671 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -97,7 +97,7 @@ long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count) return src - unsafe_addr; Efault: pagefault_enable(); - dst[-1] = '\0'; + dst[0] = '\0'; return -EFAULT; } -- 2.25.1