From patchwork Mon Apr 23 14:10:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 10357139 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 375EC601BE for ; Mon, 23 Apr 2018 14:14:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2865C28AF5 for ; Mon, 23 Apr 2018 14:14:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D21228AFB; Mon, 23 Apr 2018 14:14:15 +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=-5.4 required=2.0 tests=BAYES_00,FROM_WORDY, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 919E928AF5 for ; Mon, 23 Apr 2018 14:14:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755578AbeDWOOM (ORCPT ); Mon, 23 Apr 2018 10:14:12 -0400 Received: from mail1.bemta5.messagelabs.com ([195.245.231.142]:46379 "EHLO mail1.bemta5.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755315AbeDWOLA (ORCPT ); Mon, 23 Apr 2018 10:11:00 -0400 Received: from [85.158.139.51] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-6.bemta-5.messagelabs.com id 46/9A-12610-379EDDA5; Mon, 23 Apr 2018 14:10:59 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphleJIrShJLcpLzFFi42KJ27nUWLf45d0 og30/eSyaF69ns3hzfDqTRdfqnSwW1471Mllc3jWHzeJz7xFGi0XLWpktniw8w2RxeneJA6fH plWdbB7zTgZ67J+7ht1j47sdTB7v911l89j5vYHd4/MmuQD2KNbMvKT8igTWjGl/t7EW/OWoO NC2n62B8SF7FyMXh5DAekaJXTvPMHcxcgA5FRLTZwd0MXJy8ApkSkyftZsFxOYUcJfonvSRDc QWEnCTuNz2hhHEZhOwkJh84gFYnEVAVeLb6clgcWGBKIm/JyYyg8wXEXjPKPHp8QewQcwCdRK 9v9+yQCwQlDg58wlUXELi4IsXzBALDCROL2gEi0sI2EtMf38V7DYJAX2JxmOxEGFDie+zvkGV mEvcP9zFNoFRcBaSqbOQTF3AyLSKUaM4tagstUjXyFIvqSgzPaMkNzEzR9fQwFQvN7W4ODE9N ScxqVgvOT93EyMwRuoZGBh3MF7e4neIUZKDSUmU1/L83SghvqT8lMqMxOKM+KLSnNTiQ4wyHB xKErybXgDlBItS01Mr0jJzgNEKk5bg4FES4X3yHCjNW1yQmFucmQ6ROsWoy3GnraeHWYglLz8 vVUqcdzPIDAGQoozSPLgRsMRxiVFWSpiXkYGBQYinILUoN7MEVf4VozgHo5IwrxXIFJ7MvBK4 Ta+AjmACOqJD8g7IESWJCCmpBsYVq0UWuMx9WZ891/oF2+S0MIH+i+dy9nwp+PGg8x6TXe2zX aJb916MLbyp/6nz36y7Au/Oh4oefLL7p+TDk84vt6tIi7CKnpG7UHhf9cSFGTuYDvBGHOL5kZ Z2jneHxXsTBcO/EWKSCpw8fb7mpkWf2L1M70WyPnuSseFlytqa8gjvlXF+JqVKLMUZiYZazEX FiQB8+mFGFwMAAA== X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-12.tower-180.messagelabs.com!1524492658!78920666!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 10537 invoked from network); 23 Apr 2018 14:10:59 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-12.tower-180.messagelabs.com with AES128-SHA encrypted SMTP; 23 Apr 2018 14:10:59 -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; Mon, 23 Apr 2018 15:10:58 +0100 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id 5F1A73FBDE; Mon, 23 Apr 2018 15:10:58 +0100 (BST) Message-ID: <627b8dcdee758c2598c6cf68b0ce536d3e557ca4.1524490253.git.Adam.Thomson.Opensource@diasemi.com> In-Reply-To: References: From: Adam Thomson Date: Mon, 23 Apr 2018 15:10:58 +0100 Subject: [PATCH v8 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: 23/04/2018 11:44:00 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@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 Reviewed-by: Heikki Krogerus --- 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 feac7b0..a7984af 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);