From patchwork Tue Nov 8 19:52:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francis Laniel X-Patchwork-Id: 17198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2919859wru; Tue, 8 Nov 2022 12:01:32 -0800 (PST) X-Google-Smtp-Source: AMsMyM5bia1nXlz3CrHkwZPWTwNrO1tJnsG9eushXC9pOTp7wqlSy31aAsFhEvYo4I4tQ1DaGWPr X-Received: by 2002:a05:6402:294a:b0:461:b661:d903 with SMTP id ed10-20020a056402294a00b00461b661d903mr56839247edb.407.1667937692825; Tue, 08 Nov 2022 12:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667937692; cv=none; d=google.com; s=arc-20160816; b=FqKwi+ECh3En3Sp4kux1xi4dLJXFnEK/qQesO04pKZTVDsERSMpYV0UiWD4dMRMafx zk1a/Kq1swSZLnsdqGIvc17etty7VoxU0BUC2EBIUrIg7vzfFfI65gI0Na3giN2bzu6q JeF5ozOisbi26vuMkBa0YsQfkpqAL2vfqHQJuoLP9VJaRAKfTgBzel9uGLia7384n6e3 64/1bX5BpqdVnkUJgTEf1RC8kiiLqmlk1vlwv7fXFu408CnB25CAB5Z1Z3bb/DCMPgJA PWF4wvGhUBwj2Ew1rpQElrxUgbGaeJpqIFhIofzJSxN0viVz1QOZzzZZNnO3AX3SwtsE wxVA== 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=lfm7BTt/ROEPRbGDPE3vy0AJuoRZ1875JpNL6uMTfxU=; b=ISesvXy4GFYP9RKZAed2RjKaDsw5lKlgavRbcWR173n2y655N60BpwPB0DhAgSDaPo Sa4dGmWdsGQujp15kkaUjJW3j575w8BDsxrTh5ljQ8XzHzfpZcFx9xMHTXEFpVPp0dlp VLgGl7dXV2uz8S0KTOqjwM2IY1gqesIFfReWvPMOz977IoXwu+izeoczhiaQB3ODObOS XUy55V+JOqh0F3gXA8rP1pyZxdSh8JySb9DMG05grIWB06pSN6ygZK9SAa9U+rO+3lZ/ E4PFiA503KdkSz7HtgJ/QMZGQ5490d1cv/0i/YvitvgfI/0dFonhCKUKcfX1VMfUu25n p23g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Z6y0+aMF; 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 d20-20020aa7d694000000b0045d25cf222csi12616551edr.362.2022.11.08.12.01.08; Tue, 08 Nov 2022 12:01:32 -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=Z6y0+aMF; 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 S229780AbiKHTxJ (ORCPT + 99 others); Tue, 8 Nov 2022 14:53:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229821AbiKHTxD (ORCPT ); Tue, 8 Nov 2022 14:53:03 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DA8E17057F; Tue, 8 Nov 2022 11:53:00 -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 E1FAA20B9F80; Tue, 8 Nov 2022 11:52:56 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E1FAA20B9F80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667937180; bh=lfm7BTt/ROEPRbGDPE3vy0AJuoRZ1875JpNL6uMTfxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z6y0+aMF7SVBf0gFi1ICcf5FraX76ZRSz2ubkXhXtcPbw166bRHHw/TGxDIGh3txN SAQDO1pwq8hj3/PXrWZn3Uct6WoppsDGUInreNeOK8hBSmRrPvz9wrDBWvS0DhviDY 94IRSMcmuNH0IJPuoG0eAXnRTi0XMLf+eQc/qjrE= From: Francis Laniel To: linux-kernel@vger.kernel.org Cc: Alban Crequy , Alban Crequy , Francis Laniel , Andrew Morton , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , linux-mm@kvack.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH v1 2/2] selftests: bpf: add a test when bpf_probe_read_kernel_str() returns EFAULT Date: Tue, 8 Nov 2022 20:52:07 +0100 Message-Id: <20221108195211.214025-3-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 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?1748959434060045672?= X-GMAIL-MSGID: =?utf-8?q?1748959434060045672?= From: Alban Crequy This commit tests previous fix of bpf_probe_read_kernel_str(). Signed-off-by: Alban Crequy Signed-off-by: Francis Laniel Acked-by: Yonghong Song --- tools/testing/selftests/bpf/prog_tests/varlen.c | 7 +++++++ tools/testing/selftests/bpf/progs/test_varlen.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/varlen.c b/tools/testing/selftests/bpf/prog_tests/varlen.c index dd324b4933db..4d7056f8f177 100644 --- a/tools/testing/selftests/bpf/prog_tests/varlen.c +++ b/tools/testing/selftests/bpf/prog_tests/varlen.c @@ -63,6 +63,13 @@ void test_varlen(void) CHECK_VAL(data->total4, size1 + size2); CHECK(memcmp(data->payload4, exp_str, size1 + size2), "content_check", "doesn't match!\n"); + + CHECK_VAL(bss->ret_bad_read, -EFAULT); + CHECK_VAL(data->payload_bad[0], 0x42); + CHECK_VAL(data->payload_bad[1], 0x42); + CHECK_VAL(data->payload_bad[2], 0); + CHECK_VAL(data->payload_bad[3], 0x42); + CHECK_VAL(data->payload_bad[4], 0x42); cleanup: test_varlen__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/test_varlen.c b/tools/testing/selftests/bpf/progs/test_varlen.c index 3987ff174f1f..20eb7d422c41 100644 --- a/tools/testing/selftests/bpf/progs/test_varlen.c +++ b/tools/testing/selftests/bpf/progs/test_varlen.c @@ -19,6 +19,7 @@ __u64 payload1_len1 = 0; __u64 payload1_len2 = 0; __u64 total1 = 0; char payload1[MAX_LEN + MAX_LEN] = {}; +__u64 ret_bad_read = 0; /* .data */ int payload2_len1 = -1; @@ -36,6 +37,8 @@ int payload4_len2 = -1; int total4= -1; char payload4[MAX_LEN + MAX_LEN] = { 1 }; +char payload_bad[5] = { 0x42, 0x42, 0x42, 0x42, 0x42 }; + SEC("raw_tp/sys_enter") int handler64_unsigned(void *regs) { @@ -61,6 +64,8 @@ int handler64_unsigned(void *regs) total1 = payload - (void *)payload1; + ret_bad_read = bpf_probe_read_kernel_str(payload_bad + 2, 1, (void *) -1); + return 0; }