Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp949380pxb; Wed, 6 Apr 2022 05:07:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNpntqk3xr+HAKNc22VimHjdt9YWiGXtg5nneFAy/5nW/3wDV1B1TxTbo0iYFTkwpYtG1S X-Received: by 2002:a63:fd4e:0:b0:399:3005:d0e0 with SMTP id m14-20020a63fd4e000000b003993005d0e0mr6936757pgj.276.1649246824383; Wed, 06 Apr 2022 05:07:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649246824; cv=none; d=google.com; s=arc-20160816; b=b/uOfvlNP5U7o0cHMQ00Yb3n5H/aGDZZKFpk5uKeB+vUPAJKj/Ofx+M0krt28XKy23 n9K3x6/ZGElKrrnfkTDOlDFo3JBytryeIicoMAi9+hoEH4iXAJg0R6TbDUFum/q6ZFPR nEikrLC/D3WM8/Rxt4iyYPIss8y75Eyur5vtqRflY5lYwPLrUlcRx8GCkYtEnPPwvgKn VCm22Pb3DH4oF+ajG0Hk4IxqQiwOVDH7wwiPkrWgEMLkUfCrokWbfFUylWAyAI1Aapyl y8/3QUvvhmOMuolbuUN93MZaT01qqtdpP4jRVIJsOWOK0wQjuO0ioOeqOwTEAgJzHWlF 1OIg== 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=+6TjEXNQTBF/cMUOeLLgqSWlqtr0qHfzCSZGvhhLz2w=; b=0pFMCnXrB/Djlf32Zagy3+UKjvWy28CDV8Wt5zAv7M3MRGO21ix6Tvws5kxFtj1Bhd eB3+GZ5by/Iu3ukKppQmXP+Rg1VFfpB8C7U2ZCC+A9ZWsTOHy3M4XDn72Z7MA6zbK8/z DhZlO/3tbx3/Gy08gstpHOexGj3oUcN92JCgWXjGvb2+4qO+liHYJhS0Ljs6sMTHcL/C wJmRoyaLijsgUmh+RQvJnLj+cau0b7J0YKK1zyjymcqvquf2PkrQfndf1GBFbfcVu5+X o5S956sTmSpHIWWJqD0ao9tOXEEtBCtNeqihqAtiTfj2I8KHBzrKePvYe2I+gpm0qpfV ignw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FpLe5cGM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id w14-20020a17090a4f4e00b001c9a57712bdsi4300572pjl.103.2022.04.06.05.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:07:04 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FpLe5cGM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 4374868AE2B; Wed, 6 Apr 2022 03:37:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1452523AbiDFAbD (ORCPT + 99 others); Tue, 5 Apr 2022 20:31:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349463AbiDEJty (ORCPT ); Tue, 5 Apr 2022 05:49:54 -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 2ECA53884; Tue, 5 Apr 2022 02:46:37 -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 D3BD4B81B76; Tue, 5 Apr 2022 09:46:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EE2CC385A2; Tue, 5 Apr 2022 09:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151994; bh=UDPEKFoH/ToYUig5EmJ+UIbJ8kL+YWnd8kGY9L/aMqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FpLe5cGMbGvoyEHu4yQGlupS7Oexv4ZnsoJlcq2T4V5Nn9XDaF/czPFH+hEoxL2DN Sl5/GxcYT/Q3f7134IvVNhUxDjDR0MCKgiYWcGDedIWJ+uDd4NnwiEMK+m7Lx6mYz6 o9mQZbFRtahPS/sFsyFGUR/naxZrs0g/eZ5dG/4k= 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.15 579/913] mxser: fix xmit_buf leak in activate when LSR == 0xff Date: Tue, 5 Apr 2022 09:27:21 +0200 Message-Id: <20220405070357.201717601@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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 da375851af4e..3b3e169c1f69 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c @@ -711,6 +711,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) @@ -720,9 +721,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; @@ -748,8 +749,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; } /* @@ -794,6 +797,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