Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3556739pxb; Tue, 19 Apr 2022 05:26:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdR0O3WVWHQKFcB3HbxILAw4DkRtJZb9Y8vFfA5dBY0WGWwqBRqKZKRFV0dQ1EtUK7q+KF X-Received: by 2002:a17:907:eab:b0:6da:8ec5:d386 with SMTP id ho43-20020a1709070eab00b006da8ec5d386mr13424837ejc.668.1650371162805; Tue, 19 Apr 2022 05:26:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650371162; cv=none; d=google.com; s=arc-20160816; b=tT82/zGQvm7qvbyrUKixZDSRM8LnarPGvg5jMc1wYH9ifnc2VuCoosPT2pUWqO3qpy mFpZuCdQn6G2nsemmLFXYTHLrmBHCMKzAT9uqGVMEFiaoyUPlyhDQnVsThQh7/GKMc1y 6q3aXkeLmOcq+4IfopCGuvhtTpmCGPZxVObm2qUJz3dEonPdKWjBIKv+tbodovQ9B4pM zdpDnXHRlrRdpGLIfaF193jVLQTmbuFObIcJ1BfpHBRTGDElClcD1PVXnv4i7AMXoHwC 4465CegC//XjA7CCG1yYj/6p+SKwR+X1mnIY6aiEVkCkIY9Oy0l2Ln+rCzdDtOyUDTdE foEQ== 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=RqSYHLaq1C1vUEseHscMOgtizpw91SAje2IPHAEob2E=; b=Zou7/o0VRo+NRTFEf8kHgeGoV8WtYDosO2jc8GB7/WjkGmPEKUErYA7/BJ/3Cr3tX6 cn4qzhvuVH2O3xmbp51WL0IgNw3cwB/kExR7wjc2gyHFBSfmWyXyb45vRU3h1QdPZKTu pPATyC0EkA9SlfdZn41cRVNWBcKmpzkMSB/panvDHpIvyMOQ7RCjkDQ1grodjE7/YOmw tC7HrA9h4Xk4q7/aZQcd5tuaMYL8Bs27YwmTBbV1ppF0ooWcK1uzOX05vz8JECpaSoLd vIjV3oT40sokRfrNjxX70GESZOa6FDLL4EjRMxvsPUqHNH4Vj6P1tfDjNDeWoRZ4/AVX 5yVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DLS/M0IX"; 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 lt22-20020a170906fa9600b006df76385cf8si7970963ejb.408.2022.04.19.05.25.39; Tue, 19 Apr 2022 05:26:02 -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="DLS/M0IX"; 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 S244101AbiDRNwE (ORCPT + 99 others); Mon, 18 Apr 2022 09:52:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244839AbiDRNa5 (ORCPT ); Mon, 18 Apr 2022 09:30:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 171301EC54; Mon, 18 Apr 2022 05:55:51 -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 A7157612BB; Mon, 18 Apr 2022 12:55:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B004CC385A7; Mon, 18 Apr 2022 12:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286550; bh=XH/Kan+cTZtZrlbEHeit+4DII2CBsZqniMAz6XbgDrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DLS/M0IXsRd17B/y5sNL+NioWcHlvO0o52HHeH40WUikxWdeLMosS9lp9MpsA4JEL oQiq1i24O1MUCBlg10CSwZqQ/yLZo1GxkNCgu4I3KSugMecFFZqnTbGSiKEWtwgfDz lwxt44ukcYsaUy3abxjz3MbpWRNfu6YF0oZp5iVY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby , Sasha Levin Subject: [PATCH 4.14 129/284] mxser: fix xmit_buf leak in activate when LSR == 0xff Date: Mon, 18 Apr 2022 14:11:50 +0200 Message-Id: <20220418121214.940474839@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@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: 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 7dd38047ba23..31d5a4d95c2d 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c @@ -866,6 +866,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) @@ -875,9 +876,9 @@ static int mxser_activate(struct tty_port *port, struct tty_struct *tty) if (!info->ioaddr || !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; @@ -903,8 +904,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; } /* @@ -949,6 +952,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