Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2407731yba; Sat, 27 Apr 2019 23:44:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAEUvonWhmRUHTf+Hc7rH5AaNzvI8vXqmHCXUkv0pExWuJAY4GtaWzI5Dnbcnt1wKKwMIz X-Received: by 2002:a62:2b43:: with SMTP id r64mr21507646pfr.210.1556433848864; Sat, 27 Apr 2019 23:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556433848; cv=none; d=google.com; s=arc-20160816; b=ZdmMC8FqMu2xKS+yvQ98FRNghGG6bE0QpFVWKyGS5uSCkT34cUIZDnxDjQLpsvnsEP jEchffOoaA+Xkuu1QqPHUffpjfkKWi57XQ2zhpjTtONMhph12G707l7x8dSt3TQV4Nqu uJaDuHl+/nTbg2xToGYD8KHX1HYgf7A6+PZGUV14aEPk88fuQHjs7b6IBkd9udcXYiOJ EROkhXUgqy2x6YETbqqfVphSVi0qBL/zIKxUFF/8y4yZfynqVPTPNPOuiw3Y8j3AmBUq vFRVe+HspgbVPrSaxgTS9+7G1Olau5o7ViauIo/w6lU4Av2Ktv2WMLIUU3kbG7klXISl Eh0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=dCtKX+pD+Z8ECSwxAGND0lenK4rzuRAysijRT4r9928=; b=noDxDHoHmzGlaCq2HIl2HiFYKvz1nFcKujdWHefIEK8vfq3jQpR/0UHJ25yZf1yqqv 0Ds/06+zi+ZSXBgKpiKE3kcTzzJWasXsNxTCr5Qod9iOFCuMiDTb2NXRejrS48yZL9ih 4iWY+BsL5AxFB0YjEjJN/bVEsYE+JuDhhvo+woPFemzLtGGT2DAIdXl0YPGKmOChZ3qi csuvI+65DXlO74bf7hDtyQKU4aWhX7NJVYpK4sk+2ZDId8dTr8S8hNxqMkf25gqHq6bf opIVweERr4KZumLKYdVxnb24i/+s7vJdVfkKU6qaE2MgCaLo8NcFBGr1tvuGqmSG2XOl UIKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=BLfbkACX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n13si27089587pgv.11.2019.04.27.23.43.49; Sat, 27 Apr 2019 23:44:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=BLfbkACX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726445AbfD1Gmv (ORCPT + 99 others); Sun, 28 Apr 2019 02:42:51 -0400 Received: from mta-p8.oit.umn.edu ([134.84.196.208]:34356 "EHLO mta-p8.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726052AbfD1Gmv (ORCPT ); Sun, 28 Apr 2019 02:42:51 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p8.oit.umn.edu (Postfix) with ESMTP id 3C550DE9 for ; Sun, 28 Apr 2019 06:42:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p8.oit.umn.edu ([127.0.0.1]) by localhost (mta-p8.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9lyHaMZ9NyvA for ; Sun, 28 Apr 2019 01:42:49 -0500 (CDT) Received: from mail-it1-f200.google.com (mail-it1-f200.google.com [209.85.166.200]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p8.oit.umn.edu (Postfix) with ESMTPS id 1765DDD6 for ; Sun, 28 Apr 2019 01:42:49 -0500 (CDT) Received: by mail-it1-f200.google.com with SMTP id o197so6892901ito.3 for ; Sat, 27 Apr 2019 23:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=dCtKX+pD+Z8ECSwxAGND0lenK4rzuRAysijRT4r9928=; b=BLfbkACXnG8TpTRmYKunbL4CiOzxnkePBMfwtdcdWl/kIXhCjOcI2YON9uEroEIqJI ebb9TwPy7EM6XMXLnsSsQhjQisHlXBE3JVTXONzd8U/GgpsYIh/oy2EXZp8sv4VZc6za JEQeRFCSmta12GJYWplyzHEv6oUKZT9WW7O2AQviCtzOYS877DSfNTwWb9tV6/BzyjRc EmCcVvjh8KvHxHoBAUYIl3vlQKd2q/kDxfxHC9wlKtF46gBX4Wu2wgP68etGawyW/NUV evya0qtasnMW0gQ+g8TftViBwUE8QihBzDG7tIqLxo+r9E+JPvUs0o6e6kgZRMUyp4i0 9WhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dCtKX+pD+Z8ECSwxAGND0lenK4rzuRAysijRT4r9928=; b=NBtRHY84Z0rDRpD012jfINj9VXBPlc62UNT1bb/K7PdLclgy79agDMYBCCojZG8deY PIVHIs0/fhaNNQbNHnHJHadbjPhnATukzzb+mjkk+aBjyRfno3RnBAvFcql4+2gzLphG EaX15jWOfOCDdlTG8KXkhOFQiPXjOjcoUNRZHARLVkUzLX6Uw/b7vUUicP06cLpNoFdi K51pdBvx9uwiAz8nyydunDGZC6mmGfUUo4vmG38gKRc/jSDPIV0xxPFEgLU4K/BLFf6k ofzKpYf95cAlAVgRUleRCKpr8BUJv3w9X9K3gOwHwpKIeAT6TO98FBYK3OIwsbkBRLGy B1lQ== X-Gm-Message-State: APjAAAUTy67ZpX60X77gJUnMntJFElBM3At0rL/ESxFoaI64czc7jGSS Mrl7N2w5fl/5gedZnqarnfvJjQ+MQDh0PUuwslLYWV3DPtUfzQ62uTctsloGEwhG5tA+eRFCfql QMA8t70AAyPMU3T5HGshQoHD9tRnq X-Received: by 2002:a24:ba15:: with SMTP id p21mr16196062itf.66.1556433768778; Sat, 27 Apr 2019 23:42:48 -0700 (PDT) X-Received: by 2002:a24:ba15:: with SMTP id p21mr16196059itf.66.1556433768619; Sat, 27 Apr 2019 23:42:48 -0700 (PDT) Received: from cs-u-cslp16.dtc.umn.edu (cs-u-cslp16.cs.umn.edu. [128.101.106.40]) by smtp.gmail.com with ESMTPSA id k131sm4139784iof.82.2019.04.27.23.42.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 27 Apr 2019 23:42:47 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Jaroslav Kysela , Takashi Iwai , Kees Cook , alsa-devel@alsa-project.org (moderated list:SOUND), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] ALSA: usx2y: fix a memory leak bug Date: Sun, 28 Apr 2019 01:42:32 -0500 Message-Id: <1556433754-3291-1-git-send-email-wang6495@umn.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In usX2Y_In04_init(), a new urb is firstly created through usb_alloc_urb() and saved to 'usX2Y->In04urb'. Then, a buffer is allocated through kmalloc() and saved to 'usX2Y->In04Buf'. After the urb is initialized, a sanity check is performed for the endpoint in the urb by invoking usb_urb_ep_type_check(). If the check fails, the error code EINVAL will be returned. In that case, however, the created urb and the allocated buffer are not freed, leading to memory leaks. To fix the above issue, free the urb and the buffer if the check fails. Signed-off-by: Wenwen Wang --- sound/usb/usx2y/usbusx2y.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c index da4a5a5..0817018 100644 --- a/sound/usb/usx2y/usbusx2y.c +++ b/sound/usb/usx2y/usbusx2y.c @@ -303,8 +303,11 @@ int usX2Y_In04_init(struct usX2Ydev *usX2Y) usX2Y->In04Buf, 21, i_usX2Y_In04Int, usX2Y, 10); - if (usb_urb_ep_type_check(usX2Y->In04urb)) + if (usb_urb_ep_type_check(usX2Y->In04urb)) { + kfree(usX2Y->In04Buf); + usb_put_urb(usX2Y->In04urb); return -EINVAL; + } return usb_submit_urb(usX2Y->In04urb, GFP_KERNEL); } -- 2.7.4