Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4441845pxb; Mon, 21 Feb 2022 21:44:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3ikKuseOuPnYePXtAh8kZokjxEie27vnwLCV/QedI1HxgYDXo/1IP1eh1v+qDRTCKHmrL X-Received: by 2002:a05:6a00:1a56:b0:4c6:fe0c:2e27 with SMTP id h22-20020a056a001a5600b004c6fe0c2e27mr23286824pfv.65.1645508683816; Mon, 21 Feb 2022 21:44:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645508683; cv=none; d=google.com; s=arc-20160816; b=fWDcmwWtwShAFOpX0OiKmnL/LHExsGtyMMyL7NS9+m72gall8+BvmIH05DrV3+3n/s MjtwRT17QDPZHA4a2n5KjuSwrFvG+zGn9Dt2IlqaB8LsHWoe2cOV+gZoSO53dX5KrioC vHXQcX/b0O+7yV5swrBn2XK7oSXF8BJbCxz29/nbE0MBYw1bZtp0egigXJ4swAomm3mC y5i5DUbSAaFRKVltQySUFsEHIto6EYAB02UEN772I/ZC4G1aNca2n7OFFA/rRWbQrxtQ dKp3FKKXQF48Sd2Znmp+HUbG114Row0GQ/x/a+BSXn6/EqcKVvmebAa/ydlSnh3HVOKa xvvQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+jQnqoJgx0DFE3I1L3DOGdDXJTlVpT8FkHWNzeicNNU=; b=casPTZ67Q+1DTU1BcaYokTtP7tlYFW/KGCLFyHEZIH6w2ym2zG8OdWqAdxgSJza1Mk DKHPFBqyf5Hr0p++KMm/wbDzoNWJE0n04w+6cd06Lie/3H2BA4E67PzuDX/7NEwY3tjo T8PIDcW6dBD+5F1cpoxURxLpt9wHAPpoPQPtGCQpoVSOAnBEUDHiCJnZJY/dBJ3T9hb6 Y8im5HyntOdlWusrLIkHpY9+NYFGA0e5ZQybaJb9DD1WZEZesV/9b0Ubyuaq48a40PwL cdIYdqUGz5fjOUe/fkGY/Y9LpLGqwSqUnXViFAavlwdR+NIFtCK8Y/wrVy81Pfu3dWmp zyEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=azyi9D++; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q18si11556955pfu.353.2022.02.21.21.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:44:43 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=azyi9D++; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ACC9FCA0C8; Mon, 21 Feb 2022 21:10:07 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351478AbiBUJtc (ORCPT + 99 others); Mon, 21 Feb 2022 04:49:32 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244944AbiBUJoi (ORCPT ); Mon, 21 Feb 2022 04:44:38 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E4273F330; Mon, 21 Feb 2022 01:18:15 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F0F9260F1A; Mon, 21 Feb 2022 09:18:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC181C340E9; Mon, 21 Feb 2022 09:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435094; bh=n8SyEaw3FzEKtjVivgMYrGD1iFZv2h7DZWTikLxCuYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=azyi9D++1/u+7fGbALYMYsh4yBvGQ20DHvE8MG4SVkGa6HxlBjq0G2kqJuL/XaDF7 FTNoZHkTfq2j1NJAulfKAFXnvy+m12gfNerx3ifClY+QGbF+dHNOlSVntRXMG0j6/9 XuB1YVrQpXUjiKrN3lf+pO25FYv47jV2MuQfr0VE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hao Luo , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH 5.16 010/227] bpf/selftests: Test PTR_TO_RDONLY_MEM Date: Mon, 21 Feb 2022 09:47:09 +0100 Message-Id: <20220221084935.184705752@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Hao Luo commit 9497c458c10b049438ef6e6ddda898edbc3ec6a8 upstream. This test verifies that a ksym of non-struct can not be directly updated. Signed-off-by: Hao Luo Signed-off-by: Alexei Starovoitov Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20211217003152.48334-10-haoluo@google.com Cc: stable@vger.kernel.org # 5.16.x Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/bpf/prog_tests/ksyms_btf.c | 14 ++++ tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c | 29 ++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c --- a/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c +++ b/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c @@ -8,6 +8,7 @@ #include "test_ksyms_btf_null_check.skel.h" #include "test_ksyms_weak.skel.h" #include "test_ksyms_weak.lskel.h" +#include "test_ksyms_btf_write_check.skel.h" static int duration; @@ -137,6 +138,16 @@ cleanup: test_ksyms_weak_lskel__destroy(skel); } +static void test_write_check(void) +{ + struct test_ksyms_btf_write_check *skel; + + skel = test_ksyms_btf_write_check__open_and_load(); + ASSERT_ERR_PTR(skel, "unexpected load of a prog writing to ksym memory\n"); + + test_ksyms_btf_write_check__destroy(skel); +} + void test_ksyms_btf(void) { int percpu_datasec; @@ -167,4 +178,7 @@ void test_ksyms_btf(void) if (test__start_subtest("weak_ksyms_lskel")) test_weak_syms_lskel(); + + if (test__start_subtest("write_check")) + test_write_check(); } --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2021 Google */ + +#include "vmlinux.h" + +#include + +extern const int bpf_prog_active __ksym; /* int type global var. */ + +SEC("raw_tp/sys_enter") +int handler(const void *ctx) +{ + int *active; + __u32 cpu; + + cpu = bpf_get_smp_processor_id(); + active = (int *)bpf_per_cpu_ptr(&bpf_prog_active, cpu); + if (active) { + /* Kernel memory obtained from bpf_{per,this}_cpu_ptr + * is read-only, should _not_ pass verification. + */ + /* WRITE_ONCE */ + *(volatile int *)active = -1; + } + + return 0; +} + +char _license[] SEC("license") = "GPL";