Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp652319pxb; Tue, 5 Apr 2022 17:23:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTuDpSHG/1IQOEKoZwDPaY71bTZ0hSrz/bBrf28IjH1HTHOpuPidsJFVK2UgqbPiSFNWtX X-Received: by 2002:a63:6f44:0:b0:398:31d6:e37f with SMTP id k65-20020a636f44000000b0039831d6e37fmr4902701pgc.177.1649204602668; Tue, 05 Apr 2022 17:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649204602; cv=none; d=google.com; s=arc-20160816; b=qP9uS6v8KzXTo+6y0CHNBxNqi0Be/+YaptRxK09WjDM9SYd5dpvwbr82uS59dNlxO1 V/uUN+eLHnYPrKjWwWGFpwwG9UCym82II7W3obN2zvXlKLg4N8V2VS2fJYHzHh0cpKGk E/CDhblCmEoDglLTcJHv4vKJsmSbTpNX8nrTyjFa4SueIZzaJfhmfcnpeMFmSg5sRZa/ uS5/FtU+9EVd+4dZeVRtw6QZbvMtjGmWUD/DBbpTLqnJPlmoDQAhCHdEzLBIjvRVoSYY LCpzadp7EPbIvQyFiNZ7d1mg2bbz6dnpK2YOmgsB3xmAt0S8gC4AT8UQQETXSACWdl7r PfWw== 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=YBlCVBQW8OXEabCJ1R6y/uk3+iEIFVY8+65F5TkXpxw=; b=PeviKjRRztzpPx3cjSeBdSYjGOdR2IsNc8Tczgbm53rYYecI6ABosTvaG/Vbw07IpX pbATJ4D7i22kuPT2YLW4w51MU++yCJGwId6SVHnn4ncOMeTVkTVujeD7oIsjYxKjQpDT cPyEMJ85DzRmU33kSAHSp+jGaS98+1sDIa5FdlPEDOChEhqCo2eed1YpCAMiUdIlFcqY GghUcUNEeBQKYHw35gWHtGVSObe/K+KMLqZ6UDlSLAO4Ic/yt5hXYFGIWKzKQxtk81DZ TOeV1TD5xn0Ei6BrOonw6F9MtVFYCT6uX0cIynrds88peGEfWFyuHYlvff4LiZ7wSPBj mNvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hu4hLyKG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q9-20020a056a00084900b004fa3a8dff73si15115604pfk.42.2022.04.05.17.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 17:23:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hu4hLyKG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A846E209A68; Tue, 5 Apr 2022 17:09:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380638AbiDEMyB (ORCPT + 99 others); Tue, 5 Apr 2022 08:54:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244102AbiDEJOP (ORCPT ); Tue, 5 Apr 2022 05:14:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A69D73DDF6; Tue, 5 Apr 2022 02:00:38 -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 ams.source.kernel.org (Postfix) with ESMTPS id 52797B818F3; Tue, 5 Apr 2022 09:00:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D611C385A0; Tue, 5 Apr 2022 09:00:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149236; bh=ROnrbzz1l46AppRuRx0ztfxHB96FsZrQXsAc4TedgXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hu4hLyKGP5TGp0UbFMQf5fyb6XZA4huXEUSByB/m7A+67gG/S8uw6TXscTIXPZNMn 8WLyiOFgCWv6Oo0ralos1Kxt6rBirc4QiwjWWk9DhDncKFFDUdayLGCZrhHtsCOcap qcPNiX5H8f7jm/tE/sMaLBO9nVhd0Ktj3iM5AEk8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby , Sasha Levin Subject: [PATCH 5.16 0644/1017] mxser: fix xmit_buf leak in activate when LSR == 0xff Date: Tue, 5 Apr 2022 09:25:57 +0200 Message-Id: <20220405070413.399273841@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Jiri Slaby [ Upstream commit cd3a4907ee334b40d7aa880c7ab310b154fd5cd4 ] When LSR is 0xff in ->activate() (rather unlike), we return an error. Provided ->shutdown() is not called when ->activate() fails, nothing actually frees the buffer in this case. Fix this by properly freeing the buffer in a designated label. We jump there also from the "!info->type" if now too. Fixes: 6769140d3047 ("tty: mxser: use the tty_port_open method") Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20220124071430.14907-6-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/mxser.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c index 39458b42df7b..88d2f16fbf89 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c @@ -719,6 +719,7 @@ static int mxser_activate(struct tty_port *port, struct tty_struct *tty) struct mxser_port *info = container_of(port, struct mxser_port, port); unsigned long page; unsigned long flags; + int ret; page = __get_free_page(GFP_KERNEL); if (!page) @@ -728,9 +729,9 @@ static int mxser_activate(struct tty_port *port, struct tty_struct *tty) if (!info->type) { set_bit(TTY_IO_ERROR, &tty->flags); - free_page(page); spin_unlock_irqrestore(&info->slock, flags); - return 0; + ret = 0; + goto err_free_xmit; } info->port.xmit_buf = (unsigned char *) page; @@ -750,8 +751,10 @@ static int mxser_activate(struct tty_port *port, struct tty_struct *tty) if (capable(CAP_SYS_ADMIN)) { set_bit(TTY_IO_ERROR, &tty->flags); return 0; - } else - return -ENODEV; + } + + ret = -ENODEV; + goto err_free_xmit; } /* @@ -796,6 +799,10 @@ static int mxser_activate(struct tty_port *port, struct tty_struct *tty) spin_unlock_irqrestore(&info->slock, flags); return 0; +err_free_xmit: + free_page(page); + info->port.xmit_buf = NULL; + return ret; } /* -- 2.34.1