Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752517AbdHPUTE (ORCPT ); Wed, 16 Aug 2017 16:19:04 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:35555 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752130AbdHPUTC (ORCPT ); Wed, 16 Aug 2017 16:19:02 -0400 MIME-Version: 1.0 In-Reply-To: References: <20170816171211.4021-1-christian.brauner@ubuntu.com> <20170816194805.hnof3aqiqykwki7p@gmail.com> From: Linus Torvalds Date: Wed, 16 Aug 2017 13:19:01 -0700 X-Google-Sender-Auth: dVRktEAhMFAviZGWauh8HHyUJc4 Message-ID: Subject: Re: [PATCH 0/1] devpts: use dynamic_dname() to generate proc name To: Christian Brauner Cc: Christian Brauner , Linux Kernel Mailing List , "Serge E. Hallyn" , Al Viro Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1743 Lines: 42 On Wed, Aug 16, 2017 at 12:56 PM, Linus Torvalds wrote: > > So the fact that we _don't_ get the right pathname for the pts entry > here means that something got screwed up in setting filp->f_path to > the right thing. We have all the code in place that _tries_ to do it, > but it clearly has a bug somewhere. Ok, I think I see what the bug is, although I don't have a fix for it yet. We generate the path largely correctly: the path has a nice dentry that contains the right pts number, and has the right parent pointer that points to the root of the pts mount. And we also fill in the path 'mnt' field. Everything should be fine. Except when we actually hit that root dentry of the pts mount, the code in prepend_path() hits this condition: if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { struct mount *parent = ACCESS_ONCE(mnt->mnt_parent); /* Escaped? */ if (dentry != vfsmnt->mnt_root) { and we break out, and reset the path to '/' because we think it somehow escaped out of the user namespace. So it looks like we filled in the path with the *wrong* mount information. And THAT in turn is because we fill the path with the mount information for the "/dev/ptmx" field - which is *not* in the /dev/pts/ mount - that's the mount for '/dev'. So we have a dentry and a mnt, but they simply aren't paired up correctly. And you can see this with your test program: if you open /dev/pts/ptmx for the master, it actually works correctly (but you need to make sure the permissions for that ptmx node allow that). Anyway, I know what's wrong, next step is to figure out what the fix is. Linus