Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752243AbbF0VRs (ORCPT ); Sat, 27 Jun 2015 17:17:48 -0400 Received: from mail-ig0-f179.google.com ([209.85.213.179]:37504 "EHLO mail-ig0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752033AbbF0VRi (ORCPT ); Sat, 27 Jun 2015 17:17:38 -0400 From: Patrick Donnelly To: Greg Kroah-Hartman , Jiri Slaby , linux-kernel@vger.kernel.org (open list) Cc: Patrick Donnelly Subject: [PATCH 2/2] Check tcsetpgrp p is a process group. Date: Sat, 27 Jun 2015 17:17:03 -0400 Message-Id: <1435439824-3975-2-git-send-email-batrick@batbytes.com> X-Mailer: git-send-email 2.4.4 In-Reply-To: <1435439824-3975-1-git-send-email-batrick@batbytes.com> References: <1435439824-3975-1-git-send-email-batrick@batbytes.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1322 Lines: 44 This fixes a bug where a process can set the foreground process group to its pid even if its pid is not a valid pgrp. Signed-off-by: Patrick Donnelly --- drivers/tty/tty_io.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 401d05e..c20a2fb 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -2560,9 +2560,11 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t { struct pid *pgrp; pid_t pgrp_nr; - int retval = tty_check_change(real_tty); + int retval; unsigned long flags; + retval = tty_check_change(real_tty); + if (retval == -EIO) return -ENOTTY; if (retval) @@ -2580,6 +2582,10 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t retval = -ESRCH; if (!pgrp) goto out_unlock; + retval = -EINVAL; + if (!pid_task(pgrp, PIDTYPE_PGID)) { + goto out_unlock; + } retval = -EPERM; if (session_of_pgrp(pgrp) != task_session(current)) goto out_unlock; -- Patrick Donnelly -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/