Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp7974572imm; Thu, 28 Jun 2018 12:21:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdoniWJXK/OpuegMw8ni0bSbhTqg7oV3yLOcClQcoy71davlqFDrn1ilt/ibQ5cwwe64SuY X-Received: by 2002:a62:4fcd:: with SMTP id f74-v6mr10484810pfj.161.1530213697435; Thu, 28 Jun 2018 12:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530213697; cv=none; d=google.com; s=arc-20160816; b=HPFPQdedo0HikEq4l6dwWyZ0nrYnZs8bFL5MbjosH4v8zpYDF/cnxoKK93ogv1g2ME LDA5EW9VxxUbAjRvtKO41RghinpiNE3d1sOliEaNdK4wR48G+PoSSgmh+trXFsuPoy4i iCyQcBV6eKPNx7CDDx/lC3EUnzmtx24Sak6Bh8AMs6fs69RBg+qOF/CTYlbNTome0n2Z n7Kfa5rv1CinEpi5EwiOIMBGAL+1vCz9Ds/ozSDalSeyjRlKVlaRU/20zLk/XfM4jnaJ 1ImE3+PVB1eq8U/2cB7QGwjFqjHyyMC3XhAy1WQTVopjxPg5uufXDzLz74YSFXulJZRq V6SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :arc-authentication-results; bh=whOWnZ8vlzRb4MFPGcMC1P+5gEEOwt2DmR99r08RYPY=; b=pN+i2HxeasSSKIhcPU8ebgHYlF8oWSTZBeMkSXGBDTG++wxvCTETn4wABrCLgNH2If a1v+1Z/Nm3zBsYCQdQec8UpwxaiornqlM2JaUA4qSa75UmmZiKnJdxGrEMj1rhXc6XCF QL5nJDB1QZe5/lxiU1VAfhDeuLtSJzT4BSC2f5+fxo1UaErmSpXPB6V2DR9ElQLBVndq y5n79mNt9cWmt2KPjBlqtpIPzXpI1jAotRTCOts+2h+FIaIJ7EnS1demYLIcR3ea46Bo hsfngSkoRx3XoYXlg/hzakUJ3JBKmOWxkKLiR3RvwrpMAT6zCHM1DhujqB50awBSxKep LwQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=H4HtrI9V; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=TXdy0dfw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5-v6si222952pla.337.2018.06.28.12.20.52; Thu, 28 Jun 2018 12:21:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=H4HtrI9V; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=TXdy0dfw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935960AbeF1QvL (ORCPT + 99 others); Thu, 28 Jun 2018 12:51:11 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:59438 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935748AbeF1Qs1 (ORCPT ); Thu, 28 Jun 2018 12:48:27 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.22/8.16.0.22) with SMTP id w5SGiPIk021776; Thu, 28 Jun 2018 09:48:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=whOWnZ8vlzRb4MFPGcMC1P+5gEEOwt2DmR99r08RYPY=; b=H4HtrI9V62edFeoxCB4JcXVHTcMpJp6OvVsPUDfmFQWXW4SfoMqCyq+BEgUWFICUorw8 y7f8TEtrQ9NUIfezJtVW+LOyQwqkj7RZYQKkecMHNa4AWup+T+ealQ+qNTM7J29e92D9 31K5z7BPr6flFzM3Vcs9QWnVT1W4Jgh5e3Y= Received: from maileast.thefacebook.com ([199.201.65.23]) by m0089730.ppops.net with ESMTP id 2jw22p8ex1-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 28 Jun 2018 09:48:10 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.26) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 28 Jun 2018 12:48:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=whOWnZ8vlzRb4MFPGcMC1P+5gEEOwt2DmR99r08RYPY=; b=TXdy0dfwX1pmi+s8F6Rnbit8aqvTmsomb7P/3BClXP61P2pxsSSLY3sRmz/+o7/LjSgO6L/jCNMGyeC1DZ5DRcKDW/tLYyEkyPluA1Gd5JXizdh+wTnXDDStittmJUB1Z5P8Osrtyzh2T7YkYEW+tUKMa9RWWpAlcxwG066zZ4E= Received: from castle.thefacebook.com (2620:10d:c090:200::4:4716) by DM3PR15MB1081.namprd15.prod.outlook.com (2603:10b6:0:12::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.884.24; Thu, 28 Jun 2018 16:48:04 +0000 From: Roman Gushchin To: CC: , , , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH bpf-next 08/14] bpf: introduce the bpf_get_local_storage() helper function Date: Thu, 28 Jun 2018 09:47:13 -0700 Message-ID: <20180628164719.28215-9-guro@fb.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180628164719.28215-1-guro@fb.com> References: <20180628164719.28215-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c090:200::4:4716] X-ClientProxiedBy: MW2PR16CA0046.namprd16.prod.outlook.com (2603:10b6:907:1::23) To DM3PR15MB1081.namprd15.prod.outlook.com (2603:10b6:0:12::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 195db4dd-2795-4c30-cace-08d5dd16eb6a X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652034)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600026)(711020)(2017052603328)(7153060)(7193020);SRVR:DM3PR15MB1081; X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1081;3:NKweAdf7gUta8ymT3OX21NBSV5cCA4DNtzSB/ld+xKmlnDPDGmOZuNG4rnlYNtKrTso4Y4UsRtmBcH2nJwtszB8FD/0fePsetzcmqM25ZfZO0kI6eVogY7+rn8lgygiVpVUteLH4abyEvhXNZ3k0TBjp5MOebEbuyTnpB9b6OFinQvUJbtw0N1TXq60WpJbZhyAJpk9Ro65BEpA4SCBjprvEtkdTqD29bLHjMVg+iX9HxucWq1dtcwGY1Iz3OlZI;25:WCDp2HRWVliwEM/2S6BJYw+Kq9DegQ3PsfPHglQ0PUF53sp69wm4bdVVUG/SxnCWGpwOMIiT3w+2+jB5UMqwTF2bcXbDt+Mn3d3o4Xs8/h7NNbn5HuiIPpGr6bHnLxpR5HdnIdWf+ojmcfcj6EI2WfnYpBnphzbELxhBrIH7yswGa5LNyWvP1fmy8WlHXQ212DzrAtNQsCocwibfqi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0u90Of0u7R8EOP9B4qCZ7YFPt2oxLIRjn1Qi8j4TRbhBroSyJfdAnC2EKf4OLFS0J8IvJdmXHKLpNXuXc727co8odA1PtDVgvsZj3bnbr3y4zgLR4EDtQEvuoVSv5D2Fj4IhYNjHAw1ZEV5SVynYBfp54Bg9d5908945a2m5q37D2Twe9OlJxDgmWbabSNpQ19SHXGztcql6PeeuQ/koMqKC5CvuuZ2tWTSZy7L4OaoZk= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(131327999870524)(67672495146484); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231254)(11241501184)(944501410)(52105095)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(6072148)(201708071742011)(7699016);SRVR:DM3PR15MB1081;BCL:0;PCL:0;RULEID:;SRVR:DM3PR15MB1081; X-Forefront-PRVS: 0717E25089 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(136003)(396003)(346002)(39860400002)(376002)(366004)(189003)(199004)(8676002)(6512007)(4326008)(81166006)(81156014)(69596002)(97736004)(52116002)(2361001)(51416003)(8936002)(76176011)(305945005)(53416004)(186003)(16526019)(6506007)(386003)(106356001)(105586002)(2906002)(25786009)(36756003)(52396003)(7736002)(68736007)(50226002)(5660300001)(6666003)(53936002)(6916009)(48376002)(50466002)(478600001)(6486002)(1076002)(47776003)(6116002)(86362001)(575784001)(14444005)(16586007)(54906003)(46003)(476003)(486006)(446003)(2351001)(11346002)(2616005)(316002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:DM3PR15MB1081;H:castle.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Micros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WQZ9Dw8lHIajtNIQm1i7BMVD4REwY1+Me6j9a81H3kkZ5JA4j7Oyu9kcxWulIxijMfP735GhCjtI+OcvqxMtpAi135amcBjJ08dCTKG8rUAB9ge4foG8e2azIn2kb7R2/+SOPtSI4xhCbIpp+hqH805O3JwrI8tzAzODlny58= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2018 16:48:04.4112 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 195db4dd-2795-4c30-cace-08d5dd16eb6a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR15MB1081 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-28_08:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The bpf_get_local_storage() helper function is used to get a pointer to the bpf local storage from a bpf program. It takes a pointer to a storage map and flags as arguments. Right now it accepts only cgroup storage maps, and flags argument has to be 0. Further it can be extended to support other types of local storage: e.g. thread local storage etc. Signed-off-by: Roman Gushchin Cc: Alexei Starovoitov Cc: Daniel Borkmann Acked-by: Martin KaFai Lau --- include/linux/bpf.h | 2 ++ include/uapi/linux/bpf.h | 13 ++++++++++++- kernel/bpf/cgroup.c | 2 ++ kernel/bpf/helpers.c | 20 ++++++++++++++++++++ kernel/bpf/verifier.c | 18 ++++++++++++++++++ net/core/filter.c | 23 ++++++++++++++++++++++- 6 files changed, 76 insertions(+), 2 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index aaaa6d7e0dfc..1fdcf9d21b74 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -771,6 +771,8 @@ extern const struct bpf_func_proto bpf_sock_map_update_proto; extern const struct bpf_func_proto bpf_sock_hash_update_proto; extern const struct bpf_func_proto bpf_get_current_cgroup_id_proto; +extern const struct bpf_func_proto bpf_get_local_storage_proto; + /* Shared helpers among cBPF and eBPF. */ void bpf_user_rnd_init_once(void); u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 7aa135e4c2f3..baf74db6c06e 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -2081,6 +2081,16 @@ union bpf_attr { * Return * A 64-bit integer containing the current cgroup id based * on the cgroup within which the current task is running. + * + * void* get_local_storage(void *map, u64 flags) + * Description + * Get the pointer to the local storage area. + * The type and the size of the local storage is defined + * by the *map* argument. + * The *flags* meaning is specific for each map type, + * and has to be 0 for cgroup local storage. + * Return + * Pointer to the local storage area. */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -2163,7 +2173,8 @@ union bpf_attr { FN(rc_repeat), \ FN(rc_keydown), \ FN(skb_cgroup_id), \ - FN(get_current_cgroup_id), + FN(get_current_cgroup_id), \ + FN(get_local_storage), /* integer value in 'imm' field of BPF_CALL instruction selects which helper * function eBPF program intends to call diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 14a1f6c94592..47d4519a6847 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -629,6 +629,8 @@ cgroup_dev_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_map_delete_elem_proto; case BPF_FUNC_get_current_uid_gid: return &bpf_get_current_uid_gid_proto; + case BPF_FUNC_get_local_storage: + return &bpf_get_local_storage_proto; case BPF_FUNC_trace_printk: if (capable(CAP_SYS_ADMIN)) return bpf_get_trace_printk_proto(); diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 73065e2d23c2..ca17b4ed3ac9 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -193,4 +193,24 @@ const struct bpf_func_proto bpf_get_current_cgroup_id_proto = { .gpl_only = false, .ret_type = RET_INTEGER, }; + +DECLARE_PER_CPU(void*, bpf_cgroup_storage); + +BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) +{ + /* map and flags arguments are not used now, + * but provide an ability to extend the API + * for other types of local storages. + * verifier checks that their values are correct. + */ + return (u64)this_cpu_read(bpf_cgroup_storage); +} + +const struct bpf_func_proto bpf_get_local_storage_proto = { + .func = bpf_get_local_storage, + .gpl_only = false, + .ret_type = RET_PTR_TO_MAP_VALUE, + .arg1_type = ARG_CONST_MAP_PTR, + .arg2_type = ARG_ANYTHING, +}; #endif diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index cc0c7990f849..a0f5c26fffc1 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2127,6 +2127,10 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env, func_id != BPF_FUNC_current_task_under_cgroup) goto error; break; + case BPF_MAP_TYPE_CGROUP_STORAGE: + if (func_id != BPF_FUNC_get_local_storage) + goto error; + break; /* devmap returns a pointer to a live net_device ifindex that we cannot * allow to be modified from bpf side. So do not allow lookup elements * for now. @@ -2209,6 +2213,10 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env, if (map->map_type != BPF_MAP_TYPE_SOCKHASH) goto error; break; + case BPF_FUNC_get_local_storage: + if (map->map_type != BPF_MAP_TYPE_CGROUP_STORAGE) + goto error; + break; default: break; } @@ -2533,6 +2541,16 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn } regs = cur_regs(env); + + /* check that flags argument in get_local_storage(map, flags) is 0, + * this is required because get_local_storage() can't return an error. + */ + if (func_id == BPF_FUNC_get_local_storage && + !tnum_equals_const(regs[BPF_REG_2].var_off, 0)) { + verbose(env, "get_local_storage() doesn't support non-zero flags\n"); + return -EINVAL; + } + /* reset caller saved regs */ for (i = 0; i < CALLER_SAVED_REGS; i++) { mark_reg_not_init(env, regs, caller_saved[i]); diff --git a/net/core/filter.c b/net/core/filter.c index e7f12e9f598c..42e39e0c6c80 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4652,6 +4652,8 @@ sock_filter_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) */ case BPF_FUNC_get_current_uid_gid: return &bpf_get_current_uid_gid_proto; + case BPF_FUNC_get_local_storage: + return &bpf_get_local_storage_proto; default: return bpf_base_func_proto(func_id); } @@ -4674,6 +4676,8 @@ sock_addr_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) default: return NULL; } + case BPF_FUNC_get_local_storage: + return &bpf_get_local_storage_proto; default: return bpf_base_func_proto(func_id); } @@ -4696,6 +4700,17 @@ sk_filter_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) } } +static const struct bpf_func_proto * +cg_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) +{ + switch (func_id) { + case BPF_FUNC_get_local_storage: + return &bpf_get_local_storage_proto; + default: + return sk_filter_func_proto(func_id, prog); + } +} + static const struct bpf_func_proto * tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) { @@ -4816,6 +4831,8 @@ sock_ops_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_sock_map_update_proto; case BPF_FUNC_sock_hash_update: return &bpf_sock_hash_update_proto; + case BPF_FUNC_get_local_storage: + return &bpf_get_local_storage_proto; default: return bpf_base_func_proto(func_id); } @@ -4835,6 +4852,8 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_msg_cork_bytes_proto; case BPF_FUNC_msg_pull_data: return &bpf_msg_pull_data_proto; + case BPF_FUNC_get_local_storage: + return &bpf_get_local_storage_proto; default: return bpf_base_func_proto(func_id); } @@ -4862,6 +4881,8 @@ sk_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_sk_redirect_map_proto; case BPF_FUNC_sk_redirect_hash: return &bpf_sk_redirect_hash_proto; + case BPF_FUNC_get_local_storage: + return &bpf_get_local_storage_proto; default: return bpf_base_func_proto(func_id); } @@ -6664,7 +6685,7 @@ const struct bpf_prog_ops xdp_prog_ops = { }; const struct bpf_verifier_ops cg_skb_verifier_ops = { - .get_func_proto = sk_filter_func_proto, + .get_func_proto = cg_skb_func_proto, .is_valid_access = sk_filter_is_valid_access, .convert_ctx_access = bpf_convert_ctx_access, }; -- 2.14.4