Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753335AbdHXPv3 (ORCPT ); Thu, 24 Aug 2017 11:51:29 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:35004 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753201AbdHXPv2 (ORCPT ); Thu, 24 Aug 2017 11:51:28 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Linus Torvalds Cc: Stefan Lippers-Hollmann , Christian Brauner , Christian Brauner , Linux Kernel Mailing List , "Serge E. Hallyn" , Al Viro , Thorsten Leemhuis References: <20170816171211.4021-1-christian.brauner@ubuntu.com> <20170816194805.hnof3aqiqykwki7p@gmail.com> <87pobvruzt.fsf@xmission.com> <87ziazqdfr.fsf@xmission.com> <20170824022436.44adb497@mir> <87378hhi3y.fsf@xmission.com> <87wp5tfynr.fsf@xmission.com> Date: Thu, 24 Aug 2017 10:51:05 -0500 In-Reply-To: (Linus Torvalds's message of "Wed, 23 Aug 2017 20:24:35 -0700") Message-ID: <87efs1ezh2.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1dkuPf-0002xn-Uy;;;mid=<87efs1ezh2.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=67.3.200.44;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+l2MhJBSKIZHBhywa6HOtLcsaSfcGtPYk= X-SA-Exim-Connect-IP: 67.3.200.44 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_03 6+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_02 5+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 5681 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 2.5 (0.0%), b_tie_ro: 1.68 (0.0%), parse: 0.85 (0.0%), extract_message_metadata: 14 (0.2%), get_uri_detail_list: 1.86 (0.0%), tests_pri_-1000: 7 (0.1%), tests_pri_-950: 1.12 (0.0%), tests_pri_-900: 0.96 (0.0%), tests_pri_-400: 25 (0.4%), check_bayes: 24 (0.4%), b_tokenize: 8 (0.1%), b_tok_get_all: 9 (0.2%), b_comp_prob: 2.4 (0.0%), b_tok_touch_all: 3.1 (0.1%), b_finish: 0.54 (0.0%), tests_pri_0: 328 (5.8%), check_dkim_signature: 0.51 (0.0%), check_dkim_adsp: 5 (0.1%), tests_pri_500: 5298 (93.3%), poll_dns_idle: 5292 (93.2%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 0/1] devpts: use dynamic_dname() to generate proc name X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3080 Lines: 91 Linus Torvalds writes: > On Wed, Aug 23, 2017 at 8:11 PM, Eric W. Biederman > wrote: >> -static int pty_get_peer(struct tty_struct *tty, int flags) >> +int ptm_open_peer(struct file *master, struct tty_struct *tty, int flags) >> { >> int fd = -1; >> struct file *filp = NULL; >> int retval = -EINVAL; >> + struct path path; >> + >> + if ((tty->driver->type != TTY_DRIVER_TYPE_PTY) || >> + (tty->driver->subtype != PTY_TYPE_MASTER)) >> + return -EIO; > > No. Afaik, that could be a legact PTY, which wouldn't be ok. > > I think you need to do > > if (tty->driver != ptm_driver) > return -EIO; > > which should check both that it's the unix98 pty, and that it's the master. > > Maybe I'm missing something. > > That check used to be implicit, in that only the unix98 pty's could > reach that pty_unix98_ioctl() function, so then testing just that it > was a master was sufficient. No. That seems correct. Change made. If nothing else it is cheaper and clearer so even if the other version wasn't wrong it is a good idea. >> - /* We need to cache a fake path for TIOCGPTPEER. */ >> - pts_path = kmalloc(sizeof(struct path), GFP_KERNEL); >> - if (!pts_path) >> - goto err_release; >> - pts_path->mnt = filp->f_path.mnt; >> - pts_path->dentry = dentry; >> - path_get(pts_path); >> - tty->link->driver_data = pts_path; >> + tty->link->driver_data = dentry; > > We used to do "path_get()". Shouldn't we now use "dget()"? > > But maybe the slave dentry is guaranteed to be around and we don't > need to do that. So your approach may be fine. You did remove all the > path_put() calls too, so I guess it all matches up. > > So this looks like it could be fine, but I'd like to make sure. That change is a revert to the old v4.12 code. So it is definitely not regression inducing. Further devpts_pty_new allocates a dentry keeps it in the devpts filesystem. The dentry is good until devpts_pty_kill where the dentry is unlinked and killed. I figure not differences from v4.12 if the logic hasn't changed seems a good good way to cut down on the search for bugs/regressions. >> +struct vfsmount *devpts_mnt(struct file *filp) >> +{ >> + struct path path; >> + int err; >> + >> + path = filp->f_path; >> + path_get(&path); >> + >> + err = devpts_ptmx_path(&path); >> + if (err) { >> + path_put(&path); >> + path.mnt = ERR_PTR(err); >> + } >> + return path.mnt; >> +} > > That can't be right. You're leaking the dentry that you're not returning, no? Correct. That is buggy. Will fix before I resend. > But yes, apart from those comments, this looks like what I envisioned. > > Needs testing, and needs more looking at those reference counts, but > otherwise looks good. > > And while the patch is a bit bigger, I do like getting rid of that > 'struct path' thing, and keeping just the dentry. Eric