From patchwork Wed Jun 7 13:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 690475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62B0CC7EE23 for ; Wed, 7 Jun 2023 14:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240759AbjFGOIM (ORCPT ); Wed, 7 Jun 2023 10:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240726AbjFGOH6 (ORCPT ); Wed, 7 Jun 2023 10:07:58 -0400 Received: from qs51p00im-qukt01071502.me.com (qs51p00im-qukt01071502.me.com [17.57.155.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 844682695 for ; Wed, 7 Jun 2023 07:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1686146263; bh=pzOiGFlXxe7wjzq9Fg+hUaE4VwJuvopU7xJEFjn/GtE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Ess5UdrSTD0MqGSfHurZPTz//Rqt34b2G1OxfCVLZ6IQSlR/f/b61dAuKilsJu9Zg 4fqTo8mJZtQPDwDaXMyspBRCDAWBG08P0/TB2aDugahJpWcLhVCt6WzMvGQgQb/9cz SNfEwdpku/4fNbKI4CvozQyvM3x0gArQsV4S6PtiJ0qg6C5i9waqC0knlUqIZPTMhf Oc616rEAj3lmVp0CoaQ0XnNUiPNwUVx/0bKLhmJx6KUTAF6sSDmNitvvXEUCE2lpje 8plkSlF0/IyYYW+OF1AzpNUYp1ee8HfP8qT1tZrLhylzohU2j/G/DhHOZu9R9avLFZ iE8Di/KhMlZTA== Received: from fossa.iopsys.eu (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01071502.me.com (Postfix) with ESMTPSA id 1526666802E9; Wed, 7 Jun 2023 13:57:40 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Jan Kiszka , linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v4 1/4] usbnet: ipheth: fix risk of NULL pointer deallocation Date: Wed, 7 Jun 2023 15:56:59 +0200 Message-Id: <20230607135702.32679-1-forst@pen.gy> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: FF6KxZYHCoMp_WPLSmy58s38wlihLML9 X-Proofpoint-GUID: FF6KxZYHCoMp_WPLSmy58s38wlihLML9 X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E138=2C18=2E0?= =?utf-8?q?=2E790=2C17=2E11=2E62=2E513=2E0000000_definitions=3D2022-01-12=5F?= =?utf-8?q?02=3A2020-02-14=5F02=2C2022-01-12=5F02=2C2021-12-02=5F01_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 spamscore=0 clxscore=1030 suspectscore=0 malwarescore=0 mlxlogscore=350 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2306070117 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Georgi Valkov The cleanup precedure in ipheth_probe will attempt to free a NULL pointer in dev->ctrl_buf if the memory allocation for this buffer is not successful. While kfree ignores NULL pointers, and the existing code is safe, it is a better design to rearrange the goto labels and avoid this. Signed-off-by: Georgi Valkov Signed-off-by: Foster Snowhill --- v4: No change v3: https://lore.kernel.org/netdev/20230527130309.34090-1-forst@pen.gy/ - Reword commit msg to indicate design improvement rather than bugfix - Add missing signoff for Foster Snowhill No code changes v2: https://lore.kernel.org/netdev/20230525194255.4516-1-forst@pen.gy/ - Factor out goto label change from v1 into this separate patch v1: n/a Part of https://lore.kernel.org/netdev/20230516210127.35841-1-forst@pen.gy/ --- drivers/net/usb/ipheth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index 6a769df0b..8875a3d0e 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -510,8 +510,8 @@ static int ipheth_probe(struct usb_interface *intf, ipheth_free_urbs(dev); err_alloc_urbs: err_get_macaddr: -err_alloc_ctrl_buf: kfree(dev->ctrl_buf); +err_alloc_ctrl_buf: err_endpoints: free_netdev(netdev); return retval;