Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8068498rwr; Wed, 10 May 2023 17:32:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ745VqVnd4zal1Og9I4MAFiwexN5S9TBaN7ax62ZSe4AXQMkaqG+6F/FOxDJ/XJJNmuP7V6 X-Received: by 2002:a17:903:6ce:b0:1a6:3799:ec2a with SMTP id kj14-20020a17090306ce00b001a63799ec2amr16846902plb.35.1683765165053; Wed, 10 May 2023 17:32:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683765165; cv=pass; d=google.com; s=arc-20160816; b=aTiHu/FS4Q+Y7VcSTLhf+r1cPTgGlxw7UFtok1kGhQ+Fj1LsO1SJTaN+H2NiAvl3mF 6x/smzUIO06pzJPy2UPYteMHgTu/RXnhhqLxfVJSpef69WaEtBgzCDOyTUCQluMv2qPR +ArpV7gSsk0hN0qI3W9/c3f2Mg1v/Co30S9qm8MPj8PxiSyCfQjX/qi6cZtKUBdUK0wS yOtAh4682UN1U4CAezC0hsRvRdBahOjQe4LtWItfRFTpf3bJwFTK1XgOf/qasRixvIJa fsYaRJbh+NlpFaGe6M4barpPZnweBMWXxxV2NO/d4VjkDGmDdsFUlwj8PnJRGEfIrZQC a4EA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:references:cc:to:from:content-language:subject :user-agent:date:message-id:dkim-signature; bh=CHFK+HHdIkINolpjdjOvyqghmFJUHGE7cISCQ/xt1Ik=; b=ZIKhVUAAlE/usAaxjqdEsWyA7tJ/RhMfRyzAYG5u74KF61n6QkKr4S89QdnS1Yqtt7 MefA/nULW437fS7WyyhLjWjdzUqHxq+AUpW0yRHMzx/M7O1TlHjP+0IEQs1zSDExho7B HWO18mTNKWmj+o5+nFfutJhnxncsphBEwWzN+nn89RVFEsdcyIJOIgDr4sKHLgfZ5laH R4oM88fBLZogpXcr0EPUU7kmudKAvkSBLzr5lQrpUNCmyYvBywGdiIvjmq/Tp55lZZbf g6lWp5aLELDxTPAyTH/ewahn4B4/61Zoax+qt6iiiA8BfS5px2f/f210IdLtY/6vq5MN Oeug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@meta.com header.s=s2048-2021-q4 header.b=T30+Adc6; arc=pass (i=1 spf=pass spfdomain=meta.com dkim=pass dkdomain=meta.com dmarc=pass fromdomain=meta.com); 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=REJECT sp=REJECT dis=NONE) header.from=meta.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a17090a67ce00b00244a3e7bc69si19449232pjm.38.2023.05.10.17.32.30; Wed, 10 May 2023 17:32:45 -0700 (PDT) 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=@meta.com header.s=s2048-2021-q4 header.b=T30+Adc6; arc=pass (i=1 spf=pass spfdomain=meta.com dkim=pass dkdomain=meta.com dmarc=pass fromdomain=meta.com); 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=REJECT sp=REJECT dis=NONE) header.from=meta.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236928AbjEJXzP (ORCPT + 99 others); Wed, 10 May 2023 19:55:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjEJXzL (ORCPT ); Wed, 10 May 2023 19:55:11 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 323CE30D1; Wed, 10 May 2023 16:55:10 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34AHqITA022410; Wed, 10 May 2023 16:54:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=message-id : date : subject : from : to : cc : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=s2048-2021-q4; bh=CHFK+HHdIkINolpjdjOvyqghmFJUHGE7cISCQ/xt1Ik=; b=T30+Adc6bz+cI0ieEMJIqdCwPReon33UzZ77VEQ8BFLWyUmaNFsSFwS7WuxCyE/hVyv6 tNVjAkwCbf/k87Pue6ZI9wuKrRDtPY1OBrh62f5ya6JYmh024tzX8HduSdP54sN7GyzE rDvFdxVpM7giiM96tgfF1hyOgOqBD0k/hS4k2sd2xSe8gwCpW7WwXe5gVR40CUhCtAHm Pw8d5Lao8YKhyylcg3kz1MeVym6ktJHRt3goHLr0b0+RS8qohmwlun6DOPz9hQWwBZm+ L6h1umMfKA7HiVHu/x4Z3qBLsS8PTuc8C3Me0pArZXNLCE5MU3CumSCUCO5+zNJh/Ush Bw== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2172.outbound.protection.outlook.com [104.47.59.172]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3qgeqjayw9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 16:54:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hQMKf6fr46NQxPspcAY830EMkeOmaT6Sj9p1s35W/0jJmq2loN1votyOUaJJDAUaINcX2EFVMWQQJ/1Y4UPo2FZSormGfj4iEhepl4RdrPUNy62Qj0B8ssG6Wzb0ewTTrIE0ww02B++SinmUO1gNSoKN2uoEM5RsmwUwAFocvnjfFkj6bJrsz+eylk7fCsNGEENKGVvBSi62WP9M/6IOZB2O3+ZwsjmHTp9O6YOWAkrKmPbrbCPfjVybRYGEcX1DugYP9QexI7qHGgiKDG7U22/mecQ6QS6tFpTMJK1SIE27dhnyIfEbEVMzLeOlR+H9+GH0CkZ90QuI8SN759p3rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CHFK+HHdIkINolpjdjOvyqghmFJUHGE7cISCQ/xt1Ik=; b=GTrh6aE/lEiyTrZ8MXT08u983UL/1N5wL5YhQrWH/kLlg64EibQmL9jMSX5fjQCeGpL6WQ60HqnvvSIu58xVXtBNXlgRRddN6IXTfNTftiMwU1J79oSTX+lqrsFxp9SEljWAUcKz5/BR2kpiG38hF5Bfq/Y3UtV5ek/Jm1zNSoJyfqVwv+tQ4EPhaoKHgiMUPOZRbkhpCmt9JIN0u62BZ7RtW/0OhAhAtgv2xV2xP/ajsbTW+aAv9JWNxp4ifIxEBAmIM/QjV3Krri/RL53f2Rz5ZId7kwdjmu7hcVfLNJkjuwxSbX7jZCx55x3S/P7O+oYmt2pQMkQ0V98hX+v1iw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=meta.com; dmarc=pass action=none header.from=meta.com; dkim=pass header.d=meta.com; arc=none Received: from SN6PR1501MB2064.namprd15.prod.outlook.com (2603:10b6:805:d::27) by BLAPR15MB3924.namprd15.prod.outlook.com (2603:10b6:208:27c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20; Wed, 10 May 2023 23:54:16 +0000 Received: from SN6PR1501MB2064.namprd15.prod.outlook.com ([fe80::589f:9230:518:7f53]) by SN6PR1501MB2064.namprd15.prod.outlook.com ([fe80::589f:9230:518:7f53%6]) with mapi id 15.20.6363.032; Wed, 10 May 2023 23:54:15 +0000 Message-ID: <89159b33-3be4-487b-7647-0cbbd20c233d@meta.com> Date: Wed, 10 May 2023 16:54:12 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH] bpf: reject blacklisted symbols in kprobe_multi to avoid recursive trap Content-Language: en-US From: Yonghong Song To: Jiri Olsa Cc: Ze Gao , Song Liu , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Steven Rostedt , Masami Hiramatsu , Ze Gao , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org References: <20230510122045.2259-1-zegao@tencent.com> <6308b8e0-8a54-e574-a312-0a97cfbf810c@meta.com> <1195c4bd-ef54-2f1d-b079-2a11af42c62f@meta.com> In-Reply-To: <1195c4bd-ef54-2f1d-b079-2a11af42c62f@meta.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SJ0PR13CA0068.namprd13.prod.outlook.com (2603:10b6:a03:2c4::13) To SN6PR1501MB2064.namprd15.prod.outlook.com (2603:10b6:805:d::27) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR1501MB2064:EE_|BLAPR15MB3924:EE_ X-MS-Office365-Filtering-Correlation-Id: 63a14f94-3172-432d-5f8a-08db51b1dcae X-FB-Source: Internal X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WJaJwjn1jnhrikmMVgniVXcFmZfzSdIvHoCus9HiUP1uyGKfYwKtDtvBK6MI3H52u1mVSx8Emm13yTodvZAQ9qIb1OopCNp4SLTagOhSbXzfvKqoivzqdJTod5dbk6jCMp1mzfZjA9C574KrYqUoGzb35D68MBl8YOnk2aZwqYofmwh+vt7MeXueYyhdLlXTZ3MYdNyjlMX24M6GV8w1k4XTQJW9HvRGaWZk56ooYXZAEFkxgb1h1r5HTpNi/F5F61Gi75Egkclt72FV+hpQRF1YaSSNTdXo09MBCz2i5GdeZHPkk+hKYRn1+gqpD1bgrt+xdcoVuDR5NXoXT1BFFc8lyah/7Uq6H85iRQM3DtFfaYFRisVXxA/D7Q2RMjkS3EaRePrQmua0bGm2jq4Yhgmok2gwZv8hdFt/G1xwxGx4+92WSXOtxW+Sg23KPuwr43Khpl+h8kZRybU6MCHe9U7b7teUz3RWte0K+r+5ZetP0Lk/+1rygLLbYugl5fOwzh+CNX+lXh9Z+wwvg5PdLY3kK8V/s3Q2xXzm5dMEpZtbIxi4uaXBArDpV2q8+Y6Tijd8jbxacYjdvY82dHv7JLA8/ELufqXjgMKcnDE4W664FL702lM4NMka5Az44CiIOuXoiHp5sbvUbqvyh8msSw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR1501MB2064.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(376002)(136003)(366004)(39860400002)(451199021)(86362001)(38100700002)(36756003)(31696002)(31686004)(8676002)(8936002)(7416002)(6486002)(478600001)(5660300002)(6512007)(6506007)(186003)(2616005)(2906002)(83380400001)(41300700001)(66946007)(316002)(53546011)(66476007)(66556008)(54906003)(4326008)(6916009)(6666004)(43740500002)(45980500001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?QmIzRDBLdGZISC9xS3JITTZCTTczZXoyZnFQYVJ3RHdxRDU2N2ZOR21JaTJP?= =?utf-8?B?Yjhta08rMFhtaVlJbF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o5M0dqdUs2eXE4aEpaY2Va?= =?utf-8?B?QUZ5QzJ1VW1Qc3ZJV1pRVjRrYWRuRkVsWXVJTFdraWhKQVlWZUdRMnorNXRC?= =?utf-8?B?Y2o5R2EvOEVEbU5WN2kvU2tyeXhGbTFqYWNwWUN3c2FMUE4rbXlwQ1RjWWx3?= =?utf-8?B?QkU3bnk2K2g3bTNqc2NvMFBWNzFRM0s0MXd1cWxlaUM3RURUWC90OCtMRFFG?= =?utf-8?B?bFpDRUFKYUhab0xoTk9BdmdHSWZ0MU1BT1NNYW10cjM4enhtT1RmdmlZQUxa?= =?utf-8?B?bTA3Z3dDM0FTTGg1dDJ0ZmtYSjNUZ2UyVDR1OEdjOXBLR2p1b1F0MmhFNklU?= =?utf-8?B?QVE9PQ==?= X-OriginatorOrg: meta.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63a14f94-3172-432d-5f8a-08db51b1dcae X-MS-Exchange-CrossTenant-AuthSource: SN6PR1501MB2064.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 23:54:15.8290 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bzJ0gRecLSlcod35iKhyhivZ7tw+AtsvGPO1bOZmMGQ8jbkqR/NAI+piT2600SG8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR15MB3924 X-Proofpoint-ORIG-GUID: oZtrdEr3YgHwqbt5e17M1pgr8XUgNsF2 X-Proofpoint-GUID: oZtrdEr3YgHwqbt5e17M1pgr8XUgNsF2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-10_04,2023-05-05_01,2023-02-09_01 X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 On 5/10/23 1:20 PM, Yonghong Song wrote: > > > On 5/10/23 10:27 AM, Jiri Olsa wrote: >> On Wed, May 10, 2023 at 07:13:58AM -0700, Yonghong Song wrote: >>> >>> >>> On 5/10/23 5:20 AM, Ze Gao wrote: >>>> BPF_LINK_TYPE_KPROBE_MULTI attaches kprobe programs through fprobe, >>>> however it does not takes those kprobe blacklisted into consideration, >>>> which likely introduce recursive traps and blows up stacks. >>>> >>>> this patch adds simple check and remove those are in kprobe_blacklist >>>> from one fprobe during bpf_kprobe_multi_link_attach. And also >>>> check_kprobe_address_safe is open for more future checks. >>>> >>>> note that ftrace provides recursion detection mechanism, but for kprobe >>>> only, we can directly reject those cases early without turning to >>>> ftrace. >>>> >>>> Signed-off-by: Ze Gao >>>> --- >>>>    kernel/trace/bpf_trace.c | 37 +++++++++++++++++++++++++++++++++++++ >>>>    1 file changed, 37 insertions(+) >>>> >>>> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c >>>> index 9a050e36dc6c..44c68bc06bbd 100644 >>>> --- a/kernel/trace/bpf_trace.c >>>> +++ b/kernel/trace/bpf_trace.c >>>> @@ -2764,6 +2764,37 @@ static int get_modules_for_addrs(struct >>>> module ***mods, unsigned long *addrs, u3 >>>>        return arr.mods_cnt; >>>>    } >>>> +static inline int check_kprobe_address_safe(unsigned long addr) >>>> +{ >>>> +    if (within_kprobe_blacklist(addr)) >>>> +        return -EINVAL; >>>> +    else >>>> +        return 0; >>>> +} >>>> + >>>> +static int check_bpf_kprobe_addrs_safe(unsigned long *addrs, int num) >>>> +{ >>>> +    int i, cnt; >>>> +    char symname[KSYM_NAME_LEN]; >>>> + >>>> +    for (i = 0; i < num; ++i) { >>>> +        if (check_kprobe_address_safe((unsigned long)addrs[i])) { >>>> +            lookup_symbol_name(addrs[i], symname); >>>> +            pr_warn("bpf_kprobe: %s at %lx is blacklisted\n", >>>> symname, addrs[i]); >>> >>> So user request cannot be fulfilled and a warning is issued and some >>> of user requests are discarded and the rest is proceeded. Does not >>> sound a good idea. >>> >>> Maybe we should do filtering in user space, e.g., in libbpf, check >>> /sys/kernel/debug/kprobes/blacklist and return error >>> earlier? bpftrace/libbpf-tools/bcc-tools all do filtering before >>> requesting kprobe in the kernel. >> >> also fprobe uses ftrace drectly without paths in kprobe, so I wonder >> some of the kprobe blacklisted functions are actually safe > > Could you give a pointer about 'some of the kprobe blacklisted > functions are actually safe'? Thanks Jiri for answering my question. it is not clear whether kprobe blacklist == fprobe blacklist, probably not. You mentioned: note that ftrace provides recursion detection mechanism, but for kprobe only Maybe the right choice is to improve ftrace to provide recursion detection mechanism for fprobe as well? > >> >> jirka >> >>> >>>> +            /* mark blacklisted symbol for remove */ >>>> +            addrs[i] = 0; >>>> +        } >>>> +    } >>>> + >>>> +    /* remove blacklisted symbol from addrs */ >>>> +    for (i = 0, cnt = 0; i < num; ++i) { >>>> +        if (addrs[i]) >>>> +            addrs[cnt++]  = addrs[i]; >>>> +    } >>>> + >>>> +    return cnt; >>>> +} >>>> + >>>>    int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, >>>> struct bpf_prog *prog) >>>>    { >>>>        struct bpf_kprobe_multi_link *link = NULL; >>>> @@ -2859,6 +2890,12 @@ int bpf_kprobe_multi_link_attach(const union >>>> bpf_attr *attr, struct bpf_prog *pr >>>>        else >>>>            link->fp.entry_handler = kprobe_multi_link_handler; >>>> +    cnt = check_bpf_kprobe_addrs_safe(addrs, cnt); >>>> +    if (!cnt) { >>>> +        err = -EINVAL; >>>> +        goto error; >>>> +    } >>>> + >>>>        link->addrs = addrs; >>>>        link->cookies = cookies; >>>>        link->cnt = cnt;