From patchwork Mon Apr 26 09:45:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12224091 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F160BC43460 for ; Mon, 26 Apr 2021 09:46:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B94196103E for ; Mon, 26 Apr 2021 09:46:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232800AbhDZJqo (ORCPT ); Mon, 26 Apr 2021 05:46:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:60672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232239AbhDZJqm (ORCPT ); Mon, 26 Apr 2021 05:46:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D8E2A61075; Mon, 26 Apr 2021 09:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619430360; bh=qpsdBN6ORDIHKKWXNLHLog5L3frURDHaOI1Eg49/jDw=; h=From:To:Cc:Subject:Date:From; b=eCvxwAUO+BFi7IJ3TozokehnYq5mw16uyk/RuXzPEWJtfDuOBqsbb47lfK5Mp5vNS wI9AOTNYUvdvTk2+4MSVKuMsShA6vD3bNrprf7kgVI//ciAGLqpdXIztWeR3p5wsvO LYIKbOiGoeC21CLg4KwAouroC2xWxIhyCON0sbHD5fe30fibuGPqaiOD9m4OamQsnq rk0r14Y/ue8IS8JA4BkR9sbn4+Ftv7z0uhfmt+l62xOL6enmYR/dWms2bLUIFaG1Bt 58TroM3D+7u1HTrOHbZ3F2dhGZ4BXIUW8GHHNDmKp+S/OJ1gOkaqauD6Dp2Ba24y/e aZzaUTbgITCUg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1laxog-0005t0-I6; Mon, 26 Apr 2021 11:46:11 +0200 From: Johan Hovold To: "David S. Miller" , Jakub Kicinski Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH net] net: hso: fix NULL-deref on tty registration failure Date: Mon, 26 Apr 2021 11:45:42 +0200 Message-Id: <20210426094542.22578-1-johan@kernel.org> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If resource allocation and registration fail for a muxed tty device (e.g. if there are no more minor numbers) the driver should not try to deregister the never-registered tty. Fix up the error handling to avoid dereferencing a NULL pointer when attempting to remove the character device: BUG: kernel NULL pointer dereference, address: 0000000000000064 [...] RIP: 0010:cdev_del+0x4/0x20 [...] Call Trace: tty_unregister_device+0x34/0x50 hso_probe+0x1d1/0x57e [hso] Fixes: 72dc1c096c70 ("HSO: add option hso driver") Cc: stable@vger.kernel.org # 2.6.27 Signed-off-by: Johan Hovold --- drivers/net/usb/hso.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index cfad5b36bd8e..81ff54e9587f 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2710,14 +2710,14 @@ struct hso_device *hso_create_mux_serial_device(struct usb_interface *interface, serial = kzalloc(sizeof(*serial), GFP_KERNEL); if (!serial) - goto exit; + goto err_free_dev; hso_dev->port_data.dev_serial = serial; serial->parent = hso_dev; if (hso_serial_common_create (serial, 1, CTRL_URB_RX_SIZE, CTRL_URB_TX_SIZE)) - goto exit; + goto err_free_serial; serial->tx_data_length--; serial->write_data = hso_mux_serial_write_data; @@ -2733,11 +2733,9 @@ struct hso_device *hso_create_mux_serial_device(struct usb_interface *interface, /* done, return it */ return hso_dev; -exit: - if (serial) { - tty_unregister_device(tty_drv, serial->minor); - kfree(serial); - } +err_free_serial: + kfree(serial); +err_free_dev: kfree(hso_dev); return NULL;