From patchwork Wed Apr 7 10:28:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12187653 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,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 C5E5CC433ED for ; Wed, 7 Apr 2021 10:29:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87945613A7 for ; Wed, 7 Apr 2021 10:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237037AbhDGK3S (ORCPT ); Wed, 7 Apr 2021 06:29:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:46114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233465AbhDGK3L (ORCPT ); Wed, 7 Apr 2021 06:29:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4119B61284; Wed, 7 Apr 2021 10:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617791342; bh=0f5iqAFTzVz/UUoG84WKx/vqS1eja/sTREPpFmtK6Zw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uV96icEZvQKAFD6EyJtKG8WL8/YnUIUV6q3ANMtyBgjssMzBQCfdZUebj9mJI/GqU Yo1ylv2aQjwVkKcRQ1p9VlOieD5KH6IPyds0njC/XkE2JA2fNandTDTt47RMCfMis9 hiYxAH7eShrnSwAlPTYKHB+okz5gwzvLS3TNdyUe+UY+jLHgeNTcSCvDQqwbedS6Ci kNz5r873zT9rFB0PwpwM3iYOYcb+b+HcTE1VbQ20AdC4fLLFbG506LJy8hXxsIT70G ireKO6D8KBlWRvO8kyDTwOCYhTWxIa2uH8qP4MDkpuMo/32NTASBo8200bbteCEsCr WzjWi2CNDCT0Q== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lU5Qc-00004s-N9; Wed, 07 Apr 2021 12:28:54 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Oliver Neukum , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , Anthony Mallet , stable@vger.kernel.org Subject: [PATCH 1/3] Revert "USB: cdc-acm: fix rounding error in TIOCSSERIAL" Date: Wed, 7 Apr 2021 12:28:43 +0200 Message-Id: <20210407102845.32720-2-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210407102845.32720-1-johan@kernel.org> References: <20210407102845.32720-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit b401f8c4f492cbf74f3f59c9141e5be3071071bb. The offending commit claimed that trying to set the values reported back by TIOCGSERIAL as a regular user could result in an -EPERM error when HZ is 250, but that was never the case. With HZ=250, the default 0.5 second value of close_delay is converted to 125 jiffies when set and is converted back to 50 centiseconds by TIOCGSERIAL as expected (not 12 cs as was claimed). Comparing the internal current and new jiffies values is just fine to determine if the value is about to change so drop the bogus workaround (which was also backported to stable). For completeness: With different default values for these parameters or with a HZ value not divisible by two, the lack of rounding when setting the default values in tty_port_init() could result in an -EPERM being returned, but this is hardly something we need to worry about. Cc: Anthony Mallet Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/usb/class/cdc-acm.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 3fda1ec961d7..96e221803fa6 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -942,7 +942,6 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss) { struct acm *acm = tty->driver_data; unsigned int closing_wait, close_delay; - unsigned int old_closing_wait, old_close_delay; int retval = 0; close_delay = msecs_to_jiffies(ss->close_delay * 10); @@ -950,17 +949,11 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss) ASYNC_CLOSING_WAIT_NONE : msecs_to_jiffies(ss->closing_wait * 10); - /* we must redo the rounding here, so that the values match */ - old_close_delay = jiffies_to_msecs(acm->port.close_delay) / 10; - old_closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? - ASYNC_CLOSING_WAIT_NONE : - jiffies_to_msecs(acm->port.closing_wait) / 10; - mutex_lock(&acm->port.mutex); if (!capable(CAP_SYS_ADMIN)) { - if ((ss->close_delay != old_close_delay) || - (ss->closing_wait != old_closing_wait)) + if ((close_delay != acm->port.close_delay) || + (closing_wait != acm->port.closing_wait)) retval = -EPERM; else retval = -EOPNOTSUPP; From patchwork Wed Apr 7 10:28:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12187657 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 04EB3C433B4 for ; Wed, 7 Apr 2021 10:29:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4021613AF for ; Wed, 7 Apr 2021 10:29:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232747AbhDGK3U (ORCPT ); Wed, 7 Apr 2021 06:29:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:46116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233353AbhDGK3L (ORCPT ); Wed, 7 Apr 2021 06:29:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 43B286139C; Wed, 7 Apr 2021 10:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617791342; bh=lsyrtIigVOizPgWs0iXL/uoRm3JMsiE4v9eha+Vtaso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c9m2PHu6WalK4rMS2yp8AZ0JdEjYqoyCcw87aPccXMHJZ89/ImPmi8mOJ1Cknpfnr StJl6H/fY/L9Xcx/EapU975Nft/IAlViVRawL7s1o0B986DHOlJhcZtBVtcLJj2shq VBefZSF3fiMKQ3gbSeoRaJBgFf+29odJ6jfgjM9dtnrJLhvXHmn+HkgVCRMr0EiWhW ryhpTZYwf14nQTTQEzxBcG2+Da+cTOVa3A4qJSXQkpB9K82NZJXJ+sVwwYSsd/3WQK rY9zzwmI0TJStPt1QvgXdHZLZybRjmrqHJ9d0XabS+T+rkQxpTwGclCFibZFlpGldL EZe+nn0mOzoxA== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lU5Qc-00004u-Pe; Wed, 07 Apr 2021 12:28:54 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Oliver Neukum , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 2/3] USB: cdc-acm: fix unprivileged TIOCCSERIAL Date: Wed, 7 Apr 2021 12:28:44 +0200 Message-Id: <20210407102845.32720-3-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210407102845.32720-1-johan@kernel.org> References: <20210407102845.32720-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org TIOCSSERIAL is a horrid, underspecified, legacy interface which for most serial devices is only useful for setting the close_delay and closing_wait parameters. A non-privileged user has only ever been able to set the since long deprecated ASYNC_SPD flags and trying to change any other *supported* feature should result in -EPERM being returned. Setting the current values for any supported features should return success. Fix the cdc-acm implementation which instead indicated that the TIOCSSERIAL ioctl was not even implemented when a non-privileged user set the current values. Fixes: ba2d8ce9db0a ("cdc-acm: implement TIOCSSERIAL to avoid blocking close(2)") Signed-off-by: Johan Hovold --- drivers/usb/class/cdc-acm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 96e221803fa6..43e31dad4831 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -955,8 +955,6 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss) if ((close_delay != acm->port.close_delay) || (closing_wait != acm->port.closing_wait)) retval = -EPERM; - else - retval = -EOPNOTSUPP; } else { acm->port.close_delay = close_delay; acm->port.closing_wait = closing_wait; From patchwork Wed Apr 7 10:28:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12187655 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 8CBEEC43460 for ; Wed, 7 Apr 2021 10:29:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49840613A9 for ; Wed, 7 Apr 2021 10:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351053AbhDGK3T (ORCPT ); Wed, 7 Apr 2021 06:29:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:46118 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233482AbhDGK3L (ORCPT ); Wed, 7 Apr 2021 06:29:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 465FC613A0; Wed, 7 Apr 2021 10:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617791342; bh=tIq/LxC9O1wQTOdggYIlPgHa1zajHf0cAFFCHEXAskg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VmM87a0Lxl81462c00/4Qzg62Cq993slxV0Fl67/x1MLOxVD+czwSx721Me9o2l0k YXkdOtlQ10A0Dugc5bLYW0WGm3igTwRZbFpSjYi/9vHAp596l2IUZOp4y6fgjpfuoO Tnhj+JaHB7nAqgDZToCnMlBh7ABaRzQ3ICuU2cgWnCFSzL7mggz8snkVAQBHqJelAZ Uw8/WjkVqnFBB5Nof2bChDl6QuRWfOl8gc7azgtcoxjYssrSJSqwGap6j7cEoDp/v5 xVL6oAGcWTx3/9PrkY2w3XmncCVOW6RAiVlTb7fvjvdW4ufrIaCLu7D3Bndo+O+OpB QtDmYmEqcJriQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lU5Qc-00004x-Rn; Wed, 07 Apr 2021 12:28:54 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Oliver Neukum , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 3/3] USB: cdc-acm: fix TIOCGSERIAL implementation Date: Wed, 7 Apr 2021 12:28:45 +0200 Message-Id: <20210407102845.32720-4-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210407102845.32720-1-johan@kernel.org> References: <20210407102845.32720-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org TIOCSSERIAL is a horrid, underspecified, legacy interface which for most serial devices is only useful for setting the close_delay and closing_wait parameters. The xmit_fifo_size parameter could be used to set the hardware transmit fifo size of a legacy UART when it could not be detected, but the interface is limited to eight bits and should be left unset when it is not used. Similarly, baud_base could be used to set the uart base clock when it could not be detected, but might as well be left unset when it is not known. Fix the cdc-acm TIOCGSERIAL implementation by dropping its custom interpretation of the unused xmit_fifo_size and baud_base fields, which overflowed the former with the URB buffer size and set the latter to the current line speed. Also return the port line number, which is the only other value used besides the close parameters. Fixes: 18c75720e667 ("USB: allow users to run setserial with cdc-acm") Signed-off-by: Johan Hovold --- drivers/usb/class/cdc-acm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 43e31dad4831..b74713518b3a 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -929,8 +929,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_struct *ss) { struct acm *acm = tty->driver_data; - ss->xmit_fifo_size = acm->writesize; - ss->baud_base = le32_to_cpu(acm->line.dwDTERate); + ss->line = acm->minor; ss->close_delay = jiffies_to_msecs(acm->port.close_delay) / 10; ss->closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? ASYNC_CLOSING_WAIT_NONE :