Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp813241imm; Fri, 11 May 2018 06:50:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqD1K9SMJwhFA+1fSBkaTAlcD+rw+pCVqsxUssJwpfxVzruFRpMiDCjowpwdsCn6U3zHsbv X-Received: by 2002:a63:5fd2:: with SMTP id t201-v6mr4603145pgb.315.1526046636403; Fri, 11 May 2018 06:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526046636; cv=none; d=google.com; s=arc-20160816; b=GCd4QheNXY5S5HiTKEEifukfxrl0lVnDpMjTx535vQ40GqWNR4XRnse6PXaOCYAjNS 3wBzfgrQXsHvsYzr+dzYIfLndjB06ruk6TuZdcWPcWDvfcOBMU/qo0nWwp5MjmkO685J 2AHx9+qtn+LuwDFM+W92uxaZXAzQHjPrVvBmZ+qF7huBI2P+PumwJ+SGqcRIp3XwZ1M9 L6QpYWJ1nSEnG3jFZVl7uLrnX+Bdn7saGzxnVgwubtjFqLMv7QbVbAbivaq8+uvFfci7 xfHPJaAx21yvvRQRMjM8TDe8V1YTTp7zXONb2cH+quVIkxUSnUzDfdWzuc+I9ZxYObb8 0P2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=lLNLQnagQvuayT8xM+wRhjYSJXxn8OQIF9JjRXkZQLU=; b=Tkobr8hDbXA0zojxvUQA7zylS4QYHjiZSWyia+D/e0RsvgEGHrpV89U0yxYLHvMxph Gi0fjycnGJaGA/BO1hk9YVnnGK7ZrsTqA2dy43ZxXqTQy8sEBVnuBEe2WlyZxX9MITgC C29VkkezqYJbinQX9M4oTBepsNfxB8Mz37V+xOKS3SPlM/Ym8wQyvw2XN1aZo1b21Iqj zG1Y30Pi8dlqhZhKQNC0cgJsDxbGXIqruYa5ijkkjbPtnsyDugUCwCI6+eoh6F83hcw/ Aso60O3NrcvNQC50OqjCidlsJTXcq/BMyxrBDL0tTOhOiVKV65pkxpeBMa5PTTZMS1OD my9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=u5pURFmC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si3328024plt.98.2018.05.11.06.49.52; Fri, 11 May 2018 06:50:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=u5pURFmC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1753287AbeEKNti (ORCPT + 99 others); Fri, 11 May 2018 09:49:38 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:41271 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753133AbeEKNte (ORCPT ); Fri, 11 May 2018 09:49:34 -0400 Received: by mail-oi0-f66.google.com with SMTP id 11-v6so4750853ois.8 for ; Fri, 11 May 2018 06:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=lLNLQnagQvuayT8xM+wRhjYSJXxn8OQIF9JjRXkZQLU=; b=u5pURFmCOv1fndNoIyyxLE6dahQzGagZ0jBXoqcriA90VqOkQUHdBM8kn7tGzD2n7d 4EYkH6bzJ7MbUVXH2C3z7DEQppV5qECZwirXLuf41Eo4F076SaWAJdR0By7EJ4UNteI5 NmJ3b4UthgoIr0nv8XV0k8KN872zdp4AA5BKE8X8MdgG8b8o1y1z0vVTikjA/CwJsMVc pKgJto39HDTVcYxwwQoE9u2vnzUm8bMP5pJXo+CCQyJ96A43HYNJnXh9imW7fu77jOm2 9CTGa7A/hkU9L4wDCI7fBvpX9k5AqwhAeqXTyRrv6lv8CguVLkerBPlqwfspY0ujU11N 00sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=lLNLQnagQvuayT8xM+wRhjYSJXxn8OQIF9JjRXkZQLU=; b=qu1n2fw+zsUwfNzHQBHbDLkAejYZEsV5dEHniZlImAHfuqjJTVkg1zZdJaQumExrQ+ DbsziA4SSc89pn0HTqxiUD3+QqcUND5RPRa8jj2o98oaCHHDvf2V3qI1T6SuIxWKFulg ls2Ii1XGKzRJJnF3ay9jR2QFrsoRZ6JBVUhP5v8MAlMPf3GKgg6TWVe7cNi/Wy/KD8Bd ZB63U99p9+edYmEL1jDrGVj119GFgoErsWhrXlfl5IhWZGhD+8ALrMslO/HZa4AKcw+u 1vZ2qvo7E0HfWbrqWKuaEtGCNhWWIlbQMuVpHfBEr7lZyu9pAiK4librkojaAKfVgKSJ u/YQ== X-Gm-Message-State: ALKqPwfVJ7SQw16+csZm8uxczOxY8PwaBxAdX17QxpsxTSwl7GXHNwtW wRz/FUL5YI51ucFFqQdlLaWZlbuTAUcRlyYkS2/qNA== X-Received: by 2002:aca:6002:: with SMTP id u2-v6mr3389348oib.323.1526046573657; Fri, 11 May 2018 06:49:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.145.144 with HTTP; Fri, 11 May 2018 06:49:13 -0700 (PDT) In-Reply-To: <20180511093445.GA1008@comp-core-i7-2640m-0182e6> References: <20180511093445.GA1008@comp-core-i7-2640m-0182e6> From: Jann Horn Date: Fri, 11 May 2018 15:49:13 +0200 Message-ID: Subject: Re: [PATCH v5 1/7] proc: add proc_fs_info struct to store proc information To: Alexey Gladkov Cc: Kees Cook , Andy Lutomirski , Andrew Morton , linux-fsdevel@vger.kernel.org, kernel list , Kernel Hardening , linux-security-module , Linux API , Greg Kroah-Hartman , Alexander Viro , Akinobu Mita , Oleg Nesterov , Jeff Layton , Ingo Molnar , Alexey Dobriyan , "Eric W. Biederman" , Linus Torvalds , aniel Micay , Jonathan Corbet , bfields@fieldses.org, Stephen Rothwell , Solar Designer , "Dmitry V. Levin" , Djalal Harouni Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 11, 2018 at 11:34 AM, Alexey Gladkov wrote: > From: Djalal Harouni > > This is a preparation patch that adds proc_fs_info to be able to store > different procfs options and informations. Right now some mount options > are stored inside the pid namespace which makes it hard to change or > modernize procfs without affecting pid namespaces. Plus we do want to > treat proc as more of a real mount point and filesystem. procfs is part > of Linux API where it offers some features using filesystem syscalls and > in order to support some features where we are able to have multiple > instances of procfs, each one with its mount options inside the same pid > namespace, we have to separate these procfs instances. > > This is the same feature that was also added to other Linux interfaces > like devpts in order to support containers, sandboxes, and to have > multiple instances of devpts filesystem [1]. > > [1] http://lxr.free-electrons.com/source/Documentation/filesystems/devpts.txt?v=3.14 > > Cc: Kees Cook > Suggested-by: Andy Lutomirski > Signed-off-by: Djalal Harouni > Signed-off-by: Alexey Gladkov > --- [...] > static struct dentry *proc_mount(struct file_system_type *fs_type, > int flags, const char *dev_name, void *data) > { > + int error; > + struct super_block *sb; > struct pid_namespace *ns; > + struct proc_fs_info *fs_info; > + > + /* > + * Don't allow mounting unless the caller has CAP_SYS_ADMIN over > + * the namespace. > + */ > + if (!(flags & MS_KERNMOUNT) && !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) > + return ERR_PTR(-EPERM); Is this correct? The old code invoked a check with the same comment through mount_ns(); however, this patch changes the semantics of the check. The old code checked that the caller has privileges over the user namespace that contains the PID namespace; in other words, it checked that the caller has privileges over the PID namespace. The current code just checks that the caller is privileged over its own user namespace. As far as I can tell, this means that by doing something like this: unshare(CLONE_NEWNS|CLONE_NEWUSER); mount("none", "/", NULL, MS_REC|MS_PRIVATE, NULL); mount("proc", "/proc", "proc", 0, "newinstance,pids=all"); any process could create a new unrestricted procfs mount for its PID namespace, even if it is only supposed to have access to a more restricted procfs mount. > + fs_info = kzalloc(sizeof(*fs_info), GFP_NOFS); > + if (!fs_info) > + return ERR_PTR(-ENOMEM); > > if (flags & SB_KERNMOUNT) { > ns = data; > @@ -98,20 +128,47 @@ static struct dentry *proc_mount(struct file_system_type *fs_type, > ns = task_active_pid_ns(current); > } > > - return mount_ns(fs_type, flags, data, ns, ns->user_ns, proc_fill_super); > + fs_info->pid_ns = ns; > + > + sb = sget_userns(fs_type, proc_test_super, proc_set_super, flags, > + ns->user_ns, fs_info); > + if (IS_ERR(sb)) { > + error = PTR_ERR(sb); > + goto error_fs_info; > + } > + > + if (sb->s_root) { > + kfree(fs_info); > + } else { > + error = proc_fill_super(sb, data, flags & MS_SILENT ? 1 : 0); > + if (error) { > + deactivate_locked_super(sb); > + goto error; > + } > + > + sb->s_flags |= MS_ACTIVE; > + } > + > + return dget(sb->s_root); > + > +error_fs_info: > + kfree(fs_info); > +error: > + return ERR_PTR(error); > }