Received: by 10.223.185.116 with SMTP id b49csp241060wrg; Thu, 15 Feb 2018 20:55:07 -0800 (PST) X-Google-Smtp-Source: AH8x225cfyKltrGGXc+oPMALDnmHZsSuaNneB9lOzD6OplWw9eCNjE5rS+pHjIrlAabsTA61PnAy X-Received: by 2002:a17:902:2f03:: with SMTP id s3-v6mr4831452plb.112.1518756907733; Thu, 15 Feb 2018 20:55:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518756907; cv=none; d=google.com; s=arc-20160816; b=0BuJL9bzpuK94DzVSQ94X9R+JVwIC32Jw2Xh8vggYK8GPWiGmLFVcWiEoJ99ZnjKMO MKbNGiSBZTIxE/Qkl9NroZrKPvlq01/i8TIPCt2Wpz1IMjk4CjdQnBF+c+0aIPzAIRtq PEpVZc8bguWC2vjG9iKx3zB4jVGNUuoFHD0AAFU28u2a49o5hlxoZR60tcgCGD8QVLOz QeFwnpbIcBvyv4hPv8y5H29a6H94B37Nqgf447Ze/DzD2qYh0Mb4sxR9OgN9Kicsh1eK y3c+aZoXSM/+3PajyneTYLgQ8jY72BJ4yaecgcwEvCjlq3mZ9unQ1kLgB2XC9l1+a7We hi/w== 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=4ip9nABXFrmBNiMO17swPhnHnPXyEr/TZlF1TT0pzKg=; b=I35GZm4q/o1iKcPXd/3Vnu54T9uMSMkMZMPVdOajvrjbl+9k+kPRM4OfLJErZpCUBf UzDpW9hxr/VvWQONV13Yk6bWwbKynIZHQYUjiZyUjq3WrGfDVOtY1EEXUgjBhqEpp9y/ BIZOFmM6OLirNDE6D4B55Ne5C501cSx6oKVneRspKakOVAMXnwW9ccYYbkL5/ypj1Vpf w8saYA2G08VOS0gJD/pPvYApwfV3iOoQoNqA3uLyg454pkgnjjuQ/wTYnDem75pkybbl oV2cbRR6GLQC2uzgoE9vz3ZtHSmcPLOyJKra/Xt9iWDwDyCu2267iS7do9w7NXyWaOxs +9ww== 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 u2-v6si4215620plm.757.2018.02.15.20.54.51; Thu, 15 Feb 2018 20:55:07 -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 S1425180AbeBOPwC (ORCPT + 99 others); Thu, 15 Feb 2018 10:52:02 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36328 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424319AbeBOPro (ORCPT ); Thu, 15 Feb 2018 10:47:44 -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 3DB7B1025; Thu, 15 Feb 2018 15:47:44 +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.15 198/202] devpts: fix error handling in devpts_mntget() Date: Thu, 15 Feb 2018 16:18:18 +0100 Message-Id: <20180215151723.007375147@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@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.15-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; }