Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1261750

Re: [PATCH] namei: permit linking with CAP_FOWNER in userns

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject Re: [PATCH] namei: permit linking with CAP_FOWNER in userns
Date Tue, 03 Nov 2015 19:00:03 +0100
Message-ID <qqO2f-5XS-23@gated-at.bofh.it> (permalink)
References <qi46e-4HV-25@gated-at.bofh.it>
X-Original-To Dirk Steinmetz <public@rsjtdrjgfuzkfg.com>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=bPWmrm4PE7LADcGuDFF3EkLjjsfVZLSYYBt74GAI7Ls=; b=k8DBV5QNs6eVCzLiu8cs109R/YOx4xgN1tStnhahsyBjsBtyYMgFywnyVlAef1TyXC Idg0ch/rmVMOAPBebjgsqva8yY519xvWWMX5nCxPD6YKwCRIIN43R/J4Y+TlVyGIwujf GsYkwLHJl4i9Zn/BkN9GDWxEWbxAkOubr0E4+MuQWTUlCejv6NVn6pqxSHipdNxt4n/S G6rzkWw5ZSAeZe6Ar50PjxFjmKZPrlsO/hwgexZgO9x8uIyJnqAALv8tjJnc1orN8dky 4H6pFrqG3uthy0xzhHpG6fptcs5cy1Q7zDYJjUGLFhAmF3LwvJhhc2+Qe3S7dB7HxOnf 6VXg==
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=bPWmrm4PE7LADcGuDFF3EkLjjsfVZLSYYBt74GAI7Ls=; b=BIsqJzU1vmK1zd13ZLa5p3Na1aW6cyu/8oW+rh3aV1nudyDR5XTY9uq0eNX3uMo2/q /kb587MfeVr9Knyf810JpBTkGhjlcmWGSedRDJRELZUoR9SQh53lQLu2jMkwbAzYQDzL TSY462Jb/o1OqBnLwE6w8LK8je3lCU6cp4w5w=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=bPWmrm4PE7LADcGuDFF3EkLjjsfVZLSYYBt74GAI7Ls=; b=Q7VpUSBQJ5e03cmRW9RyJvArCCYYjwQIvYItfze/nwpM4z0LJ6JNel6UuoZmqeh6JP s1JfLx4pa+p34+YRBuEN1ERH+tOrUgbXDElq2X8DxUls82w9cjcAePV2TnRutOBq4WeP XcKHHfLvx2PKB7CuExppP2sBe583G3qebPYyIo116UoofyKoh+KMsSQf49TjQcMwIZFB spTgasPz+wu46FhhELli3lYoS8baKQLrvj8KYjsnsE7nsaYIlqB9oqOoSQ9zYr1yp8Bf +8PwErTAUv1gqFE82MH5BcTjt86NYLhk0VkDWpkr9mOLFGd4uMx4wPk7KwfRDVtFPGM6 /stA==
X-Gm-Message-State ALoCoQko7YjkV/Cpp2mLuXTfBOgQIqNRUCISptguLLbN9LZYa/gv5twl3lkXPJPnZqCgOEBOdjvX
MIME-Version 1.0
X-Received by 10.50.65.101 with SMTP id w5mr18961024igs.3.1446573066474; Tue, 03 Nov 2015 09:51:06 -0800 (PST)
X-Google-Sender-Auth cwWbhvwr5b9EsOih62iLeqtKyKU
Content-Type text/plain; charset=UTF-8
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 84
Organization linux.* mail to news gateway
X-Original-Cc "Eric W. Biederman" <ebiederm@xmission.com>, Alexander Viro <viro@zeniv.linux.org.uk>, "linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org>, Andy Lutomirski <luto@amacapital.net>, Serge Hallyn <serge.hallyn@ubuntu.com>, Seth Forshee <seth.forshee@canonical.com>
X-Original-Date Tue, 3 Nov 2015 09:51:06 -0800
X-Original-Message-ID <CAGXu5jLsYCmpR0=WhL3H6AL71ATJFtRRYwcko_eAA=Ve=0Skbg@mail.gmail.com>
X-Original-References <1444489163-24266-1-git-send-email-public@rsjtdrjgfuzkfg.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1261750

Show key headers only | View raw


On Sat, Oct 10, 2015 at 7:59 AM, Dirk Steinmetz
<public@rsjtdrjgfuzkfg.com> wrote:
> Attempting to hardlink to an unsafe file (e.g. a setuid binary) from
> within an unprivileged user namespace fails, even if CAP_FOWNER is held
> within the namespace. This may cause various failures, such as a gentoo
> installation within a lxc container failing to build and install specific
> packages.
>
> This change permits hardlinking of files owned by mapped uids, if
> CAP_FOWNER is held for that namespace. Furthermore, it improves consistency
> by using the existing inode_owner_or_capable(), which is aware of
> namespaced capabilities as of 23adbe12ef7d3 ("fs,userns: Change
> inode_capable to capable_wrt_inode_uidgid").
>
> Signed-off-by: Dirk Steinmetz <public@rsjtdrjgfuzkfg.com>

Sorry for the delay: was travelling when I got put on CC. (FWIW, in
the future, please check the scripts/get_maintainer.pl script with
--git-blame to build CC lists, then I would have been CCed earlier.)

I think Eric's already taken this patch, but it looks correct to me:

Acked-by: Kees Cook <keescook@chromium.org>

I'll hop on the other thread to discuss the setgid issue.

-Kees

> ---
>  fs/namei.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index 726d211..29fc6a6 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -955,26 +955,23 @@ static bool safe_hardlink_source(struct inode *inode)
>   *  - sysctl_protected_hardlinks enabled
>   *  - fsuid does not match inode
>   *  - hardlink source is unsafe (see safe_hardlink_source() above)
> - *  - not CAP_FOWNER
> + *  - not CAP_FOWNER in a namespace with the inode owner uid mapped
>   *
>   * Returns 0 if successful, -ve on error.
>   */
>  static int may_linkat(struct path *link)
>  {
> -       const struct cred *cred;
>         struct inode *inode;
>
>         if (!sysctl_protected_hardlinks)
>                 return 0;
>
> -       cred = current_cred();
>         inode = link->dentry->d_inode;
>
>         /* Source inode owner (or CAP_FOWNER) can hardlink all they like,
>          * otherwise, it must be a safe source.
>          */
> -       if (uid_eq(cred->fsuid, inode->i_uid) || safe_hardlink_source(inode) ||
> -           capable(CAP_FOWNER))
> +       if (inode_owner_or_capable(inode) || safe_hardlink_source(inode))
>                 return 0;
>
>         audit_log_link_denied("linkat", link);
> --
> 2.1.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/



-- 
Kees Cook
Chrome OS Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

Re: [PATCH] namei: permit linking with CAP_FOWNER in userns Kees Cook <keescook@chromium.org> - 2015-11-03 19:00 +0100

csiph-web