From patchwork Thu Mar 22 15:52:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 10301823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B1AAC60385 for ; Thu, 22 Mar 2018 15:54:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4AAB2872D for ; Thu, 22 Mar 2018 15:54:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9991228733; Thu, 22 Mar 2018 15:54:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.4 required=2.0 tests=BAYES_00,FROM_WORDY, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CFDB2872D for ; Thu, 22 Mar 2018 15:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751668AbeCVPxX (ORCPT ); Thu, 22 Mar 2018 11:53:23 -0400 Received: from mail1.bemta5.messagelabs.com ([195.245.231.141]:29619 "EHLO mail1.bemta5.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751753AbeCVPwG (ORCPT ); Thu, 22 Mar 2018 11:52:06 -0400 Received: from [85.158.139.19] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-5.bemta-5.messagelabs.com id 61/49-29733-521D3BA5; Thu, 22 Mar 2018 15:52:05 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkleJIrShJLcpLzFFi42KJ27nUWFf14uY ogwsdnBbNi9ezWbw5Pp3Jomv1ThaLa8d6mSwu75rDZvG59wijxaJlrcwWTxaeYbI4vbvEgdNj 06pONo95JwM99s9dw+6x8d0OJo/3+66yeez83sDu8XmTXAB7FGtmXlJ+RQJrRueG6IK/HBWtT xYzNTA+ZO9i5OIQEljPKDHp2h/WLkZOIKdCYtHhw+wgNq9ApsTMed1gcU4Bd4n5v74wQ9S4Sc zZ95INxGYTsJCYfOIBmM0ioCqxu+cnUA0Hh7BAlMSSFzIg80UE3jNKfHr8gQWkhlmgTqL391s WiPmCEidnPoGKS0gcfPECar6BxOkFjWBxCQF7ienvr4LNlBDQl2g8FgsRNpT4PusbVIm5xM1F e9gmMArOQjJ1FpKpCxiZVjFqFKcWlaUW6RpZ6CUVZaZnlOQmZuboGhqY6uWmFhcnpqfmJCYV6 yXn525iBEZIPQMD4w7GvlV+hxglOZiURHk/vdgUJcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCl+ HC5ighwaLU9NSKtMwcYKzCpCU4eJREeDVB0rzFBYm5xZnpEKlTjMYcz/Y+aGPmuPHidRuzEEt efl6qlDhvCEipAEhpRmke3CBYCrnEKCslzMvIwMAgxFOQWpSbWYIq/4pRnINRSZhXHmQKT2Ze Cdy+V0CnMAGdkj1zA8gpJYkIKakGxtSLd8u5ijMqzgif+7xYIqhmLovUftcHxi7R79sN57XrK iu5/td8c9rqy9u2x2GCTf+2zikUYXdVjvnScnjBgxma0XzGmbrxk7yvSqjkHpFfkyb6w9H8ce qJ4GLed5P56hp2Pcnec+i3ULSVK+u3GMZtqqsSZzqz+v19JHripknfNsa/2pWcSizFGYmGWsx FxYkAptHw1xwDAAA= X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-11.tower-178.messagelabs.com!1521733924!100425480!1 X-Originating-IP: [94.185.165.51] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.9.15; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26005 invoked from network); 22 Mar 2018 15:52:05 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-11.tower-178.messagelabs.com with AES128-SHA encrypted SMTP; 22 Mar 2018 15:52:05 -0000 Received: from swsrvapps-01.diasemi.com (10.20.28.141) by SW-EX-CASHUB01.diasemi.com (10.20.16.140) with Microsoft SMTP Server id 14.3.382.0; Thu, 22 Mar 2018 15:52:04 +0000 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id 5471B3FADB; Thu, 22 Mar 2018 15:52:04 +0000 (GMT) Message-ID: In-Reply-To: References: From: Adam Thomson Date: Thu, 22 Mar 2018 15:52:04 +0000 Subject: [PATCH v6 3/6] power: supply: Add error checking of psy desc during registration To: Heikki Krogerus , Guenter Roeck , Greg Kroah-Hartman , Sebastian Reichel , Hans de Goede , Jun Li CC: , , , MIME-Version: 1.0 X-KSE-AttachmentFiltering-Interceptor-Info: protection disabled X-KSE-ServerInfo: sw-ex-cashub01.diasemi.com, 9 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 22/03/2018 12:24:00 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently there's no error checking of this parameter in the registration function and it's blindly added to psy class and subsequently used as is. For example if this is NULL the call to psy_register_thermal() will try to dereference the pointer thus causing a kernel dump. This commit updates the registration code to add some basic checks on the desc pointer validity, name, and presence of properties. Signed-off-by: Adam Thomson --- drivers/power/supply/power_supply_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 82f998a..64f6449 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -849,6 +849,9 @@ static void psy_unregister_cooler(struct power_supply *psy) pr_warn("%s: Expected proper parent device for '%s'\n", __func__, desc->name); + if (!desc || !desc->name || !desc->properties || !desc->num_properties) + return ERR_PTR(-EINVAL); + psy = kzalloc(sizeof(*psy), GFP_KERNEL); if (!psy) return ERR_PTR(-ENOMEM);