Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp246594ybh; Mon, 20 Jul 2020 15:44:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaHHZUaDge6qTeGPomx0miy3MCVJDttluQC2Pvz8XO5eqnE2TeM44SwDzB6AQ1+cChkjae X-Received: by 2002:a17:906:7f93:: with SMTP id f19mr23882930ejr.0.1595285087981; Mon, 20 Jul 2020 15:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595285087; cv=none; d=google.com; s=arc-20160816; b=ns3pBQvlmZnGL+JByCu50mcugrS5S8QYlO/UiUiIw4rjzoPZ6MKbZpw4i07/BUlskK vzdp31t7paZeVias6B8NwzpVGQEVBQHMJdJes1IPCwgMYlmeVWz5JMjudQdCKXltOSF2 uzyEZ+Kk8fr5n5aSK1OuXu9Ex9xPjOR2oGFg++Heaf21HOPXAoiNUFD33aY8cUMuWfQz QdOmKURZq5BqwTL1laOv2hp4X0u+zclqWsHeirhf1C1pg99MEQKOSUpj+Dz+y3sC/WZS aLuhindBejcW8btpwuOwQMrvm2bYdiy6DC7l8R2EuPgzFkA9bEVLM3CB40xooaFR9oPk emqA== 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=vYYj1xkqdAsQ1FACIja4W5B8GUjTG6OnchmcXRlXDAM=; b=yhGJTMBeaun3dJKim5MPxP5MU+I+FJWv8qwKl9QeZ7XyNxOxjoS0HjMCEdtajm5ii8 kW8BEe6PSEkcINFzdFh5qYgkt2JGe+SuVk+F5feiXw6DZW2dAq/rdeXJXv/zwIIepadS fODeeUtZWyh3OAxSaC+/uOYz0UcJcgBvuaH28L8WpfeE1I3EF3hgDg6FbLJ2w6pHSFEK XP1teF+I+lcSvzIvfz7ZyO5RC6qcusgSiWCWjzJDw5dQQMAaVHUxGQ0s3sIF3lT9L4/d TPqQBtX0zjKjV+UbYJm/luXDZcaWtM67ozg1EisrpT8HvcNgoJ8CHW+77UCr60YwLQZC JTQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LhvbkMtt; 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 h22si10746210ejj.363.2020.07.20.15.44.24; Mon, 20 Jul 2020 15:44:47 -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=LhvbkMtt; 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 S1727042AbgGTWoR (ORCPT + 99 others); Mon, 20 Jul 2020 18:44:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726127AbgGTWoP (ORCPT ); Mon, 20 Jul 2020 18:44:15 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C67EC0619D2 for ; Mon, 20 Jul 2020 15:44:15 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id n2so13942076edr.5 for ; Mon, 20 Jul 2020 15:44:15 -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=vYYj1xkqdAsQ1FACIja4W5B8GUjTG6OnchmcXRlXDAM=; b=LhvbkMttHCYSIkbtKIEJKfKLYcHeua/U3mDmokc6dBBiJsdTOS9eQQVY9fXHQEpNSg bsBZjEcH/UvUgiyXF/bGXcjZfuUC/BGaS5rd6vGmLmfV0UaHgRLXjT0EXKUmsIqGPCBy Sb8dlD85mrzgrlGYZs+ZHYMQF4zJNXtsCPBXw= 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=vYYj1xkqdAsQ1FACIja4W5B8GUjTG6OnchmcXRlXDAM=; b=mQr5p29MdRnCDY+7r5mhJk5qJUfH4hnOWnX5H3SnD1cQYSrZ/6Uy5j0sKvQZrrTTNy No+rLrFX8jQWhYJINH0Y5KD7J6lbWb1cEloAjfLJii7RYB7JAe/AvJm1PvIUHcf5c0Y7 TZJ1ndVPuCXBxn1wqbWPYMe6uZQreB4tILTSq6LVC5IQl0Do5VEYD/Jo1B0gsdobl9Ye BICLNm3rE09GtZ1Qbl0Q5u0iUTOrkacqpZfswH38VZwjXDJlirXFVMEDQi0a5gDwsH84 04aDNj6G82yyKRYciIkbRu9GxIgoXKdcwy4VkdHunPc6ZdBPjQvDxYJ1OqgrnwGZGtPr e07A== X-Gm-Message-State: AOAM530zBtimx8ikcpaacqsmOqX5W4jQilaa55gG+jxgoFhCFn6uFaRh RkArhBdSW68C7NXLj27o/D2LWQ== X-Received: by 2002:a05:6402:3d0:: with SMTP id t16mr22865489edw.287.1595285053947; Mon, 20 Jul 2020 15:44:13 -0700 (PDT) Received: from google.com ([81.6.44.51]) by smtp.gmail.com with ESMTPSA id cc9sm16719027edb.14.2020.07.20.15.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 15:44:13 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Tue, 21 Jul 2020 00:44:11 +0200 To: KP Singh Cc: Martin KaFai Lau , 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: <20200720224411.GA1873800@google.com> References: <20200709101239.3829793-1-kpsingh@chromium.org> <20200709101239.3829793-3-kpsingh@chromium.org> <20200715215751.6llgungzff66iwxh@kafai-mbp> <20200715225911.GA1194150@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200715225911.GA1194150@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16-Jul 00:59, KP Singh wrote: > 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. I actually implemented these as: static int bpf_fd_inode_storage_delete_elem(struct bpf_map *map, void *key) { struct file *f; int fd; fd = *(int *)key; f = fcheck(fd); if (!f) return -EINVAL; return inode_storage_delete(f->f_inode, map); } This keeps it similar to sk_storage and the userspace can just pass an fd. - KP > > - 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, > > > +}; > > > +