Received: by 10.223.185.116 with SMTP id b49csp1750142wrg; Thu, 22 Feb 2018 02:27:28 -0800 (PST) X-Google-Smtp-Source: AH8x226JI/ClwX5flR4N2lwc5Q6ijPYz8xBhZC5tSfe2s31EIZHgNNs14Xr9a7ohnwDWE9Gl3xY5 X-Received: by 10.98.69.76 with SMTP id s73mr2484059pfa.31.1519295248784; Thu, 22 Feb 2018 02:27:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519295248; cv=none; d=google.com; s=arc-20160816; b=PDXybEMHR2kcohi9MeCjFWQiFfYbTBYOVVGxWPvm+iJbFrfst1sm9eoI8olFPM3QeE W1I//i/kZM1dAFSv/Kr/GNX79ILV1xlcv9zp2jGZLXboNW5QK2d5iir0qGpP42dg69C/ idJxqCTqJluSX0m8qJbKY67zqgVKVS/2C72b9kfAtiP0Ai7pO3OCJaQregJf8z5p3iNV HU5hWt3skuBwI133wdVgHm47FD4MsNcB1LhzSGr8l5I9zw9bXMxMvnbvHU6nmW5HPX1q ZB+Ic0mg5u4sCmvJEZnUY6cYQkTAgWxZE68K+/uswgrlkTV13MedFhezwXCv9NDxo4oO rU8Q== 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:arc-authentication-results; bh=H8Djuy62nrAjw7bVVfb55UX8FQ1hSZXpfRRROXGpytU=; b=rjRyRmXXo16M5LEPcOhiAosJJthx0eLk349ZRg6wTkyfit1ybhj2jvn7NCzlzT1lUl BJe41hOv8mtSD6M2K7W/EtG8lPVXcRyD1M8o5UPurFoayhPh732UlxkrF8n343Xs7/nA CVdBpI8yDS06PqU6fmayCNsxxIFLjWPkbm4hhwhzpYLl48fUcXlD8/L9yufo7uI8opHB 9RdPIVhjS3UzHCCXALHHo5EFsxLusov0OTMREmiLHZGoijmV753Ni0/NA2USaJxwCCje yHewdu+B8mhcb4oER1rG2orN3fUDG1WYOg8DB5azC8H09NQ8yHyKkEWqIkeAyIlkXACU 45Pg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si7800246pgc.758.2018.02.22.02.27.14; Thu, 22 Feb 2018 02:27:28 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753460AbeBVK0Z (ORCPT + 99 others); Thu, 22 Feb 2018 05:26:25 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:32844 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753417AbeBVK0X (ORCPT ); Thu, 22 Feb 2018 05:26:23 -0500 Received: by mail-qk0-f196.google.com with SMTP id f25so5807950qkm.0 for ; Thu, 22 Feb 2018 02:26:23 -0800 (PST) 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=H8Djuy62nrAjw7bVVfb55UX8FQ1hSZXpfRRROXGpytU=; b=KoSlyQjMfTkC9b4y5ZrjaQoqYwy59wBFV9xAHnP4Egk2oIMLu2krdn7bHBjgtrl3Jb UL3Tz4WlFfxzFBZNTDZzmy6hGHT1gz0VJujmTDp97Pqa+filgxs96nNl2LM2l7yHjwzq 3GBY1bLcbUVn4OKtKrkur+813xYbHWumqBTeSJudMAU1XjP5s5mYgrCNA85cHyR+7AJN EwYcDE9xltDUI+5XuZgvmjIoO5JINXLsbvBEMfm+PYkc2/JAAy6X58oW/vrnvfsJbA5z Sxh5kaUTtqNku2nDO3uCeygRI8LBEYkKOrWR6iQBf/gNW7UtSdgqfK+5pz8fxrq9cF+U EcDg== X-Gm-Message-State: APf1xPDfPJmXhRejKlsruNDvyRTBGTzAY6eRNlxHaR27BXUV/+IA420y cY9j+7tpAqV3hoK7njNrHQNEtXqal2/EbmQBsTwjLg== X-Received: by 10.55.195.79 with SMTP id a76mr9922183qkj.217.1519295182870; Thu, 22 Feb 2018 02:26:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.29.117 with HTTP; Thu, 22 Feb 2018 02:26:22 -0800 (PST) In-Reply-To: <20180221202908.17258-2-ebiederm@xmission.com> References: <878tbmf5vl.fsf@xmission.com> <20180221202908.17258-2-ebiederm@xmission.com> From: Miklos Szeredi Date: Thu, 22 Feb 2018 11:26:22 +0100 Message-ID: Subject: Re: [PATCH v6 2/5] fuse: Fail all requests with invalid uids or gids To: "Eric W. Biederman" Cc: lkml , Linux Containers , linux-fsdevel , Alban Crequy , Seth Forshee , Sargun Dhillon , Dongsu Park , "Serge E. Hallyn" 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 Wed, Feb 21, 2018 at 9:29 PM, Eric W. Biederman wrote: > Upon a cursory examinination the uid and gid of a fuse request are > necessary for correct operation. Failing a fuse request where those > values are not reliable seems a straight forward and reliable means of > ensuring that fuse requests with bad data are not sent or processed. > > In most cases the vfs will avoid actions it suspects will cause > an inode write back of an inode with an invalid uid or gid. But that does > not map precisely to what fuse is doing, so test for this and solve > this at the fuse level as well. > > Performing this work in fuse_req_init_context is cheap as the code is > already performing the translation here and only needs to check the > result of the translation to see if things are not representable in > a form the fuse server can handle. > > Signed-off-by: Eric W. Biederman > --- > fs/fuse/dev.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 deletions(-) > > diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c > index 0fb58f364fa6..216db3f51a31 100644 > --- a/fs/fuse/dev.c > +++ b/fs/fuse/dev.c > @@ -112,11 +112,13 @@ static void __fuse_put_request(struct fuse_req *req) > refcount_dec(&req->count); > } > > -static void fuse_req_init_context(struct fuse_conn *fc, struct fuse_req *req) > +static bool fuse_req_init_context(struct fuse_conn *fc, struct fuse_req *req) > { > - req->in.h.uid = from_kuid_munged(&init_user_ns, current_fsuid()); > - req->in.h.gid = from_kgid_munged(&init_user_ns, current_fsgid()); > + req->in.h.uid = from_kuid(&init_user_ns, current_fsuid()); > + req->in.h.gid = from_kgid(&init_user_ns, current_fsgid()); > req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns); > + > + return (req->in.h.uid != ((uid_t)-1)) && (req->in.h.gid != ((gid_t)-1)); > } > > void fuse_set_initialized(struct fuse_conn *fc) > @@ -162,12 +164,13 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages, > wake_up(&fc->blocked_waitq); > goto out; > } > - > - fuse_req_init_context(fc, req); > __set_bit(FR_WAITING, &req->flags); > if (for_background) > __set_bit(FR_BACKGROUND, &req->flags); > - > + if (unlikely(!fuse_req_init_context(fc, req))) { > + fuse_put_request(fc, req); > + return ERR_PTR(-EOVERFLOW); > + } > return req; > > out: > @@ -256,9 +259,12 @@ struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, > if (!req) > req = get_reserved_req(fc, file); > > - fuse_req_init_context(fc, req); > __set_bit(FR_WAITING, &req->flags); > __clear_bit(FR_BACKGROUND, &req->flags); > + if (unlikely(!fuse_req_init_context(fc, req))) { > + fuse_put_request(fc, req); > + return ERR_PTR(-EOVERFLOW); > + } I think failing the "_nofail" variant is the wrong thing to do. This is called to allocate a FLUSH request on close() and in readdirplus to allocate a FORGET request. Failing the latter results in refcount leak in userspace. Failing the former results in missing unlock on close() of posix locks. Thanks, Miklos