Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2877444ybi; Sun, 28 Jul 2019 20:04:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7e9fkJyPb6qZokk2Ffbbi/NOv/QASXiLLBUzZhSe9ScJCrzuNC7pAHKZawRgMPbJNPwh1 X-Received: by 2002:a17:90a:17a6:: with SMTP id q35mr110170848pja.118.1564369470001; Sun, 28 Jul 2019 20:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564369469; cv=none; d=google.com; s=arc-20160816; b=avsbzFiq9aoipqt33nZ+rNUaOtAg3dftpxdWE8CMLy/LV8gFqaftkKs2jLwiUjIriM jmmTLKgfNQwyP/Ks/MxZAYBnL6VTFuaGrOUN+N5FRzkCqHSMQ8YyUgzxTa5QddwhTpyS C2b0bqm+QdA+OTwaHgrXKWiNoQUZ3h01fqYgs1HTYi5OT3ceWkQcWQZF/yyxD8saIYaL ql6L9MfUQm/LDiFaEOa/gVien5J231rcwuXVNhB+no+KQb7Lx7VqwyhbNN1gxKtnVUYB 8NQ45DTUiowXixv+2gdLruhtPKwpESW0sZ/8e02Ut81s/djP/zMrHUUhgMpffW+/fgiI 7O8Q== 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=vhdyHKbr6BRELOCiWIx8QFrf2iWsG4qCQT0zVGLttDQ=; b=oSTFOkRNMaq89pVVCMFLRaQ+assPfGwky21YFZOahzNrQtJZ4+fI/04M+aReqvW18F /Ysqya4LIgKjxPbCoDzivxuUmFy+wWKcHIturEIfKLsdsp+vKEOd7k1+4t8LtDckNueD kNFZItjToJhWk2mOcfJSEbabSKDfGkt+cb/KCbFs0hchFPMRUMFjCfkl1EZBhAhzlJGM oUtb4g+a06219nvnONXT3FMmmEqQDl4sMZ0UoWYQCbNks3qZdbzXW4AZVSWhN5+D+YB0 eRs9p0mmqd9hOKAbIOYHyMa/fJ0e0i8F5gqcG8EDC13E2Ye5XPZEDSgjc7lUkU2Ds5yU s6rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fYkbKVYb; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o8si24302520pgc.179.2019.07.28.20.04.02; Sun, 28 Jul 2019 20:04:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-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=@gmail.com header.s=20161025 header.b=fYkbKVYb; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726425AbfG2DDN (ORCPT + 99 others); Sun, 28 Jul 2019 23:03:13 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46989 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbfG2DDN (ORCPT ); Sun, 28 Jul 2019 23:03:13 -0400 Received: by mail-pg1-f195.google.com with SMTP id k189so8406761pgk.13; Sun, 28 Jul 2019 20:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=vhdyHKbr6BRELOCiWIx8QFrf2iWsG4qCQT0zVGLttDQ=; b=fYkbKVYbMf7WylANOPWUxOmxhD0YEN3Arb+f4/5LmCJvzWI/K7DodlBOlT/0Dv97xB hXR41NQfxhGHng8dn5Wi7pv5WiWYA9ZnpivmMzmBCBcZFs5dalWXv08FTCRV/NHF+zQl 4ttOfg6yC8yU7jbOF5XFNpAG+klbqalXmZC4Fb0DQlaepm6hWzrhQpDTt7SxJzS1j8Wy Rt5dgMjxwjQkRMoX8/Iu/I4EdkJ0Do8pp1PMwNPoMy95fvz7oB2E+ZkEq7deZw5a/YyN 5XM3okKO7MCXLRC4r5dzsQU7z28G6i/DbBi4BjAuETipwPfylJ3bMPLg5mI4l44V3KIZ wcGg== 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=vhdyHKbr6BRELOCiWIx8QFrf2iWsG4qCQT0zVGLttDQ=; b=dXKauXZqnFuaPIqlHXmzDLchO5WM0Eau77ftTevClwOZ32o/swJO1Ii4FE8xFt+EW4 +LXgZafWYN3hwcE23IKRqy3jKFO1ovZCXscdUbYNlGK0h12Jo2/NfbTI8GnJwch1pGte liQFHBefRj33Oku5h7m3NZWlcE5AqVynYJ5KMOTL9Co0vD3Nod7AFS2BgAllR3DJAUOo 0lXJmYnixhncgiGV3rqkSVnxf1ihxzLu7us0UOthcECmaDV03cJlv2Z/BZHSqCFGyE8B d5xa4ceY2wEiHlPXdiq7n0SS8nUMSm2BRKRan/742Xphacz3dxh6gewtW9kxXw6MOlY1 aeWA== X-Gm-Message-State: APjAAAUWIisMkMNLcOaoTOWO4R7yWLi3UYtYv8vqGt5xpbbqQEATwuBL x5TzCLTbSHPLdrfkDNzyJmg= X-Received: by 2002:a05:6a00:4c:: with SMTP id i12mr34459331pfk.134.1564369392804; Sun, 28 Jul 2019 20:03:12 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id h14sm74535781pfq.22.2019.07.28.20.03.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2019 20:03:12 -0700 (PDT) From: Jia-Ju Bai To: kvalo@codeaurora.org, davem@davemloft.net Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] ath6kl: Fix a possible null-pointer dereference in ath6kl_htc_mbox_create() Date: Mon, 29 Jul 2019 11:03:05 +0800 Message-Id: <20190729030305.18410-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org In ath6kl_htc_mbox_create(), when kzalloc() on line 2855 fails, target->dev is assigned to NULL, and ath6kl_htc_mbox_cleanup(target) is called on line 2885. In ath6kl_htc_mbox_cleanup(), target->dev is used on line 2895: ath6kl_hif_cleanup_scatter(target->dev->ar); Thus, a null-pointer dereference may occur. To fix this bug, kfree(target) is called and NULL is returned when kzalloc() on line 2855 fails. This bug is found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- drivers/net/wireless/ath/ath6kl/htc_mbox.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath6kl/htc_mbox.c b/drivers/net/wireless/ath/ath6kl/htc_mbox.c index 65c31da43c47..998947ef63b6 100644 --- a/drivers/net/wireless/ath/ath6kl/htc_mbox.c +++ b/drivers/net/wireless/ath/ath6kl/htc_mbox.c @@ -2855,8 +2855,8 @@ static void *ath6kl_htc_mbox_create(struct ath6kl *ar) target->dev = kzalloc(sizeof(*target->dev), GFP_KERNEL); if (!target->dev) { ath6kl_err("unable to allocate memory\n"); - status = -ENOMEM; - goto err_htc_cleanup; + kfree(target); + return NULL; } spin_lock_init(&target->htc_lock); -- 2.17.0