Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4120709rwb; Tue, 8 Nov 2022 12:22:54 -0800 (PST) X-Google-Smtp-Source: AMsMyM5MJAlvE6hAPfzmakefxWFMrYRwD4UdN9ZHxk+wGeXQD7KNovcZuKc2KuKZqwUUUa2Z6My6 X-Received: by 2002:a17:90b:388f:b0:215:f01f:7975 with SMTP id mu15-20020a17090b388f00b00215f01f7975mr31092837pjb.53.1667938974431; Tue, 08 Nov 2022 12:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667938974; cv=none; d=google.com; s=arc-20160816; b=DKiJo69nkA/2OKgyli36OhiQfYeWguk8wFL6dEksJVcOaX57EgMC4mZal60zCpjiNl O/tuCP/NiEOYy05D+L2hcIFqq8RoEnKfh96WPJ97/oFT3UKHBY5TLqYdV6RRbPfTvgue oKTVtXRjjX1APRvhTyRZ8i/DUASlVKzGoBAMk4zyYfMke64ZCSomwnT42GeLvudWzdc+ bIIjwoOlnivlAjalfGdNC4YqQspLW0YKMl5jmkA/gzt00DeHnELOsKgtkQgwe8gpQEqB 2ToT0B9Tfilskw41pVNGtqZHOLNv8xBG7fk2Ftb31qXyMbq7R2KqUJ6M2cIjnX6ltWz2 gVfA== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=t36xpm43qmLMEEXsLNHAnvSSN1fHn9/wxZfzoHQm4H4=; b=yP6go+K4zjbCsi3SM6GDHDJIUHVj4M1x5U/nr9LSEghGZObZ/K20k/DnM67dxGwdxm L157ly+pq7cinu0kRcj39QOIshuLw13UpsgzkOmVyPbK06e3GJU/j+dguYS3g/ZlemWR ObL0MxtUhxTLf7nLA3IKK5lcThpicoEbaa1r4PVupwI+u/Smr7NsX1JMmReRs5iEaGfp 07oqQC0JDL0sy2I2ND2wdFV3HjPjXd+ZZg1QdiBkzbl7bLMewQg1amh6S2azehwQvOzM Xb/C7oy9mRZ2UJgIci6RIJNxzvTBoHGt8f/x837PY0FGy6LO5gPify/tY/9Z8awxmefU hViA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=jLCsIjth; 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 qe5-20020a17090b4f8500b00217cdc4b09csi10118192pjb.3.2022.11.08.12.22.38; Tue, 08 Nov 2022 12:22:54 -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=jLCsIjth; 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 S229734AbiKHTws (ORCPT + 91 others); Tue, 8 Nov 2022 14:52:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbiKHTwq (ORCPT ); Tue, 8 Nov 2022 14:52:46 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 28AFE65E6C; Tue, 8 Nov 2022 11:52:46 -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 C085920B9F80; Tue, 8 Nov 2022 11:52:41 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C085920B9F80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667937165; bh=t36xpm43qmLMEEXsLNHAnvSSN1fHn9/wxZfzoHQm4H4=; h=From:To:Cc:Subject:Date:From; b=jLCsIjthGu7d4DRVQ1TB1mUyc8RViDwSi21b47OLSSvYIUrMF88SfAwGaztkyEF3C xlvS4iAXH5LWDmr/3H9Zbx7JkO/Pk1Yeyq1fUOTIm7LLa854J4p4OteAabn/akYUnt ut53qaPtrmCoJUQjxqsEupHjc9whVtslOLdkiBus= From: Francis Laniel To: linux-kernel@vger.kernel.org Cc: 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 , Alban Crequy , linux-mm@kvack.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH v1 0/2] Fix offset when fault occurs in strncpy_from_kernel_nofault() Date: Tue, 8 Nov 2022 20:52:05 +0100 Message-Id: <20221108195211.214025-1-flaniel@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 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 Hi. First of all, I hope you are fine and the same for your relatives. This contribution fixes a bug where the byte before the destination address can be reset when a page fault occurs in strncpy_from_kernel_nofault() while copying the first byte from the source address. This bug leaded to kernel panic if a pointer containing the modified address is dereferenced as the pointer does not contain a correct addresss. To fix this bug, we simply reset the current destination byte in a case of a page fault. The proposed fix was tested and validated inside a VM: root@vm-amd64:~# ./share/linux/tools/testing/selftests/bpf/test_progs --name varlen ... #222 varlen:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED Without the patch, the test will fail: root@vm-amd64:~# ./share/linux/tools/testing/selftests/bpf/test_progs --name varlen ... #222 varlen:FAIL Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED If you see any way to improve this contribution, feel free to share. Alban Crequy (2): maccess: fix writing offset in case of fault in strncpy_from_kernel_nofault() selftests: bpf: add a test when bpf_probe_read_kernel_str() returns EFAULT mm/maccess.c | 2 +- tools/testing/selftests/bpf/prog_tests/varlen.c | 7 +++++++ tools/testing/selftests/bpf/progs/test_varlen.c | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) Best regards and thank you in advance. -- 2.25.1