Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp721467pxb; Tue, 5 Apr 2022 20:18:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzePbCeVUxx0zfMZpOO9CsFS6M8k8aO5O2GtprP/euNzxyT75fCJfhKhUnK43Ll8u7oytbb X-Received: by 2002:a63:d456:0:b0:399:4c5a:2682 with SMTP id i22-20020a63d456000000b003994c5a2682mr5309100pgj.573.1649215093440; Tue, 05 Apr 2022 20:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649215093; cv=none; d=google.com; s=arc-20160816; b=PAveDJwUhflnpSpgK1viycgJ9qbaJ6AUTWPTDV2qzySLS12JbTQALxozAINqfbOZtE 5wvUTIyhPsWYxNK/B5ATTOgBOjidJ5BPysL5NFO3v8QIVXQBxZvc9458zbL1CnkriuC7 fU4ngJ4oQDE/7Ka0OkNwLdb33DFxN32r1s+OTyKQp4BDPWvtm+NBEPCKk004Y3WC8cYL 3Tt/OJ4hUk3KiaOO8dNj0x2/Xg5dsS6biy1f55/VD51mkastps5Kt2hW6Hxip8ljJBOD R4JwoU1v5kxXJj8rgdUFgA7R2IjJh8Yyi286wDKBFpPnqSeaymL5vmpIb2K+20bsR8iX 49Sw== 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=AJ6qtjEdnpFnCEIB5qyMu0puaV5yWsePJNPbvrjUbjA=; b=OMvDOOB8CW4Bwm9L/AlaQSSxGtw5wjuswgVk214xft869lmXQATaBQYr16/OsPnryZ Uanp3hU+fUpxDzKOPguyweP9RTl0tGaRWoR6OdweNn47scoBbYkIh5+GFOvfmTvgd4ff 0tHOgcg+zMZUtHkvMlklF9L1jI6ZCy+VESBE7BfyowEA/vC7X2B0uhQ5UIh+U2JvzjMg X851FGgBHfLQY6LIzv2rSFfpMGGQxffmHGOtsVvBanvvHbnSGqKu+yyMaG9CFsDQ+nLp pAXE7vqr+B1spAzbIlG/UgJMDveGIhVa78QgWwLgAwB7QRuHmBi/6T/Rzq4E0f/SXViY Y/hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pr1k1YaI; 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 n189-20020a6227c6000000b004faa6d525ddsi13737593pfn.269.2022.04.05.20.18.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 20:18:13 -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=pr1k1YaI; 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 249E632E966; Tue, 5 Apr 2022 19:54:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243199AbiDEJjN (ORCPT + 99 others); Tue, 5 Apr 2022 05:39:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239363AbiDEIUA (ORCPT ); Tue, 5 Apr 2022 04:20:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53D4FBF024; Tue, 5 Apr 2022 01:11:57 -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 E614860B0E; Tue, 5 Apr 2022 08:11:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 001E8C385A0; Tue, 5 Apr 2022 08:11:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146316; bh=UALNzqvcXmqNvJhIT5/hpuibeLTK0XCfJTnwpvzLAw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pr1k1YaI3d1UG/H3f7DM9+ZihIlyjtZZrfaxEcRnhL9ycGi5n01+TIZoMhG3icH/v HroYoLB70XJ52Yzi9ED4PPSdl3BHYXdFMxg+Pfv+WL7KqhBM0KadcOZyO8/M9qJhwD 4aInXqNi7BxEXUeaa57dCY8Uhdzz4+/MENFeJocI= 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.17 0713/1126] mxser: fix xmit_buf leak in activate when LSR == 0xff Date: Tue, 5 Apr 2022 09:24:20 +0200 Message-Id: <20220405070428.526224623@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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 c858aff721c4..fbb796f83753 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c @@ -744,6 +744,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) @@ -753,9 +754,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; @@ -775,8 +776,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; } /* @@ -821,6 +824,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