Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3923689ybi; Tue, 18 Jun 2019 08:39:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSbYVmMMbC16hB/i7HkYGcoicP6DTcaWyOa/FDuWNHoo3/vOR8Fs/QMnNucU5ocajCup/d X-Received: by 2002:a65:454c:: with SMTP id x12mr3268792pgr.354.1560872388731; Tue, 18 Jun 2019 08:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560872388; cv=none; d=google.com; s=arc-20160816; b=Y1WfpwP5aEgJPQlfWYLy8oxF+N0sEilxHUisCin45bqAOQTbOIH12m9nZQ391kzlN1 5LHI+nS6yBQKRvgoOfSJLro+UjDIMMLzVDsCy6Vt1LaS8SwiIALG+uTUuCm+JbZ8Aad0 aUJ9D0UPF41HG1UTCP8V1i87uIChPsoKIg0NgXF7vpCGwKWjhyZIqlG/sZgo/3iNN7gL 10wxgI+AE9JpQLsfmjTGBySrAHi8+J+0c0C7EZT8vC8Jsp5zEpdgdgtQ43NpWmDA9sTs r+Hn3ZSr7d17dUYpRfw92pB2KhHm3kWCAh8f6LCqLbWg630Tmqt9njpUzHWxgpY1p+Hv 1TTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=SO+Fc7QHK3ZWNGjAtBuqseDFrtb88Y5pcGabp47sz0Q=; b=kGkQk+Nl/HvRLW+roQx77t4BiPRgXPNcHax3PkNg7V3PD5qMn2UZzzs9IxUbQnTzSD SpS29GjF3PNj+ZvvxzwfYPkAhI60hd4+zSFWy1HjHWGrRfPnDShuwYsAlhIbo4JR7S/v PBKiu7rvEAioemjyzioNq/HTNPSEn23EDeuvFMnbkK3+YBQ55Mj0Zj64Mc9Ja0SP1D7g ouupHBXYlgfwehb6uVCSaKu9xxo5WywFtahxo0OzxY51m3/G1teQDqa+7llDG9q4RJoT IrgDAlifpDsobFaLzuwxCQaB1+PtGXpPA3x6m/BXbQn1cP1o3cqyUgvvG79dxM9iDTPK 7WOg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i19si8076804pfa.232.2019.06.18.08.39.33; Tue, 18 Jun 2019 08:39:48 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729386AbfFRPj1 (ORCPT + 99 others); Tue, 18 Jun 2019 11:39:27 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54249 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729189AbfFRPj1 (ORCPT ); Tue, 18 Jun 2019 11:39:27 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1hdGCj-000724-6L; Tue, 18 Jun 2019 15:39:25 +0000 From: Colin King To: Benson Leung , Enric Balletbo i Serra , Nick Crews Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc Date: Tue, 18 Jun 2019 16:39:24 +0100 Message-Id: <20190618153924.19491-1-colin.king@canonical.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King If the kzalloc of the entries queue q fails a null pointer dereference occurs when accessing q->capacity and q->lock. Add a kzalloc failure check and handle the null return case in the calling function event_device_add. Addresses-Coverity: ("Dereference null return") Fixes: 75589e37d1dc ("platform/chrome: wilco_ec: Add circular buffer as event queue") Signed-off-by: Colin Ian King --- drivers/platform/chrome/wilco_ec/event.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/platform/chrome/wilco_ec/event.c b/drivers/platform/chrome/wilco_ec/event.c index c975b76e6255..e251a989b152 100644 --- a/drivers/platform/chrome/wilco_ec/event.c +++ b/drivers/platform/chrome/wilco_ec/event.c @@ -112,8 +112,11 @@ module_param(queue_size, int, 0644); static struct ec_event_queue *event_queue_new(int capacity) { size_t entries_size = sizeof(struct ec_event *) * capacity; - struct ec_event_queue *q = kzalloc(sizeof(*q) + entries_size, - GFP_KERNEL); + struct ec_event_queue *q; + + q = kzalloc(sizeof(*q) + entries_size, GFP_KERNEL); + if (!q) + return NULL; q->capacity = capacity; spin_lock_init(&q->lock); @@ -474,6 +477,11 @@ static int event_device_add(struct acpi_device *adev) /* Initialize the device data. */ adev->driver_data = dev_data; dev_data->events = event_queue_new(queue_size); + if (!dev_data->events) { + kfree(dev_data); + error = -ENOMEM; + goto free_minor; + } init_waitqueue_head(&dev_data->wq); dev_data->exist = true; atomic_set(&dev_data->available, 1); -- 2.20.1