From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3164C07E9A for ; Mon, 12 Jul 2021 20:03:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8076961242 for ; Mon, 12 Jul 2021 20:03:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234394AbhGLUG0 (ORCPT ); Mon, 12 Jul 2021 16:06:26 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:44984 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233686AbhGLUGZ (ORCPT ); Mon, 12 Jul 2021 16:06:25 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m329P-00GBKY-Tg; Mon, 12 Jul 2021 14:03:35 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:60510 helo=email.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m329O-002iY0-KP; Mon, 12 Jul 2021 14:03:35 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Linus Torvalds Cc: Kalesh Singh , Kees Cook , Christian Brauner , Christian Koenig , Suren Baghdasaryan , Hridya Valsaraju , Android Kernel Team , Andrew Morton , Linux Kernel Mailing List , linux-fsdevel References: <20210708155647.44208-1-kaleshsingh@google.com> Date: Mon, 12 Jul 2021 15:02:38 -0500 In-Reply-To: (Linus Torvalds's message of "Sat, 10 Jul 2021 11:21:34 -0700") Message-ID: <87czrn8fmp.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1m329O-002iY0-KP;;;mid=<87czrn8fmp.fsf@disp2133>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+kWxupuXErFY3jJxeNcvha9YzdyoVp6Nk= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH] procfs: Prevent unpriveleged processes accessing fdinfo X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Linus Torvalds writes: > On Thu, Jul 8, 2021 at 8:57 AM Kalesh Singh wrote: >> >> The file permissions on the fdinfo dir from were changed from >> S_IRUSR|S_IXUSR to S_IRUGO|S_IXUGO, and a PTRACE_MODE_READ check was >> added for opening the fdinfo files [1]. However, the ptrace permission >> check was not added to the directory, allowing anyone to get the open FD >> numbers by reading the fdinfo directory. >> >> Add the missing ptrace permission check for opening the fdinfo directory. > > The more I look at this, the more I feel like we should look at > instead changing how "get_proc_task()" works. The practical implementation that I can see is to add a exec_id attribute into the proc inode and to modify proc_pid_make_inode to take a new exec_id parameter. There are some directories like /proc/PPP/, /proc/PPP/task/TTT/, /proc/PPP/net where it is both safe and appropriate to allow caching the reference over a suid exec. To handle that I would have a flag somewhere (possibly a special exec_id value) that indicates we don't care about the exec id. Once get_proc_task is taught to handle both cases and the appropriate exec_id is passed to proc_pid_make_inode proc_pid_invalidate works automatically. So I think that is all we really need to do. > That's one of the core functions for /proc, and I wonder if we > couldn't just make it refuse to look up a task that has gone through a > suid execve() since the proc inode was opened. > > I don't think it's basically ever ok to open something for one thread, > and then use it after the thread has gone through a suid thing. > > In fact, I wonder if we could make it even stricter, and go "any exec > at all", but I think a suid exec might be the minimum we should do. > > Then the logic really becomes very simple: we did the permission > checks at open time (like UNIX permission checks should be done), and > "get_proc_task()" basically verifies that "yeah, that open-time > decision is still valid". > > Wouldn't that make a lot of sense? Roughly. I want to use reuse exec_id but that seems a bit strong for have the permissions changed. Checking ->cred is too sensitive. So it is a bit fiddly to get right. Limiting this to suid-exec (and equivalent) seems like the proper filter, because it is when the permissions have fundamentally changed. I just don't think this should be blanket for everything that uses get_prock_task. Eric