From patchwork Tue Nov 8 19:52:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francis Laniel X-Patchwork-Id: 1350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2918761wru; Tue, 8 Nov 2022 11:59:18 -0800 (PST) X-Google-Smtp-Source: AMsMyM6SPcg+bzYKhs6rAYQ09wLhu2/Dnu7DzPQc3YA8DnGwL/nP9BlpM80PfMgGHG/dRqgmQWOe X-Received: by 2002:aa7:de9a:0:b0:44d:8191:44c5 with SMTP id j26-20020aa7de9a000000b0044d819144c5mr56105366edv.232.1667937558034; Tue, 08 Nov 2022 11:59:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667937558; cv=none; d=google.com; s=arc-20160816; b=w4c0x8vUyokQSjqHb8VQlUKF6Bcl1aV60Sjub+wSq5+wMOv7hDlufrSxmBEpdBi6lA wSYVs7jdGLxxvVVd1oYqRmZ5Wrxn+y+G619El2OReVOoqiTeETRSf4x6jEtxlt7X2qO/ cwBwHiLiGiaTYq0MyLabw98tKvSiHFoLH4Z0yp3JZP8gn1JwAuuqA7NhtZCpwr5J+kdc ddmVNDhkxbwfW0Fr8tRYqpvM7HeP1U24MxPTdX/SCSluUFC7ggoW5eHKe6hH5yCDYRGI /6bzZA4XN5cIniLOk46QLZvD6Ohe2pajXFMaHxmTZ9ziohGi/4uDpOz8mJyky5dbcmB1 TWiw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t5-20020a056402240500b00458b71488bdsi13497171eda.388.2022.11.08.11.58.53; Tue, 08 Nov 2022 11:59:18 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748959293301938976?= X-GMAIL-MSGID: =?utf-8?q?1748959293301938976?= 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