Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2408547pxa; Fri, 7 Aug 2020 10:21:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9qapUuaOKITHH7WfYHPqbYp2NGJintl/i/41DTZF/trwKcsnjzqpUP1gaKwTNwbnWkvlM X-Received: by 2002:a05:6402:44e:: with SMTP id p14mr2381902edw.1.1596820910932; Fri, 07 Aug 2020 10:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596820910; cv=none; d=google.com; s=arc-20160816; b=KXXe/dGNcywZ94/1shGfMN8vOaQ3ntD/h+GPi8LpWTRp6YzxbEdhRHpNGE4FubgiKy 9tnLQHSOd0Uib9mGY+9vTnP8NZzQ+3rrnonW3xIFgtn5cRpVNjolP83GO7HY3/26N4Nq fJsm+b48junnkS08oyi5Cj/W4py27nvkoJlLhJ2FK5lHjolntfC9VqdHfu2mA9HlahMf VO0fo7Sc0yif9az4dK9f2LqvufHEo3mSQK7eHZttaf78RG7rQ/38ZZndGAsYcksgLxCi Y/7oyKsS7Q+5YNndzIAQ/c/HPTbBUMDpRSH/J2G5065W/7c6YknjJ4ccry+lTCiisdJv NArw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ukHtyEG90H2bGWPQaxA9oxldYLhvq6WKTnL6jXGaoCY=; b=mxcfWilj9GgAEd64q6tCTzfIatdEvvLIYp3RqFabasH99ilzlICgXwd0a7kdrYJJ6Z JgiH1pNA30UVSbKkz/4CEDWw8ZrnjN8FlWRPiQ+EDvyU/OeV/zfCIgP+VyxbT/0VK9Jb UBuaA2YmomKOzr0lR9lLSrvqINR8i6P5OiJtHxcOedwp2TbCyddf1O3cE5W1HSYZhNnA CTSJLVzP2Ur2Kte3VKKQW45wmMiqAK7twAI7g/qra1zYUivptkxFLphuffQzm+3cGTHf CXV5Z77IeBTXQuk/maC+EO+N5v5zwwMF2rHiqTFd2Kz4IA+j4+sZ6VGt1KdUB85h47VK 2QXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q2si5793608edn.377.2020.08.07.10.21.28; Fri, 07 Aug 2020 10:21:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726094AbgHGRUd (ORCPT + 99 others); Fri, 7 Aug 2020 13:20:33 -0400 Received: from foss.arm.com ([217.140.110.172]:60146 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbgHGRUc (ORCPT ); Fri, 7 Aug 2020 13:20:32 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7C8641FB; Fri, 7 Aug 2020 10:20:31 -0700 (PDT) Received: from net-arm-thunderx2-02.shanghai.arm.com (net-arm-thunderx2-02.shanghai.arm.com [10.169.210.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A05A13F7D7; Fri, 7 Aug 2020 10:20:28 -0700 (PDT) From: Jianlin Lv To: bpf@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, Jianlin.Lv@arm.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH bpf-next] bpf: fix segmentation fault of test_progs Date: Sat, 8 Aug 2020 01:20:16 +0800 Message-Id: <20200807172016.150952-1-Jianlin.Lv@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200731061600.18344-1-Jianlin.Lv@arm.com> References: <20200731061600.18344-1-Jianlin.Lv@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org test_progs reports the segmentation fault as below $ sudo ./test_progs -t mmap --verbose test_mmap:PASS:skel_open_and_load 0 nsec ...... test_mmap:PASS:adv_mmap1 0 nsec test_mmap:PASS:adv_mmap2 0 nsec test_mmap:PASS:adv_mmap3 0 nsec test_mmap:PASS:adv_mmap4 0 nsec Segmentation fault This issue was triggered because mmap() and munmap() used inconsistent length parameters; mmap() creates a new mapping of 3*page_size, but the length parameter set in the subsequent re-map and munmap() functions is 4*page_size; this leads to the destruction of the process space. Another issue is that when unmap the second page fails, the length parameter to delete tmp1 mappings should be 3*page_size. Signed-off-by: Jianlin Lv --- tools/testing/selftests/bpf/prog_tests/mmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mmap.c b/tools/testing/selftests/bpf/prog_tests/mmap.c index 43d0b5578f46..2070cfe19cac 100644 --- a/tools/testing/selftests/bpf/prog_tests/mmap.c +++ b/tools/testing/selftests/bpf/prog_tests/mmap.c @@ -192,7 +192,7 @@ void test_mmap(void) /* unmap second page: pages 1, 3 mapped */ err = munmap(tmp1 + page_size, page_size); if (CHECK(err, "adv_mmap2", "errno %d\n", errno)) { - munmap(tmp1, map_sz); + munmap(tmp1, 3 * page_size); goto cleanup; } @@ -207,8 +207,8 @@ void test_mmap(void) CHECK(tmp1 + page_size != tmp2, "adv_mmap4", "tmp1: %p, tmp2: %p\n", tmp1, tmp2); - /* re-map all 4 pages */ - tmp2 = mmap(tmp1, 4 * page_size, PROT_READ, MAP_SHARED | MAP_FIXED, + /* re-map all 3 pages */ + tmp2 = mmap(tmp1, 3 * page_size, PROT_READ, MAP_SHARED | MAP_FIXED, data_map_fd, 0); if (CHECK(tmp2 == MAP_FAILED, "adv_mmap5", "errno %d\n", errno)) { munmap(tmp1, 3 * page_size); /* unmap page 1 */ @@ -226,7 +226,7 @@ void test_mmap(void) CHECK_FAIL(map_data->val[2] != 321); CHECK_FAIL(map_data->val[far] != 3 * 321); - munmap(tmp2, 4 * page_size); + munmap(tmp2, 3 * page_size); /* map all 4 pages, but with pg_off=1 page, should fail */ tmp1 = mmap(NULL, 4 * page_size, PROT_READ, MAP_SHARED | MAP_FIXED, -- 2.17.1