Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3217976pxm; Mon, 28 Feb 2022 14:47:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJz471/Cw0LrhFBDwE+Y+6RQ7poKmPWKOegFaen5fZBRHHNVsF1kF+JG6urajC06+rn5//3+ X-Received: by 2002:a17:906:40c9:b0:6ba:6f72:dd3d with SMTP id a9-20020a17090640c900b006ba6f72dd3dmr17038537ejk.373.1646088443129; Mon, 28 Feb 2022 14:47:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646088443; cv=none; d=google.com; s=arc-20160816; b=QX4/4W/sTs05WwLImwnjmYRLun1Ge3f0eFWh/oEMhuCfq/59F0k5jjMwDDsbfeisJZ cJaKf0XcXYHxg73LSrx8NeMFab09Um84ZQeb/j+LMfvkb18MrdMpJOGsE/MF4q+hxsBJ 9LZsHwOjhA1K9amuatFKayTX5+c8V3hpMFrLlloziMaD2qPsCK8Meh/mZweuSHQcGviu hVJCLTynRDoJYqBSBVFBF26xp/JUC2NTZ44ipk4nuWbdXCRh02SFkQkjDqKl9HlcGuPX g49LTqChfXPw7FzxaJ3rlOVo7+/SabzZ3HNxR7r8QG5tWwgj1TSIPDM03oR6B/uYXc1M JH+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=V0f1W4Wc0EEoXA/hJdBQxq1Gp1glgbsbboI5sHwm0rI=; b=AfSqS7U4C+Y2DYS9Pmmq4QGbodAGxjcJi+ubZCXclWbhh6nn9Nut/pKRi0c7NSkP1u 6LqFcfY8hXXTM64eb4Q0RNyck/ZVBJkkGjIrqL2E+XDt6JZVb/JYRURfYMIhPRh5/pm5 TBxnnNYjL+O9VKH/0mSkzFBjQTg/sj9PxO2huugz/dvEb/DMDh0oigSIiwNYyDhhqFh8 fDWl4ZDlSMG/CSc3pXzuHqF0ceB7ZDXJ68zWZCcPMkXwfy9Sqvua3aX7fVKh/ZvusARl hgmBnODDwrRVRgWko/ACYyebu4tR8VhU+A6bCfhAVF+9a0EHXvRPN1ZeoDAdfYkx0N/q ZqOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dbuCifi5; 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=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14-20020a1709066c8e00b006cfe1cc4dd0si7159479ejr.305.2022.02.28.14.46.59; Mon, 28 Feb 2022 14:47:23 -0800 (PST) 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=@google.com header.s=20210112 header.b=dbuCifi5; 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=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231255AbiB1WLe (ORCPT + 99 others); Mon, 28 Feb 2022 17:11:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbiB1WLc (ORCPT ); Mon, 28 Feb 2022 17:11:32 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E104FC6837 for ; Mon, 28 Feb 2022 14:10:52 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id b5so17638046wrr.2 for ; Mon, 28 Feb 2022 14:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=V0f1W4Wc0EEoXA/hJdBQxq1Gp1glgbsbboI5sHwm0rI=; b=dbuCifi5i+s3laQK3MjadtEFvIaRuSFEgIgs6v+ZXKni+Uy6rtBlqfgbKbaERW/Vm1 6qpTNdPApqL8ttGC58JdO2m32ISLCxCp9lgTqt9qHVEM5Up+KJ6s0837mtLlEEer5Jsp rOSTtj0S66wvuhJZPTQdev8Lo0+ur6L7tvlxGIivcI9PdXalv+tXMPK8VVVm07MRaSY+ Xpa6gf2FjPZt7rm3pfMZsc/bYGSzbyaNjnOpJwKjfwxjese1IJa7Fb30PIGk8rXsxBzd GVDlAcjlEOIQzv8J5MLmfVjLTgvBWDa966RLFV0DKx+6MjGRW+1gBUbxkQLeNw+jz4iA f0wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=V0f1W4Wc0EEoXA/hJdBQxq1Gp1glgbsbboI5sHwm0rI=; b=lfsp0olEE4iRuelhXa8qHyAm8v5KTHNeFG3UMG+SfMMo2C64sbFU83yLfkmgeHMRRs EjD6LaSkOlCHf9fXoyUsSvUXQwc7RCbrRtF3Pphy6fVSecEwgTZuQ97K1uN25cQQuiEK FX9YFqfdNYxEq/oSmeRrlQjIFFn0TWbZKXuV2F9Bb80wGdDKgZuMjirQ8cBKdPUTI5kN y+vLvivXSM6eH/6vc6desNAeh0Xemv2p7yi8YZSmg6feZ1lJq/s52SR+b+o5zk53kDqJ lD69LJnzjTSTmPMdpaI+mAZXuh8IzeUD/j+s2+rRwCsn2HzSO7/ZsPqGk9teGAg1A+WH 3y+g== X-Gm-Message-State: AOAM530pBdf/nk9FVvdsFvSXKeitJf4bZOyb7fmPxcQSDaOSXduHrLO2 IYjMzZ0TFRPqlPMjreYfjgVQYke9IPVhQBXRCsVpWQ== X-Received: by 2002:adf:cd04:0:b0:1f0:d63:392c with SMTP id w4-20020adfcd04000000b001f00d63392cmr173680wrm.489.1646086251275; Mon, 28 Feb 2022 14:10:51 -0800 (PST) MIME-Version: 1.0 References: <20220225234339.2386398-1-haoluo@google.com> <20220225234339.2386398-2-haoluo@google.com> <20220227051821.fwrmeu7r6bab6tio@apollo.legion> In-Reply-To: <20220227051821.fwrmeu7r6bab6tio@apollo.legion> From: Hao Luo Date: Mon, 28 Feb 2022 14:10:39 -0800 Message-ID: Subject: Re: [PATCH bpf-next v1 1/9] bpf: Add mkdir, rmdir, unlink syscalls for prog_bpf_syscall To: Kumar Kartikeya Dwivedi Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Shakeel Butt , Joe Burton , Tejun Heo , joshdon@google.com, sdf@google.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-18.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Hi Kumar, On Sat, Feb 26, 2022 at 9:18 PM Kumar Kartikeya Dwivedi wrote: > > On Sat, Feb 26, 2022 at 05:13:31AM IST, Hao Luo wrote: > > This patch allows bpf_syscall prog to perform some basic filesystem > > operations: create, remove directories and unlink files. Three bpf > > helpers are added for this purpose. When combined with the following > > patches that allow pinning and getting bpf objects from bpf prog, > > this feature can be used to create directory hierarchy in bpffs that > > help manage bpf objects purely using bpf progs. > > > > The added helpers subject to the same permission checks as their syscall > > version. For example, one can not write to a read-only file system; > > The identity of the current process is checked to see whether it has > > sufficient permission to perform the operations. > > > > Only directories and files in bpffs can be created or removed by these > > helpers. But it won't be too hard to allow these helpers to operate > > on files in other filesystems, if we want. > > > > Signed-off-by: Hao Luo > > --- > > + * > > + * long bpf_mkdir(const char *pathname, int pathname_sz, u32 mode) > > + * Description > > + * Attempts to create a directory name *pathname*. The argument > > + * *pathname_sz* specifies the length of the string *pathname*. > > + * The argument *mode* specifies the mode for the new directory. It > > + * is modified by the process's umask. It has the same semantic as > > + * the syscall mkdir(2). > > + * Return > > + * 0 on success, or a negative error in case of failure. > > + * > > + * long bpf_rmdir(const char *pathname, int pathname_sz) > > + * Description > > + * Deletes a directory, which must be empty. > > + * Return > > + * 0 on sucess, or a negative error in case of failure. > > + * > > + * long bpf_unlink(const char *pathname, int pathname_sz) > > + * Description > > + * Deletes a name and possibly the file it refers to. It has the > > + * same semantic as the syscall unlink(2). > > + * Return > > + * 0 on success, or a negative error in case of failure. > > */ > > > > How about only introducing bpf_sys_mkdirat and bpf_sys_unlinkat? That would be > more useful for other cases in future, and when AT_FDCWD is passed, has the same > functionality as these, but when openat/fget is supported, it would work > relative to other dirfds as well. It can also allow using dirfd of the process > calling read for a iterator (e.g. if it sets the fd number using skel->bss). > unlinkat's AT_REMOVEDIR flag also removes the need for a bpf_rmdir. > > WDYT? > The idea sounds good to me, more flexible. But I don't have a real use case for using the added 'dirfd' at this moment. For all the use cases I can think of, absolute paths will suffice, I think. Unless other reviewers have opposition, I will try switching to mkdirat and unlinkat in v2.