Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3179938imw; Mon, 11 Jul 2022 03:41:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uDSGh3iAUTgRW8L2oq1OhawlGTXIiUad/hzpDsdxjH4FUejpezpzKM5unhH/v0MhAfayJJ X-Received: by 2002:a05:6402:400a:b0:43a:40e4:af89 with SMTP id d10-20020a056402400a00b0043a40e4af89mr24381456eda.383.1657536091049; Mon, 11 Jul 2022 03:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657536091; cv=none; d=google.com; s=arc-20160816; b=FEpUJEN46f5F3GFc6mIqxwwZ/TEP4b4wTn7tVkZ+QnnpDm/JCxGxm69WTXljicnHCn kcj/9LhRFAZKxTo4DV9xUFlBLrCCrC784sDkS1l1lyBpUUGmJANi3FwsJnnT9w/bBP9m REQM16ssD3lDwLRYIJuY/M7Fl9XFBnYTb+6FxIk+yLGsNFlgp7IBEJ2emQsNLjozw8Ly mVGzLxUq5fipjmQtVGuwQ8IfqydNG8SSlZFNEG43bcBsyGjbzFbl7VKOwqoB79xp9NP4 kIfHlHCf1yjrOX2+JpiIzuhpjIIF9m0kT7RB7DFghM+FUINdCOS98xZO/klPAsO9v44+ B96w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4TJqBz+qYdsKz0P9YeKMPwg+qyhLvtUMgBjJvRkVxsk=; b=gncaOzw90AK1fFKRUc84LTt5KLZO3Gz4UtJhTaqztavsBBicZgeFsSxYTbUgdwbDRa qheORQN35wczH4mhphDGGgoPBh7ARME6LKgxkrY5B/6S/CdpnteYp7ULiA/anWEQSQtz /hWFuk7I7KF1zHhxDUVsbNi+ev0EgHndUm+iUwR+ZIXCIy/nnaC07vcKAp5bP+nMEDoj R1hgbOskMdGJFslFXASBKiQ7kMcAkYb32uSUMjH6jZl1zviMNjaSdmNAHlshCff7gPMK URrv5uI+4uOs6IiZluUxjPrvl2+MaspGxjCwvPGyPQ/ZpOv8mieC9uD4exIx8XE54ZtO zNmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CczWVxuy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs14-20020a1709072d0e00b0072b4d8bc1c6si6374887ejc.367.2022.07.11.03.41.04; Mon, 11 Jul 2022 03:41:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CczWVxuy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234297AbiGKJ7R (ORCPT + 99 others); Mon, 11 Jul 2022 05:59:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234228AbiGKJ6j (ORCPT ); Mon, 11 Jul 2022 05:58:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0815BB5D29; Mon, 11 Jul 2022 02:27:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A17E161383; Mon, 11 Jul 2022 09:27:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAE1BC34115; Mon, 11 Jul 2022 09:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657531637; bh=yukl6GV3BRbGGtmdnfo95ezX+H3GVr/qNTWjY1Phkmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CczWVxuyhWIh4CL3FxPASBHzJclnkjJUr48pLliffnahP1cz++FSQLAuhz8WQO9/n +IO6MNS1roQ02vx7e1fj0YN5YSHcJlrUvhOl4obRYKa+rsDKfvulAlYIHR0Z/PMcOy dsZ1Oh7IOaZyFgKpXkBRQ4PI8RwhEcRCXIojaLGg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Starke , Sasha Levin Subject: [PATCH 5.15 137/230] tty: n_gsm: fix invalid gsmtty_write_room() result Date: Mon, 11 Jul 2022 11:06:33 +0200 Message-Id: <20220711090607.950458131@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090604.055883544@linuxfoundation.org> References: <20220711090604.055883544@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Starke [ Upstream commit 9361ebfbb79fd1bc8594a487c01ad52cdaa391ea ] gsmtty_write() does not prevent the user to use the full fifo size of 4096 bytes as allocated in gsm_dlci_alloc(). However, gsmtty_write_room() tries to limit the return value by 'TX_SIZE' and returns a negative value if the fifo has more than 'TX_SIZE' bytes stored. This is obviously wrong as 'TX_SIZE' is defined as 512. Define 'TX_SIZE' to the fifo size and use it accordingly for allocation to keep the current behavior. Return the correct remaining size of the fifo in gsmtty_write_room() via kfifo_avail(). Fixes: e1eaea46bb40 ("tty: n_gsm line discipline") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke Link: https://lore.kernel.org/r/20220504081733.3494-3-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/n_gsm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index fd4a86111a6e..4a430f6ca170 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -137,6 +137,7 @@ struct gsm_dlci { int retries; /* Uplink tty if active */ struct tty_port port; /* The tty bound to this DLCI if there is one */ +#define TX_SIZE 4096 /* Must be power of 2. */ struct kfifo fifo; /* Queue fifo for the DLCI */ int adaption; /* Adaption layer in use */ int prev_adaption; @@ -1758,7 +1759,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr) return NULL; spin_lock_init(&dlci->lock); mutex_init(&dlci->mutex); - if (kfifo_alloc(&dlci->fifo, 4096, GFP_KERNEL) < 0) { + if (kfifo_alloc(&dlci->fifo, TX_SIZE, GFP_KERNEL) < 0) { kfree(dlci); return NULL; } @@ -3035,8 +3036,6 @@ static struct tty_ldisc_ops tty_ldisc_packet = { * Virtual tty side */ -#define TX_SIZE 512 - /** * gsm_modem_upd_via_data - send modem bits via convergence layer * @dlci: channel @@ -3274,7 +3273,7 @@ static unsigned int gsmtty_write_room(struct tty_struct *tty) struct gsm_dlci *dlci = tty->driver_data; if (dlci->state == DLCI_CLOSED) return 0; - return TX_SIZE - kfifo_len(&dlci->fifo); + return kfifo_avail(&dlci->fifo); } static unsigned int gsmtty_chars_in_buffer(struct tty_struct *tty) -- 2.35.1