Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp769159ybh; Wed, 15 Jul 2020 15:00:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjksoBz78I4gqQUJz4YOBKUbAalEA8cH5rx+4PEawdViPnf0/kFy27AB/ScrKX6Hrurhef X-Received: by 2002:a05:6402:164f:: with SMTP id s15mr1625227edx.239.1594850453652; Wed, 15 Jul 2020 15:00:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1594850453; cv=pass; d=google.com; s=arc-20160816; b=dLa1s/WaReGcxzw7YXpoBkSucr6h7KPVKBYaYZIfMT/FBnJltat4ibiorWMstmAW05 P6LzR/AQ05Q1WTH61JMIRAZt+Qn83FENxr6adH4gYwdo0Tgqgs6KP9jIqlxDH8IELvAA sGcrtUw7ilYOMSkJhahu4nC9nzZh/t1/DvPFMVeh0JHjRwxNN6zpgRvdBTW0b7ntqRN/ h1MKYmkcW8/mDqgoiTKEYlv9SYsbjH8Pjkj4W/whSkJe81kq8HnPcpHpbbSH/ORq9DS4 YdcyBd3He8rym4tsmzlpiuksNMB79yO+5KwgmPvpXJyue2s0gkqywFG+AyCsq8EVx1Gu dZAw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:in-reply-to :content-disposition:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=WXxjhYYHs2uvaqOOltD7ZeIAJl7XQaF4tF7W6uO/ASk=; b=wsOB5qnHnYYoH2FrbIqvH2lJxTLeW6XhAkxYwzK0VqmD+nxlLFqLolFxWrby91taIA f+IHCoAS5Jc4dtd5xh5F45npnMn/ooWjnlv+/BweDP2BA70xZflSVXok+yFgqFo0adm+ 5ZLpdpJfkgeQRq6xk4r8dbBJlh7XcqEmq5VB71p3pvb39GmC8D+dnUNwJlJTmLPZTdyg cMpCoBh9SgsPHu17pUvWwMLNscmRfa0sPG5EPPmG2Xn8FSuaSclJwNtEXlbo9P7eVPex PS+vBnStPqtZck57YPnIJQT0CS/nXa1k/bDyp3SlDoGRgWWBBvHwam1Qi9wL9rFssbzz Iitg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=rp3vO2RM; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=La8OBjjX; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lf11si2083936ejb.475.2020.07.15.15.00.27; Wed, 15 Jul 2020 15:00:53 -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; dkim=pass header.i=@fb.com header.s=facebook header.b=rp3vO2RM; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=La8OBjjX; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727788AbgGOV6M (ORCPT + 99 others); Wed, 15 Jul 2020 17:58:12 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:54914 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbgGOV6L (ORCPT ); Wed, 15 Jul 2020 17:58:11 -0400 Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06FLsNKE025832; Wed, 15 Jul 2020 14:57:55 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : content-type : in-reply-to : mime-version; s=facebook; bh=WXxjhYYHs2uvaqOOltD7ZeIAJl7XQaF4tF7W6uO/ASk=; b=rp3vO2RMA6G9cOIe8wtRHrp9H4Vv6766tKtfAhcRSa1cDejBRxlxrlGa8tYiutG/Etkc T9mQwDjuyoUMsn1lijwaDFm+0wfQmofTlmkOAB+CRrnvRpBwHoQ8AFSiOn785kxxAk9q H9lu9vs3NwCjrakfh/6Qwn9n5ypI26CvTwQ= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 327wdrt0mc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 15 Jul 2020 14:57:55 -0700 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (100.104.31.183) by o365-in.thefacebook.com (100.104.36.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 15 Jul 2020 14:57:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iefDx+E7ABWk5aUr4pOVoJ+LKmkLELITi/g6SJbyNLIhLZdVtJ22WfFp0O9KIJ0cA4Ri6w/Pd8m6J8/1eTATF78AnSZ/6DZBTjXJh7YKVQDTQ3gHhepUw3o/B4s/zT+6oiQI/ZPcUAI/yw4Gw3o3K7KDg7+ldq87aAC9EQS2CGd2wIHOR+udJ+MktKaB9aR0wGNxoXsoV8LNq0cgXuGwdSV9SfknR4os6Xppk8mu1rSK0HXSQ2sruGf7oIMD41Gwnez8jgEdOXVrnmUSicNM63UGIzknHKqcqO95ZozXicD6KfVBDUamobJcCluiCKoprotp0AGctjL1ooSESfywaw== 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-SenderADCheck; bh=WXxjhYYHs2uvaqOOltD7ZeIAJl7XQaF4tF7W6uO/ASk=; b=cpwT7StQe6+KmFo7D2nOHunPsoMJkNeMDMLUi1FnAraHr3JGUwuGZKhjL2k3YIXQ9+M6ObAY8vXcbx2I/IOFfafGhFtLAYsSpQsOOhC4wEI/XwahTFKnTbv9GRjoj9s0bMmpzqyHIuYEZ8qPdJL0HymaqR/n1k7KdA3Qfqp8xqpCoURGfsqqmlYn+Wk8AV98LTvfIELLlG+pFQ8jtcABxTenz4YwkAjljokzDgcpJpC0CMXry5cNzV/JyiDqs+SfnkaJbGrfmcEPYKKYF06HiCOolkNVnbiBNMNEf5zCOCvnVHGYYiLt10VF2hd0edGUqO//C1SwqggmWDKJT8FG1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector2-fb-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WXxjhYYHs2uvaqOOltD7ZeIAJl7XQaF4tF7W6uO/ASk=; b=La8OBjjXmgSaaZsFrY1eVKvst56qTLlyEifibR2RMpTdcgMcbZ7BrIyaCbmTeElLFE68/R2PvVxzY2/NaXINoYirAyfaQCGYgyZfI5ROr11tyB+EKWeENx5SQh/X6KKzoUFx3ybP4Rv48/1F4BofnGjwW3NYnbbCE3lA3DTihh8= Authentication-Results: chromium.org; dkim=none (message not signed) header.d=none;chromium.org; dmarc=none action=none header.from=fb.com; Received: from BY5PR15MB3571.namprd15.prod.outlook.com (2603:10b6:a03:1f6::32) by BYAPR15MB3302.namprd15.prod.outlook.com (2603:10b6:a03:10f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.23; Wed, 15 Jul 2020 21:57:53 +0000 Received: from BY5PR15MB3571.namprd15.prod.outlook.com ([fe80::d489:8f7f:614e:1b99]) by BY5PR15MB3571.namprd15.prod.outlook.com ([fe80::d489:8f7f:614e:1b99%7]) with mapi id 15.20.3174.026; Wed, 15 Jul 2020 21:57:53 +0000 Date: Wed, 15 Jul 2020 14:57:51 -0700 From: Martin KaFai Lau To: KP Singh CC: , , , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Jann Horn , Florent Revest Subject: Re: [PATCH bpf-next v4 2/4] bpf: Implement bpf_local_storage for inodes Message-ID: <20200715215751.6llgungzff66iwxh@kafai-mbp> References: <20200709101239.3829793-1-kpsingh@chromium.org> <20200709101239.3829793-3-kpsingh@chromium.org> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200709101239.3829793-3-kpsingh@chromium.org> User-Agent: NeoMutt/20180716 X-ClientProxiedBy: BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) To BY5PR15MB3571.namprd15.prod.outlook.com (2603:10b6:a03:1f6::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kafai-mbp (2620:10d:c090:400::5:5ec) by BYAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:a02:a8::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Wed, 15 Jul 2020 21:57:52 +0000 X-Originating-IP: [2620:10d:c090:400::5:5ec] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 53228ed2-a151-4178-818d-08d8290a1f7f X-MS-TrafficTypeDiagnostic: BYAPR15MB3302: X-Microsoft-Antispam-PRVS: X-FB-Source: Internal X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rkwoy2j2Dqh7bDo/7zPxIsfEZn8/jZq6Ok/7L+5BG7kmNIgzZu4OlOIaltLxt6VbX3GKgggMYPsuIysmaPkn++0GaeB0Mdg0A7ICounkH5vP0Gct9NNCzevZ8Dm0X2YvgJGO11IJ8Ne0swsAB0qaV22z0VCw/9wGXhPncqtAGGscKbzIqB9HV3tlZfwaUHbr8slR5Uo27jSX6bPquz7JdEscPSdQ23FG0gz9SD04HqV2OcQDlphTw8E/CIJK5rk8YCfI0dvc0x7+xgR9IHZCnd242DJuWwieZNzrcqWRJyf0wTJqmrRxFxNkxcvqAIaj X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR15MB3571.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(396003)(346002)(376002)(366004)(136003)(39860400002)(33716001)(16526019)(6496006)(66476007)(52116002)(66556008)(8676002)(66946007)(6916009)(55016002)(186003)(2906002)(5660300002)(478600001)(86362001)(1076003)(4326008)(83380400001)(9686003)(8936002)(54906003)(316002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: RSftEDidlj8JSHfFPGhw1971hlgUmR8XFPJ8VZT5VkY1fkoDiIJ9yOVGTgoNkg6WpONa05YIwe0tbRTXlJAN9M59TeJNixbaw2vwM5NLXGOzdN6NwkXke3naayNCkE+HODdlwENhu1HxLkOHGloE9IP/XAfzLXFFLL+5VHI6kgs8q5LboTF9fvh23PURhF1TOLWaHTUbg10/YoH3zonl1GCHYDk1+QgWcYfvQEeW6XJG+yMy0LyI5ibOha7GDnTdlCyi5eIWA7wjgUQD3sqXh3hahM9gqVAC/yE3qTO93iUFEyHTW4tziP+yKEBHhv+KCHW1HMEP2fCS9MSLCt9JVZ97LqNplyqoVC7wD015Ve+V2alte0c9or/WK7TppwJ6fseWiA9YIZFHtkbKiMYVWPIBazPaIyZIuRJPLJ4GGv99PEE2CdcbYexB1OyMBgOEnl6joaqFsklHrn6mi9tPALsGvQUbYVHrV7sSCmEQGWxIlQt7HGTE+In8riTb4BzqBa9PQkuweO01p7GFyANRxw== X-MS-Exchange-CrossTenant-Network-Message-Id: 53228ed2-a151-4178-818d-08d8290a1f7f X-MS-Exchange-CrossTenant-AuthSource: BY5PR15MB3571.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2020 21:57:52.9166 (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: A6YOUTlZi2+0gtntqdl59DWWr8NpT8HgM90FACht9Q899jJxO7XR4opesewUxwuS X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR15MB3302 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-15_12:2020-07-15,2020-07-15 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 bulkscore=0 mlxscore=0 malwarescore=0 phishscore=0 clxscore=1015 impostorscore=0 suspectscore=2 adultscore=0 spamscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=485 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007150163 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 09, 2020 at 12:12:37PM +0200, KP Singh wrote: > From: KP Singh > > Similar to bpf_local_storage for sockets, add local storage for inodes. > The life-cycle of storage is managed with the life-cycle of the inode. > i.e. the storage is destroyed along with the owning inode. > > The BPF LSM allocates an __rcu pointer to the bpf_local_storage in the > security blob which are now stackable and can co-exist with other LSMs. > > Signed-off-by: KP Singh [ ... ] > +static void *bpf_inode_storage_lookup_elem(struct bpf_map *map, void *key) > +{ > + struct bpf_local_storage_data *sdata; > + struct inode *inode; > + int err = -EINVAL; > + > + if (key) { > + inode = *(struct inode **)(key); The bpf_inode_storage_lookup_elem() here and the (update|delete)_elem() below are called from the userspace syscall. How the userspace may provide this key? > + sdata = inode_storage_lookup(inode, map, true); > + return sdata ? sdata->data : NULL; > + } > + > + return ERR_PTR(err); > +} > + > +static int bpf_inode_storage_update_elem(struct bpf_map *map, void *key, > + void *value, u64 map_flags) > +{ > + struct bpf_local_storage_data *sdata; > + struct inode *inode; > + int err = -EINVAL; > + > + if (key) { > + inode = *(struct inode **)(key); > + sdata = map->ops->map_local_storage_update(inode, map, value, > + map_flags); > + return PTR_ERR_OR_ZERO(sdata); > + } > + return err; > +} > + > +static int inode_storage_delete(struct inode *inode, struct bpf_map *map) > +{ > + struct bpf_local_storage_data *sdata; > + > + sdata = inode_storage_lookup(inode, map, false); > + if (!sdata) > + return -ENOENT; > + > + bpf_selem_unlink_map_elem(SELEM(sdata)); > + > + return 0; > +} > + > +static int bpf_inode_storage_delete_elem(struct bpf_map *map, void *key) > +{ > + struct inode *inode; > + int err = -EINVAL; > + > + if (key) { > + inode = *(struct inode **)(key); > + err = inode_storage_delete(inode, map); > + } > + > + return err; > +} > + [ ... ] > +static int inode_storage_map_btf_id; > +const struct bpf_map_ops inode_storage_map_ops = { > + .map_alloc_check = bpf_local_storage_map_alloc_check, > + .map_alloc = inode_storage_map_alloc, > + .map_free = inode_storage_map_free, > + .map_get_next_key = notsupp_get_next_key, > + .map_lookup_elem = bpf_inode_storage_lookup_elem, > + .map_update_elem = bpf_inode_storage_update_elem, > + .map_delete_elem = bpf_inode_storage_delete_elem, > + .map_check_btf = bpf_local_storage_map_check_btf, > + .map_btf_name = "bpf_local_storage_map", > + .map_btf_id = &inode_storage_map_btf_id, > + .map_local_storage_alloc = inode_storage_alloc, > + .map_selem_alloc = inode_selem_alloc, > + .map_local_storage_update = inode_storage_update, > + .map_local_storage_unlink = unlink_inode_storage, > +}; > +