Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp799123ybh; Wed, 15 Jul 2020 16:00:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2Rs3KFmZ9aXj1v/67cKSrU3LsCrirzXO0Qta1rctQf0WeIN9Q4OmrfjEOBW/N030sEAjw X-Received: by 2002:a05:6402:22f0:: with SMTP id dn16mr1846700edb.83.1594854040361; Wed, 15 Jul 2020 16:00:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594854040; cv=none; d=google.com; s=arc-20160816; b=C5UmlCSxx/zXSs//FmzU9tmcposwJZPs7jOdsTzOlQoQIR5lvw1SDJ6y6trqktKDQK +XQ+60SbGZCMw+EKNANBNTQe0rITlr3TuBcsJRrUhOx0p0s7vo3I5PEMch+iYBu4rjRf z4Od7Qv9lX1u7SPxBpL7xygK1M0FPSx4Ux6Exdobfk2fjyT+o2l+edtioApALzvHmgws EDw5CegccVUcjVW6JvhTP3+zMK4AKpRysGBLetHKHwM67ZjD7A3V6ElOWrJRajhUNcMV UrZEHFnF73eHAh0wV9RiAvsjSxI9VCg2O6hYgQ97Nhh6TxIBix0PvPdZqvUfovWkCYrU bzcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=fZ1rBakSReO9Dn+EzmBi7QlVUTw5S5sAIhY6NkDcqpg=; b=i9xNkEISSST2dpCfGerP3LE0PmZJr3us06883Q3VqKYtvSd76AB03Wl1LmOqLlBSkV sEKaJf+RlDO7dSN4jYV+0y8tZn+RHnKWYM+tjKDla2bmjaWh5G56VG/JlEKYp7sHYiP2 zPSG7VNXzQI0AHE+ofteljSZp2MbQMhS1EsOwGWPDk4bRcxJg2yrZLTq+XRXVsjpuBax 4kzTcNqY505jv/n6xTyWutfA/n9pbbAluRg+QVDzW9u39GnjwnoWK8RPOffJ+wGiSq4B Jir0e9QK+E1G3OJ1xJjKS0ca2auLlwsZeUslJdO3oZZ1FpQLOIhiZU5LNn36q6wDFzbx YvUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UyVYVGZ3; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si1910489ejb.579.2020.07.15.16.00.16; Wed, 15 Jul 2020 16:00:40 -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=@chromium.org header.s=google header.b=UyVYVGZ3; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727062AbgGOW7P (ORCPT + 99 others); Wed, 15 Jul 2020 18:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726765AbgGOW7P (ORCPT ); Wed, 15 Jul 2020 18:59:15 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA7C0C061755 for ; Wed, 15 Jul 2020 15:59:14 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id o18so4154182eje.7 for ; Wed, 15 Jul 2020 15:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fZ1rBakSReO9Dn+EzmBi7QlVUTw5S5sAIhY6NkDcqpg=; b=UyVYVGZ3tCLbe+5CH0LQ890sq2xoQmOnnE5A7hlJaGCoxZtFB624re+THIl7BI+lvO eyyMilV41zbb2R7HS+QQp0qUghMOIUFFpGhvCz6uhonYxEZ2Lupsz+v2JGuO2SUposUC wjZ0s+y5RtIISKMhBqUi/DW+mBLIJ4qpPEQ28= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fZ1rBakSReO9Dn+EzmBi7QlVUTw5S5sAIhY6NkDcqpg=; b=YOkvmmX2qE5CvgfU9DAIpR35vfxYuZsa2Wq3vrN9A/poQjtywmArrKUlKe7G/3B2eF y/sekBJLdMhMFaF3xuwdVEmNjlRk50e8x70X6KKn6mFW5/GUI4Oy/AjZZICtuQRiNRr4 RZlCwAuyHkNcC1rg0aO/Ivsuq6RPhmDHX65oLBCr0WLWf8xpH873hA8E0/lQWs/M4rXi kpliUsLSeNOWnC9jqqCNsLtY3jQGUgdmVdxBj58JdEHbibTz2JPhDbjHqxIxkUJI7Jch B1mVt5KxHQTCzmAsKyIn/Lrm+fNv5s9Ub2xyMvt210gEogoW4uHiyWUuohI6/1m7+h0K K2xg== X-Gm-Message-State: AOAM533Ck0zjKH6Wq6cxrunRgPlj0xWU1TloRdnFYFi/vmY6N79wgqMG spn0DYjltHYOBE0gFk7xVz1SBg== X-Received: by 2002:a17:907:2149:: with SMTP id rk9mr1079014ejb.553.1594853953417; Wed, 15 Jul 2020 15:59:13 -0700 (PDT) Received: from google.com ([81.6.44.51]) by smtp.gmail.com with ESMTPSA id hb8sm3307531ejb.8.2020.07.15.15.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2020 15:59:12 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Thu, 16 Jul 2020 00:59:11 +0200 To: Martin KaFai Lau Cc: KP Singh , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, 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: <20200715225911.GA1194150@google.com> References: <20200709101239.3829793-1-kpsingh@chromium.org> <20200709101239.3829793-3-kpsingh@chromium.org> <20200715215751.6llgungzff66iwxh@kafai-mbp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200715215751.6llgungzff66iwxh@kafai-mbp> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15-Jul 14:57, Martin KaFai Lau wrote: > 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? I realized this when I replied about the _fd_ name in the sk helpers. I am going to mark them as unsupported for now for inodes. We could, probably and separately, use a combination of the device and inode number as a key from userspace. - KP > > > + 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, > > +}; > > +