Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp44797pxp; Tue, 15 Mar 2022 23:18:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmRBOHMGpxuWqAIfdyNQdYvyrWvgzOXjG9oEwEgTVKX7HKulod9QnoDxsr50o91iEsxBRD X-Received: by 2002:a17:906:b287:b0:6ce:98af:3f6e with SMTP id q7-20020a170906b28700b006ce98af3f6emr24708324ejz.216.1647411534475; Tue, 15 Mar 2022 23:18:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647411534; cv=none; d=google.com; s=arc-20160816; b=Gwxwro6XWCbD6zTzt7j4wvYWAGKkil1/0JgPKhJlGiZ2gC73xJvhG0r9+GHpK8/PMr GjUNzal2ZFsfvpY2TWcy7zanKI1NoNpx0aNHvss3o/UcCqMX4ytopZqIKFH3pfcDcoGs w3uA4GyvbB8rYApXQ+XOSpAHDAychQU1VdNzAVSSMDgSshhs1BAt2DPR3hjV8mpXhtZo VmtfY+BnW2u97TQ7K0PgjVchiX5evChUpGDB9gzQc29U6ILEWjoOx1yTyOA6/R2XFATi u49RnEXrvXJFDm7ZMhWO+2N/oofx4e8j6tNZNUOewUZOuRlsOOH6etsRjPu99sDhn64V WcdA== 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=P75noemU3nNM9QREmpWEOIwo6AUAf43zc7dC9ZROgxU=; b=ij9d5bT9qWN8X+3jYoMqugZtsPdhGU8ngLQ4t1p5b5RB98Pzl3pZjEFzzikmCqh5kH o9VZ/R8fc+4LZ6jBLATgSbQadFdSHFolj0uaFF/vs2jc2LeZ+8ckS/KLUiBKdhSpKfDy 37B1S/tsVkkpjj0ESwPjkY03+XOr4mYLZCOy4cYbUi8SEtlMfVcuNpv28hc1TuODEGVH nAEDqz+4/JXq3xy6BaMRztoOXrZHdpIbXCufvW+vLUiZvUyAWZ8E7CT9KijzdJjN/qyc VkgZvxhqVe6K0h24AYT/8aEGR3O8Rhi+fsz8bdJEWs/U5wyZ94w9J1G6DNXtsNPc13x3 jatw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ieoeLFUC; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bk23-20020a170906b0d700b006dab4a377f7si616546ejb.726.2022.03.15.23.18.15; Tue, 15 Mar 2022 23:18:54 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=ieoeLFUC; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351181AbiCOTBB (ORCPT + 99 others); Tue, 15 Mar 2022 15:01:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343730AbiCOTBA (ORCPT ); Tue, 15 Mar 2022 15:01:00 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78DF650E32; Tue, 15 Mar 2022 11:59:48 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id e3so255626pjm.5; Tue, 15 Mar 2022 11:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P75noemU3nNM9QREmpWEOIwo6AUAf43zc7dC9ZROgxU=; b=ieoeLFUClHFCNmE61XYmhfqH7JJ9Y6zrtBkhzQvZc/mecvz4an6xlpq4SFiDPrN3Ga Dnm9xmvDjgGJf2MJtScduCG7fQlWJ4eXHclFNRPyswzAyro8UryJAnQD+N06b+7BKqp/ 8WFC8eLzZiLB8dWerH2e40Zs6h+1UV7LfToNHVO9tGakihPBLG2vgOaoVfGtAa/5iegr kcp/jkm7hFDZ99GMAu3d3l2JE3HvS+nJwMrrAWu60POVVSE5ascgZjj8PYqbRB+koYw/ furxvYiQ2zosuFLWXlANqaqK+rvAGE+868qVRctXNOykYG66OEBj8UPGibuqfJNU41q4 6gxQ== 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=P75noemU3nNM9QREmpWEOIwo6AUAf43zc7dC9ZROgxU=; b=4z3NUxGsrqGqxOpr+NeOJjJtlqOOFdLxHyRlOpKeGFsS6tazDIhY5/yWWf3f+GvUZw i2M+u4FFdy9Z+WxReN0Xu6c9pA9hRaQDZrFmjQoWrQc8HQSJnOkt/2Oqt+tF8WOpH6iO TAIsbZSwVZdIHxzjqoXknYMFgSRQ/YAEU3Jb7kDVehL5/Ksumo6e2dJOUAClKVcuBRVv 2Ot2IK8V7xhDiF0Rdw7/kvjzoA7VW2cvVPTmYmJ/npW7iXO08+99N9HHP/KTvmtwUHyb TimWPZwDWEbigAqGKiYcI14UmZ2CQ8MHCcG7U46uwp9iLHx8GfGzvRoAN5iK2LybQNhD 4tHQ== X-Gm-Message-State: AOAM5331qVmPJMtfy22yh+LTJ1KN1EoeuLmVF8rbLaZ1fh6pHCEiWUrQ I9crjV/khUDwl+J/lqNQP4w6yx/x2ruJ1xG/9Ec= X-Received: by 2002:a17:903:32d2:b0:153:9c6a:5750 with SMTP id i18-20020a17090332d200b001539c6a5750mr4104519plr.34.1647370787936; Tue, 15 Mar 2022 11:59:47 -0700 (PDT) MIME-Version: 1.0 References: <20220225234339.2386398-1-haoluo@google.com> <20220225234339.2386398-2-haoluo@google.com> In-Reply-To: From: Alexei Starovoitov Date: Tue, 15 Mar 2022 11:59:36 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1 1/9] bpf: Add mkdir, rmdir, unlink syscalls for prog_bpf_syscall To: Hao Luo Cc: Al Viro , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Shakeel Butt , Joe Burton , Tejun Heo , Josh Don , Stanislav Fomichev , bpf , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Tue, Mar 15, 2022 at 10:27 AM Hao Luo wrote: > > On Mon, Mar 14, 2022 at 4:12 PM Al Viro wrote: > > > > On Mon, Mar 14, 2022 at 10:07:31AM -0700, Hao Luo wrote: > > > Hello Al, > > > > > > In which contexts can those be called? > > > > > > > > > > In a sleepable context. The plan is to introduce a certain tracepoints > > > as sleepable, a program that attaches to sleepable tracepoints is > > > allowed to call these functions. In particular, the first sleepable > > > tracepoint introduced in this patchset is one at the end of > > > cgroup_mkdir(). Do you have any advices? > > > > Yes - don't do it, unless you really want a lot of user-triggerable > > deadlocks. > > > > Pathname resolution is not locking-agnostic. In particular, you can't > > do it if you are under any ->i_rwsem, whether it's shared or exclusive. > > That includes cgroup_mkdir() callchains. And if the pathname passed > > to these functions will have you walk through the parent directory, > > you would get screwed (e.g. if the next component happens to be > > inexistent, triggering a lookup, which takes ->i_rwsem shared). > > I'm thinking of two options, let's see if either can work out: > > Option 1: We can put restrictions on the pathname passed into this > helper. We can explicitly require the parameter dirfd to be in bpffs > (we can verify). In addition, we check pathname to be not containing > any dot or dotdot, so the resolved path will end up inside bpffs, > therefore won't take ->i_rwsem that is in the callchain of > cgroup_mkdir(). > > Option 2: We can avoid pathname resolution entirely. Like above, we > can adjust the semantics of this helper to be: making an immediate > directory under the dirfd passed in. In particular, like above, we can > enforce the dirfd to be in bpffs and pathname to consist of only > alphabet and numbers. With these restrictions, we call vfs_mkdir() to > create directories. > > Being able to mkdir from bpf has useful use cases, let's try to make > it happen even with many limitations. Option 3. delegate vfs_mkdir to a worker and wait in the helper.