Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp635120imm; Wed, 29 Aug 2018 08:25:03 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbQLZmw89UzmddE8fIGjZAxUOPIwrQ6Otf7LUreo2rZdpLP3/yOLGH5U5ZLxBbDRV2mPJQE X-Received: by 2002:a17:902:d887:: with SMTP id b7-v6mr6239431plz.329.1535556303208; Wed, 29 Aug 2018 08:25:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535556303; cv=none; d=google.com; s=arc-20160816; b=uyQ6pYUk7dBc9Rmn95tPdOuZdM3WhT+At28ASbzJe5UoSIL8A7+GuM2xnSm8XrKhop YHLl3qQM0OV/PVMTQ35gV16JBDVs7Id9FPxJ5ufJr3JKrzJgklyGWTSCS9stBilZQq0I fCFTCy4kpHV9Vcqthlfo0nygkCDyRDM4svTjRKMyXj1nGTRr7QLIR3xepGgZTf3qG4UK gv625JFDg8LALpL38Roq60rzrIg5HqaKGuYm1gSk6hft5Kuvw+iwWmyvF9nXxYdZzBSi KbueMK61i54gXfeFtCFe/irtdNIJp38Ch8vUmjFPLpWbaspMkasAX0oEoFde9n0utctB htkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=DkSEt7gsE06UK80VtFfusEFHAZb9fGRAnYwyXviW5XI=; b=ZOwtDhKi3dwxxPP4Bsdy0lYbZaHQGSbw3lRKAc29bjGf8yBCdexagDd2YlLUSQKGv4 9SYWxwCU3cdBnXDogX8Au93m3gJfT9K2CNfBptHpOMjEf6IXog47I5C3+PPm96X69mUd traE3plksL+H0aj2dfGeeDzXfYwDqAa7B34mBa3ToGf0uCw1KVxIl7zEWMglXY6HboJj ddBMdhqjRF9NKaR0oNDC7AdnXTR7CQF32UeaMLIyNowyR+bTzAUfbOWZHVM4CfVsNcph iXsEaAUQLPgZ4bdgCQqdZZXAn8qxfhHifi2WA6pv7/A7xvzo7NWbhfcLve9ijlB3CgKR 2mCw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r14-v6si3893202pfa.44.2018.08.29.08.24.48; Wed, 29 Aug 2018 08:25:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729048AbeH2TUP (ORCPT + 99 others); Wed, 29 Aug 2018 15:20:15 -0400 Received: from gateway34.websitewelcome.com ([192.185.148.196]:36379 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728701AbeH2TUP (ORCPT ); Wed, 29 Aug 2018 15:20:15 -0400 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 573C5174E7A for ; Wed, 29 Aug 2018 10:22:47 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id v2IPf7AohbXuJv2IjfSUbY; Wed, 29 Aug 2018 10:22:47 -0500 X-Authority-Reason: nr=8 Received: from [189.250.89.86] (port=57176 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1fv2IO-000wzK-37; Wed, 29 Aug 2018 10:22:12 -0500 Date: Wed, 29 Aug 2018 10:22:09 -0500 From: "Gustavo A. R. Silva" To: Stefan Agner , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] HID: core: fix NULL pointer dereference Message-ID: <20180829152209.GA29831@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.89.86 X-Source-L: No X-Exim-ID: 1fv2IO-000wzK-37 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.89.86]:57176 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a NULL pointer dereference in case memory resources for *parse* are not successfully allocated. Fix this by adding a new goto label and make the execution path jump to it in case vzalloc() fails. Addresses-Coverity-ID: 1473081 ("Dereference after null check") Fixes: b2dd9f2e5a8a ("HID: core: fix memory leak on probe") Signed-off-by: Gustavo A. R. Silva --- drivers/hid/hid-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 4548dae..5bec924 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1000,7 +1000,7 @@ int hid_open_report(struct hid_device *device) parser = vzalloc(sizeof(struct hid_parser)); if (!parser) { ret = -ENOMEM; - goto err; + goto alloc_err; } parser->device = device; @@ -1049,6 +1049,7 @@ int hid_open_report(struct hid_device *device) hid_err(device, "item fetching failed at offset %d\n", (int)(end - start)); err: kfree(parser->collection_stack); +alloc_err: vfree(parser); hid_close_report(device); return ret; -- 2.7.4