Received: by 10.223.185.116 with SMTP id b49csp5414wrg; Thu, 15 Feb 2018 15:24:03 -0800 (PST) X-Google-Smtp-Source: AH8x224M4UpMUB0j+QWNGmIsALWThhMVrI+5kl1lCH2I6tlYaKudBWGwBb4JUTEsCpqrp5CH+29x X-Received: by 2002:a17:902:aa95:: with SMTP id d21-v6mr4047001plr.16.1518737042908; Thu, 15 Feb 2018 15:24:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518737042; cv=none; d=google.com; s=arc-20160816; b=tctU9u1WmqBsx2clAZslBjQ/dpBPMbDm4u5d7TtogTr8wuoth9YXM7uWb0nlE5HKHe pjrhwFpmG/ALIPgLJcodvydZo01oOfrk5FdIuEId3ASgFmrTygIouAgvGdtBJkNpw2R2 KV3OFC2c6b1Pp/zCaveWNOy+wyGZMfwMIMH/wz5WHYuYxfGEW6r6sQPE9L02qjR5Ia9k NgNL3LQaeHmy0EXIzE6AGMxNDbQ2omZQZx6Sj6jdC/SriOxy4ynYO4VFo5YDN63xfHlV mhRrNUpyUysT1rpaF0X+IqMpbQ7TAJ5e6bKHQyocXnrPaXUGU9RJH0SpPD62tXekaraY owlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=UNhkV7zyaSgj8betJpA1whXeFsLpthwMf0Oi+NgxxRQ=; b=k81v9u+7K31zT5P7ekgUrKYNwZ89a7oQNS4q6Dym8u8Qd+kHWL6cgv1OdOm3msQAGA DasLTyAZ97U+golFPx4S4VsT6f0r1MEKbPkD6bvndUSW+1w78PPdsh9cg+GOZfoASijP qvnOekG6AiFq1loOzaCmFZNlADtlOxXdU6sMRVv4I37byvPibb7Rwn3dRMX0t9QdrYXy dgeiZ10iwLSJm8oPo1EUS9SN2yuqAclzDfYvy7toZy5UzxaIn0Auof7mJ8xw2Dz9DHtN 8GpAdDZTr5IjAH8pg7QA3na2bqYkGQeAUw/YQ2ApVNp29SL/JbuOPEpXGTn+UQPBIVVh v0ZA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si7767673plj.456.2018.02.15.15.23.13; Thu, 15 Feb 2018 15:24:02 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423313AbeBOPiZ (ORCPT + 99 others); Thu, 15 Feb 2018 10:38:25 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:59382 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422752AbeBOPiV (ORCPT ); Thu, 15 Feb 2018 10:38:21 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BFFF410A9; Thu, 15 Feb 2018 15:38:20 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Eric Biggers , Linus Torvalds Subject: [PATCH 4.14 191/195] devpts: fix error handling in devpts_mntget() Date: Thu, 15 Feb 2018 16:18:02 +0100 Message-Id: <20180215151715.878189408@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit c9cc8d01fb04117928830449388512a5047569c9 upstream. If devpts_ptmx_path() returns an error code, then devpts_mntget() dereferences an ERR_PTR(): BUG: unable to handle kernel paging request at fffffffffffffff5 IP: devpts_mntget+0x13f/0x280 fs/devpts/inode.c:173 Fix it by returning early in the error paths. Reproducer: #define _GNU_SOURCE #include #include #include #define TIOCGPTPEER _IO('T', 0x41) int main() { for (;;) { int fd = open("/dev/ptmx", 0); unshare(CLONE_NEWNS); ioctl(fd, TIOCGPTPEER, 0); } } Fixes: 311fc65c9fb9 ("pty: Repair TIOCGPTPEER") Reported-by: syzbot Signed-off-by: Eric Biggers Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/devpts/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -168,11 +168,11 @@ struct vfsmount *devpts_mntget(struct fi dput(path.dentry); if (err) { mntput(path.mnt); - path.mnt = ERR_PTR(err); + return ERR_PTR(err); } if (DEVPTS_SB(path.mnt->mnt_sb) != fsi) { mntput(path.mnt); - path.mnt = ERR_PTR(-ENODEV); + return ERR_PTR(-ENODEV); } return path.mnt; }