From patchwork Wed Apr 7 10:23:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 417353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72ECBC433B4 for ; Wed, 7 Apr 2021 10:23:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34A8B613A0 for ; Wed, 7 Apr 2021 10:23:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350939AbhDGKYB (ORCPT ); Wed, 7 Apr 2021 06:24:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:44586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234482AbhDGKX7 (ORCPT ); Wed, 7 Apr 2021 06:23:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 43B2F613A0; Wed, 7 Apr 2021 10:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617791030; bh=wHRJSTfhmbp2C9AGX30evxMJrkmtbmwIdlqGkY/e/2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SGrb+ehhbmbharjoG2/kdhMvEMEAn4KqVkmW27uS07R3zXQnxjtTT9bl4clMtRC4L mz/NOkKzLXZFSyVetnC92f9nG4iFWfJd2DPNPxr9asYt3+YYahmw4HF5ksGvoRHFpk ivwoxk6NtKyFf0eslfsKZltd8/13XQD3h925CPv47ebd6nBWc7kKtyLTVXpLrTazo1 tn2Op9/+/BUu4lns92hk8wieXI27aKQcZd1REzxI7f3u1d1RD07FSdft/LymuR7pX/ nkssdhNi+W/Zen92B3L4ZuXDMvGiXboUiC8Yf4E1mQfaOJhm3zhdROvrAsFTle8vZg e+C8t0W5HMO+A== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lU5La-0008R1-Mc; Wed, 07 Apr 2021 12:23:42 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-staging@lists.linux.dev, greybus-dev@lists.linaro.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH 01/16] staging: fwserial: fix TIOCSSERIAL jiffies conversions Date: Wed, 7 Apr 2021 12:23:19 +0200 Message-Id: <20210407102334.32361-2-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210407102334.32361-1-johan@kernel.org> References: <20210407102334.32361-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The port close_delay parameter set by TIOCSSERIAL is specified in jiffies, while the value returned by TIOCGSERIAL is specified in centiseconds. Add the missing conversions so that TIOCGSERIAL works as expected also when HZ is not 100. Fixes: 7355ba3445f2 ("staging: fwserial: Add TTY-over-Firewire serial driver") Cc: stable@vger.kernel.org # 3.8 Signed-off-by: Johan Hovold --- drivers/staging/fwserial/fwserial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index c368082aae1a..c963848522b1 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -1223,7 +1223,7 @@ static int get_serial_info(struct tty_struct *tty, ss->flags = port->port.flags; ss->xmit_fifo_size = FWTTY_PORT_TXFIFO_LEN; ss->baud_base = 400000000; - ss->close_delay = port->port.close_delay; + ss->close_delay = jiffies_to_msecs(port->port.close_delay) / 10; mutex_unlock(&port->port.mutex); return 0; } @@ -1245,7 +1245,7 @@ static int set_serial_info(struct tty_struct *tty, return -EPERM; } } - port->port.close_delay = ss->close_delay * HZ / 100; + port->port.close_delay = msecs_to_jiffies(ss->close_delay * 10); mutex_unlock(&port->port.mutex); return 0; From patchwork Wed Apr 7 10:23:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 417352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED8B7C43461 for ; Wed, 7 Apr 2021 10:23:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B39446139C for ; Wed, 7 Apr 2021 10:23:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350954AbhDGKYC (ORCPT ); Wed, 7 Apr 2021 06:24:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:44726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350935AbhDGKYA (ORCPT ); Wed, 7 Apr 2021 06:24:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 83935613CD; Wed, 7 Apr 2021 10:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617791030; bh=aOiPbYy6/Ya3tIGwHa7GwZ9E/dBfsXM6G8A4jcFIg/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QMoWO65jgBW2Pok69R3BKsbXuIrP21olYOQZOHASBR6UxawzxDMHRKdr31p/w9hfp zO2LLm6V3dwgpSA8dYMj3b4+5QkugHofPnzlmDYip8SzxfYmFcbGmS7z12hFN7vV50 ZvSU+SmOsUyx6UP56WMYEqbQ87I20Tfi01OF41fP4swS17NrzoejFFjHmdKmSJBQCM w4FGkLn96em5nzhGCruLSrJrk+8aB7Q9Uh/OycVTP2otygNq05PKouwXO2TxlI85ps tn4I6+T4v/X6SorrSLTCXBmmV/dpa2gtd5Vkwo8Yj0olKSKWGk9bLYsqspqyJnaG0i kXAHQDmeIuXPw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lU5Lb-0008RN-94; Wed, 07 Apr 2021 12:23:43 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-staging@lists.linux.dev, greybus-dev@lists.linaro.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH 08/16] tty: amiserial: fix TIOCSSERIAL permission check Date: Wed, 7 Apr 2021 12:23:26 +0200 Message-Id: <20210407102334.32361-9-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210407102334.32361-1-johan@kernel.org> References: <20210407102334.32361-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Changing the port closing_wait parameter is a privileged operation. Add the missing check to TIOCSSERIAL so that -EPERM is returned in case an unprivileged user tries to change the closing-wait setting. Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/tty/amiserial.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c index 0c8157fab17f..ec6802ba2bf8 100644 --- a/drivers/tty/amiserial.c +++ b/drivers/tty/amiserial.c @@ -970,6 +970,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss) if (!serial_isroot()) { if ((ss->baud_base != state->baud_base) || (ss->close_delay != port->close_delay) || + (ss->closing_wait != port->closing_wait) || (ss->xmit_fifo_size != state->xmit_fifo_size) || ((ss->flags & ~ASYNC_USR_MASK) != (port->flags & ~ASYNC_USR_MASK))) { From patchwork Wed Apr 7 10:23:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 417351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4E9AC43462 for ; Wed, 7 Apr 2021 10:23:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90C9E6124B for ; Wed, 7 Apr 2021 10:23:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350957AbhDGKYD (ORCPT ); Wed, 7 Apr 2021 06:24:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:44742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350937AbhDGKYA (ORCPT ); Wed, 7 Apr 2021 06:24:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AF25A613DF; Wed, 7 Apr 2021 10:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617791030; bh=osq8Zv5no+jjMKMVk9DS4gKqyPi6TZhpdLxBOLoPeJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OsbJmXwBde2d8e+Lr6V5drvXKoLICyFpxDZnMjwpun+5gPF5scBnwg4GJRavGCZkh 2TPKrto7dJgbX3xsfrUc/VZstna7ELu+UBRr5wsY2d1wH8semrsXtQNc8Uz1FKPpQo kOrhUNR7B4TkyE4L+TOFPUYOzc8ILnhGbUL1qujyeZUwNplmHHGpfWjnyigFOh3O5q eGskzEIWIPcyjSX7t0zLN854YOX7402fzTy8Q6TETsqiYw++tss77MqCQ3PNKsPGx+ u+V5pBQ7q/StMEmYfLZYZRmp6FFKK5iJdLkTCcxKjKicalMUuOW7QCQ9lD8TvuL8e0 A7oXfpRzV7W1A== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lU5Lb-0008RT-Dq; Wed, 07 Apr 2021 12:23:43 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-staging@lists.linux.dev, greybus-dev@lists.linaro.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH 10/16] tty: moxa: fix TIOCSSERIAL jiffies conversions Date: Wed, 7 Apr 2021 12:23:28 +0200 Message-Id: <20210407102334.32361-11-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210407102334.32361-1-johan@kernel.org> References: <20210407102334.32361-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The port close_delay parameter set by TIOCSSERIAL is specified in jiffies, while the value returned by TIOCGSERIAL is specified in centiseconds. Add the missing conversions so that TIOCGSERIAL works as expected also when HZ is not 100. Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/tty/moxa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c index 32eb6b5e510f..5b7bc7af8b1e 100644 --- a/drivers/tty/moxa.c +++ b/drivers/tty/moxa.c @@ -2038,7 +2038,7 @@ static int moxa_get_serial_info(struct tty_struct *tty, ss->line = info->port.tty->index, ss->flags = info->port.flags, ss->baud_base = 921600, - ss->close_delay = info->port.close_delay; + ss->close_delay = jiffies_to_msecs(info->port.close_delay) / 10; mutex_unlock(&info->port.mutex); return 0; } @@ -2067,7 +2067,7 @@ static int moxa_set_serial_info(struct tty_struct *tty, return -EPERM; } } - info->port.close_delay = ss->close_delay * HZ / 100; + info->port.close_delay = msecs_to_jiffies(ss->close_delay * 10); MoxaSetFifo(info, ss->type == PORT_16550A); From patchwork Wed Apr 7 10:23:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 417350 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FA21C433B4 for ; Wed, 7 Apr 2021 10:23:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F21D06139C for ; Wed, 7 Apr 2021 10:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350960AbhDGKYE (ORCPT ); Wed, 7 Apr 2021 06:24:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:44808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350945AbhDGKYB (ORCPT ); Wed, 7 Apr 2021 06:24:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ED45D613EA; Wed, 7 Apr 2021 10:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617791031; bh=YvIR0wKojxogYm4mzV63se8JnVW9YMFH3XKPAsG7738=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sIYUKWNeo2Msucz9qhPpvQuQJ5+m8Br118lI46SA3MCNm9N743C/4Ipm+ay1jKDx7 qku/mXJPNiCW5uu0LGWecO3wJzUgkhO+zUJQKjQolf0QPbHOOoYpO4SH7rYsltdxmW OVBlvediJuUSDKcrhUY2ZfhXZafUzgndq+k8V5ik2idP8G/xrWUrMK+2QbK8bBwxUb qhCmJajnKvs4ntzYwnPoC5yrVCt1dxjJvsFn7xaejrB2sVsPk8VEFwBKBL09dHXWXy WKemapHQkTNfjlcL5vDfqVcNYhYMq6zI3UpKowIQy69/cHP72jbUAUI2Lk6/KpyLot BhZdwdEFpiMpQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lU5Lb-0008Rc-Ma; Wed, 07 Apr 2021 12:23:43 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-staging@lists.linux.dev, greybus-dev@lists.linaro.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH 13/16] tty: mxser: fix TIOCSSERIAL jiffies conversions Date: Wed, 7 Apr 2021 12:23:31 +0200 Message-Id: <20210407102334.32361-14-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210407102334.32361-1-johan@kernel.org> References: <20210407102334.32361-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The port close_delay and closing wait parameters set by TIOCSSERIAL are specified in jiffies, while the values returned by TIOCGSERIAL are specified in centiseconds. Add the missing conversions so that TIOCSSERIAL works as expected also when HZ is not 100. Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/tty/mxser.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c index 4203b64bccdb..914b23071961 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c @@ -1208,19 +1208,26 @@ static int mxser_get_serial_info(struct tty_struct *tty, { struct mxser_port *info = tty->driver_data; struct tty_port *port = &info->port; + unsigned int closing_wait, close_delay; if (tty->index == MXSER_PORTS) return -ENOTTY; mutex_lock(&port->mutex); + + close_delay = jiffies_to_msecs(info->port.close_delay) / 10; + closing_wait = info->port.closing_wait; + if (closing_wait != ASYNC_CLOSING_WAIT_NONE) + closing_wait = jiffies_to_msecs(closing_wait) / 10; + ss->type = info->type, ss->line = tty->index, ss->port = info->ioaddr, ss->irq = info->board->irq, ss->flags = info->port.flags, ss->baud_base = info->baud_base, - ss->close_delay = info->port.close_delay, - ss->closing_wait = info->port.closing_wait, + ss->close_delay = close_delay; + ss->closing_wait = closing_wait; ss->custom_divisor = info->custom_divisor, mutex_unlock(&port->mutex); return 0; @@ -1233,7 +1240,7 @@ static int mxser_set_serial_info(struct tty_struct *tty, struct tty_port *port = &info->port; speed_t baud; unsigned long sl_flags; - unsigned int flags; + unsigned int flags, close_delay, closing_wait; int retval = 0; if (tty->index == MXSER_PORTS) @@ -1255,9 +1262,14 @@ static int mxser_set_serial_info(struct tty_struct *tty, flags = port->flags & ASYNC_SPD_MASK; + close_delay = msecs_to_jiffies(ss->close_delay * 10); + closing_wait = ss->closing_wait; + if (closing_wait != ASYNC_CLOSING_WAIT_NONE) + closing_wait = msecs_to_jiffies(closing_wait * 10); + if (!capable(CAP_SYS_ADMIN)) { if ((ss->baud_base != info->baud_base) || - (ss->close_delay != info->port.close_delay) || + (close_delay != info->port.close_delay) || ((ss->flags & ~ASYNC_USR_MASK) != (info->port.flags & ~ASYNC_USR_MASK))) { mutex_unlock(&port->mutex); return -EPERM; @@ -1271,8 +1283,8 @@ static int mxser_set_serial_info(struct tty_struct *tty, */ port->flags = ((port->flags & ~ASYNC_FLAGS) | (ss->flags & ASYNC_FLAGS)); - port->close_delay = ss->close_delay * HZ / 100; - port->closing_wait = ss->closing_wait * HZ / 100; + port->close_delay = close_delay; + port->closing_wait = closing_wait; if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST && (ss->baud_base != info->baud_base || ss->custom_divisor !=