Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1270383pxb; Fri, 21 Jan 2022 13:58:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5GtsQvEhh4INE+nt3e/nIBGuGW4NvI1P2wpbMrmVOoOrjgITnA1eFLKYwdqmxFapIH7p/ X-Received: by 2002:a63:725b:: with SMTP id c27mr4206856pgn.481.1642802307369; Fri, 21 Jan 2022 13:58:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642802307; cv=none; d=google.com; s=arc-20160816; b=bawEH5B5Vhxotk0eTFwSn/swNCD95odf71JevZ5Z8BSJQyaVRS3iY5dB82JF1NkqsY 5O5y+3LVMCdpp4IxXBFUrWIICDLloGVxifkRp4Drd7cphyEW2KHX27LFnoPWwKu88YbB AG98DciBrmIWmic65+9p0ZlWVSnHzBuONmOwLpxkCqYekLScLbEeF2JVK4q1U+p2zfRm e/LP4qoqw00uKWERnHYoEU75yDCLlmG72oEw9XTDNDf0OAkJCgCjuP6pSOfojO7aLkUI zQzNbuZ2utKskQ7P5agjd2esqOzVE4KdSiz4FPVZgNrgnEFQt3IJsDAnfH5p7RZo6MKO xyqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SKRq4lKenw91+Znt4tUNU3j+2p6da+FhYVba+8njzzI=; b=o3+EmshVc4u/jTHa0kn9OBfmKOgF+BREkp08YxT1/HzrhkY6JbFG0RoMiS7QfyNSgr hEiZSfS3MZnv2oSkfAG9FaIiUp3v/NPtLwZDqjcyVgQaJV3U4DbxLBumTkpvE67yGQHI 5PlLr7Hq/EfghIrUnlm19/3oqGBjZ+SgDDjT1BDJkv+KrDlbnPxxtc3IxgBM5wW/ziFr Gv0STQ1CzLu+xOaPXyA58N6/SsEcaFo2zSiVWO2xJ7Yw8pIhe0/2K6+gJXmpWn2w4ILA eN1THMqO05pEacLj8RX/wFQo0evwuZPZQ7iOLcWebZgWCABbrweqsqg4XwmeiRt0RVia K/LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R7MxVWj3; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y12si3843023pjf.91.2022.01.21.13.58.15; Fri, 21 Jan 2022 13:58:27 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=R7MxVWj3; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241784AbiATM0c (ORCPT + 99 others); Thu, 20 Jan 2022 07:26:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232146AbiATM0b (ORCPT ); Thu, 20 Jan 2022 07:26:31 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DFA2C061574; Thu, 20 Jan 2022 04:26:31 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id m4so27843702edb.10; Thu, 20 Jan 2022 04:26:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=SKRq4lKenw91+Znt4tUNU3j+2p6da+FhYVba+8njzzI=; b=R7MxVWj3C09fc5Sb9LAqGxKYKTxKNj6ahxflEXwLVZ5le/dxNP7ddIVbJEoKWtfUm7 nk5OJlNAQWYkYy4TCMUxawa5fwLmn285AAfAD2+/powo/MH0cw7zWxAztrK8F9GssCow psC51Lii4mJL3CHqO0tueRySo5atmAa5U0jBjE1q8iDYHLcNl/fFole+fECq25umr5mj MSGPntPqb6bJ6POwqlyvlT6dlHoU537LW66wteMDKCFOwV/0utA+J6vV72RHtHcOE92L OQlp+I2KFLLfNtX/8e7JH4AJQKIe092YxU4mSHgjuy4Z8s1LEJy9fBeKVG2R52dOHHbD QusQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=SKRq4lKenw91+Znt4tUNU3j+2p6da+FhYVba+8njzzI=; b=RpDe09hzj8jE9BVMgB1koOqV9tJ+fuX4Zj5qE3v/z01l/5wa8woUZxxRe7BWvP4fa8 6YCRp8yY4kIbiHCVxvZQmJxcS5WpbmnAYU0RpqWl6MjYHwLEX6awZteRTDlc9W/ZEQBP 6kCzBUZYS+5p/YWSb7bZkfyxJmL+xE0XRaZWhh8wu16eqS3UDmRbeAd7td8ftJZJwpYp 00WXmPAtcpHw7FMJ/xBmwK/p+xOkOG8S5j5fbK4wtvu3xdPV0QsMx6gXJWuMyvHGIVvp 1UT+sozTM3TcqtqHPK9kGM4hGb3/j0pf4ysxXMo1N/nhZCgrTWBHEyggX6d1f0FzTzKE BkRQ== X-Gm-Message-State: AOAM531fmQ956KSAn0t0Jfb3FL870rdmpGyQgpZ62ZOJp7TyEcwxWAUN HOOfnnvQCg2H/QgwOqmyiQ== X-Received: by 2002:a05:6402:27cd:: with SMTP id c13mr36480249ede.137.1642681589590; Thu, 20 Jan 2022 04:26:29 -0800 (PST) Received: from localhost.localdomain ([46.53.254.155]) by smtp.gmail.com with ESMTPSA id c7sm941576ejm.204.2022.01.20.04.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 04:26:29 -0800 (PST) Date: Thu, 20 Jan 2022 15:26:27 +0300 From: Alexey Dobriyan To: Alexey Gladkov Cc: viro@zeniv.linux.org.uk, ebiederm@xmission.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, stephen.s.brennan@oracle.com Subject: Re: [PATCH v2] proc: "mount -o lookup=" support Message-ID: References: <20220119170432.oxxaazjwvf4q6xvh@example.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220119170432.oxxaazjwvf4q6xvh@example.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 19, 2022 at 06:04:32PM +0100, Alexey Gladkov wrote: > On Wed, Jan 19, 2022 at 06:48:03PM +0300, Alexey Dobriyan wrote: > > >From 61376c85daab50afb343ce50b5a97e562bc1c8d3 Mon Sep 17 00:00:00 2001 > > From: Alexey Dobriyan > > Date: Mon, 22 Nov 2021 20:41:06 +0300 > > Subject: [PATCH 1/1] proc: "mount -o lookup=..." support > > > > Docker implements MaskedPaths configuration option > > > > https://github.com/estesp/docker/blob/9c15e82f19b0ad3c5fe8617a8ec2dddc6639f40a/oci/defaults.go#L97 > > > > to disable certain /proc files. It overmounts them with /dev/null. > > > > Implement proper mount option which selectively disables lookup/readdir > > in the top level /proc directory so that MaskedPaths doesn't need > > to be updated as time goes on. > > > > Syntax is > > > > Filter everything > > # mount -t proc -o lookup=/ proc /proc > > # ls /proc > > dr-xr-xr-x 8 root root 0 Nov 22 21:12 995 > > lrwxrwxrwx 1 root root 0 Nov 22 21:12 self -> 1163 > > lrwxrwxrwx 1 root root 0 Nov 22 21:12 thread-self -> 1163/task/1163 > > > > Allow /proc/cpuinfo and /proc/uptime > > # mount -t proc proc -o lookup=cpuinfo/uptime /proc > > > > # ls /proc > > ... > > dr-xr-xr-x 8 root root 0 Nov 22 21:12 995 > > -r--r--r-- 1 root root 0 Nov 22 21:12 cpuinfo > > lrwxrwxrwx 1 root root 0 Nov 22 21:12 self -> 1163 > > lrwxrwxrwx 1 root root 0 Nov 22 21:12 thread-self -> 1163/task/1163 > > -r--r--r-- 1 root root 0 Nov 22 21:12 uptime > > > > Trailing slash is optional but saves 1 allocation. > > Trailing slash is mandatory for "filter everything". > > > > Remounting with lookup= is disabled so that files and dcache entries > > don't stay active while filter list is changed. Users are supposed > > to unmount and mount again with different lookup= set. > > Remount rules may change in the future. (Eric W. Biederman) > > > > Re: speed > > This is the price for filtering, given that lookup= is whitelist it is > > not supposed to be very long. Second, it is one linear memory scan per > > lookup, there are no linked lists. It may be faster than rbtree in fact. > > It consumes 1 allocation per superblock which is list of names itself. > > > > Signed-off-by: Alexey Dobriyan > > --- > > > > v2 > > documentation! > > descriptive comments! > > disable remount > > > > Documentation/filesystems/proc.rst | 8 ++ > > fs/proc/generic.c | 18 ++-- > > fs/proc/internal.h | 31 ++++++- > > fs/proc/proc_net.c | 2 +- > > fs/proc/root.c | 127 ++++++++++++++++++++++++++++- > > include/linux/proc_fs.h | 2 + > > 6 files changed, 178 insertions(+), 10 deletions(-) > > > > diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst > > index 8d7f141c6fc7..9a328f0b4346 100644 > > --- a/Documentation/filesystems/proc.rst > > +++ b/Documentation/filesystems/proc.rst > > @@ -2186,6 +2186,7 @@ The following mount options are supported: > > hidepid= Set /proc// access mode. > > gid= Set the group authorized to learn processes information. > > subset= Show only the specified subset of procfs. > > + lookup= Top-level /proc filter, independent of subset= > > Will it be possible to combine lookup= and subset= options when mounting? Currently only subset=pid is implemented, which is equivalent to mount -t proc -o lookup=/ proc /proc In the future subset= might expand and lookup= could filter whatever exposed. > > +lookup= mount option makes available only listed files/directories in > > +the top-level /proc directory. Individual names are separated > > +by slash. Empty list is equivalent to subset=pid. lookup= filters before > > +subset= if both options are supplied. lookup= doesn't affect /proc/${pid} > > +directories availability as well as /proc/self and /proc/thread-self > > +symlinks. More fine-grained filtering is not supported at the moment.