Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp466968ybl; Tue, 28 Jan 2020 06:25:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxi21fawnVJwDjmqVRO27DuvJ64NGIE7VxjRgjSr6OWA8zpkupLgTbEsl0t1pTwHoY5b79V X-Received: by 2002:aca:1c1a:: with SMTP id c26mr3019580oic.75.1580221519291; Tue, 28 Jan 2020 06:25:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580221519; cv=none; d=google.com; s=arc-20160816; b=kvTBsGIeZndffae9Ddil4hkuHc88XIqBg6lCRSk6106gK44T7EDVsGFmjZxschHp+H lRZHsbbB5r7tVapL6MFS0/lNvuZTpJet/F2J5JE9xSfVb0e6F+ty81yYMN7K8V30DtKB nj/7lG7dMxdeNxxoPt5m+c0+Smn/1EHFyRqnTAGZeQmlm6nSxxsye1l2ar0lbRXiCMU2 hbUq1tIgLSO6h8RZmLk9pcgOaheNv65gKFTk9yGsOt56wRkJi6sjqOlNbfbFmoIFeLuN MoSF0qHLI9hqPsDSZilHLV2L9dMZ9kVPyf9X8WJKefkVHoPQyaCWEeQ3F0zwnMghBeMJ nngw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pGWw8VjqF5bIQ7zGnWg7BR3Ql6pOkBaaEONIOY41yB0=; b=fi+GvZCS2/LJHYmppHZxwUdPnkv+yn+r16dAjw+zIUNJeRGPyPOf6bny/TUU1/viIt o0rebn3palbMNk3/mmHcg8Lw+pKQWtzp6PL0riv9dG+MVbrnRgDprhZh8t/d2Pknn8Or cXD4u65z0y64ORdS4wMfcLWmnTih0Bvj5nXWWO0tHB5SROBZXvCwbaT0Jak1lxt6iKwR FpbKv01ngu+/SaF4dsr47jhyxxItIcp5boGE53c1FOymyG414FyhlDBDwlFzc6NWZDls l2oQtQHNS9UyE3QfvcSpKE1kRUmy3JIWD2WP3wR74J7wjm6M57MkMd9QCuBa0cRmJjQo tsmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ov0VIQwn; 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 z14si8515125oth.15.2020.01.28.06.25.07; Tue, 28 Jan 2020 06:25:19 -0800 (PST) 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=@kernel.org header.s=default header.b=Ov0VIQwn; 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 S1728313AbgA1OYP (ORCPT + 99 others); Tue, 28 Jan 2020 09:24:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:50816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731405AbgA1OYN (ORCPT ); Tue, 28 Jan 2020 09:24:13 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4860621739; Tue, 28 Jan 2020 14:24:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221452; bh=5YYtm9ma19c214WP3Vz1E0GoAaNZU29FxW2eDLaO3UI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ov0VIQwndMtRm4q57rK1Yu386ySAeoukLXNPavYY4HAaCcXaP/8tDYZUlel+Dh2DW b1JDUi0Yl+hVgJi7Yzi11bqVy5Om79P5hRPU1IOiCm/h6JKHdr245KlCzMVL95mnUw YfD3Ec9SSQX6lTRMS7idC7ZzTEJ7qOFv3D6zIQpc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Rui Miguel Silva , Sasha Levin Subject: [PATCH 4.9 193/271] staging: greybus: light: fix a couple double frees Date: Tue, 28 Jan 2020 15:05:42 +0100 Message-Id: <20200128135906.949065403@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@linuxfoundation.org> User-Agent: quilt/0.66 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: Dan Carpenter [ Upstream commit 329101244f214952606359d254ae883b7109e1a5 ] The problem is in gb_lights_request_handler(). If we get a request to change the config then we release the light with gb_lights_light_release() and re-allocated it. However, if the allocation fails part way through then we call gb_lights_light_release() again. This can lead to a couple different double frees where we haven't cleared out the original values: gb_lights_light_v4l2_unregister(light); ... kfree(light->channels); kfree(light->name); I also made a small change to how we set "light->channels_count = 0;". The original code handled this part fine and did not cause a use after free but it was sort of complicated to read. Fixes: 2870b52bae4c ("greybus: lights: add lights implementation") Signed-off-by: Dan Carpenter Acked-by: Rui Miguel Silva Link: https://lore.kernel.org/r/20190829122839.GA20116@mwanda Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/greybus/light.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c index 9f01427f35f91..1cb82cc28aa76 100644 --- a/drivers/staging/greybus/light.c +++ b/drivers/staging/greybus/light.c @@ -1102,21 +1102,21 @@ static void gb_lights_channel_release(struct gb_channel *channel) static void gb_lights_light_release(struct gb_light *light) { int i; - int count; light->ready = false; - count = light->channels_count; - if (light->has_flash) gb_lights_light_v4l2_unregister(light); + light->has_flash = false; - for (i = 0; i < count; i++) { + for (i = 0; i < light->channels_count; i++) gb_lights_channel_release(&light->channels[i]); - light->channels_count--; - } + light->channels_count = 0; + kfree(light->channels); + light->channels = NULL; kfree(light->name); + light->name = NULL; } static void gb_lights_release(struct gb_lights *glights) -- 2.20.1