From patchwork Fri Mar 23 10:12:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 10303989 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 53C4A60386 for ; Fri, 23 Mar 2018 10:58:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 447B428D60 for ; Fri, 23 Mar 2018 10:58:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 393D828DAF; Fri, 23 Mar 2018 10:58:55 +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 C517428D60 for ; Fri, 23 Mar 2018 10:58:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933226AbeCWKMf (ORCPT ); Fri, 23 Mar 2018 06:12:35 -0400 Received: from mail1.bemta26.messagelabs.com ([85.158.142.112]:19977 "EHLO mail1.bemta26.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933179AbeCWKM1 (ORCPT ); Fri, 23 Mar 2018 06:12:27 -0400 Received: from [85.158.142.194] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-b.eu-central-1.aws.symcld.net id DF/8B-19688-803D4BA5; Fri, 23 Mar 2018 10:12:24 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFKsWRWlGSWpSXmKPExsUSt3OpsS7H5S1 RBlM6RCyaF69ns3hzfDqTRdfqnSwW1471Mllc3jWHzeJz7xFGi0XLWpktniw8w2RxeneJA6fH plWdbB7zTgZ67J+7ht1j47sdTB7v911l89j5vYHd4/MmuQD2KNbMvKT8igTWjM4N0QV/OSpan yxmamB8yN7FyMUhJLCeUeL9zzlsXYycQE6FxKOb7awgNq9ApsT6gy/B4pwC7hL3XnYydTFyAN W4Sez5xAwSZhOwkJh84gFYCYuAqkTvpA9MILawQJTE8Qt3wOaLCLxnlPj0+AMLSIJZoE6i9/d bFoj5ghInZz6BiktIHHzxghniBgOJ0wsaweISAvYS099fZQbZKyGgL9F4LBYibCjxfdY3qBJz iVlnd7BNYBSchWTqLCRTFzAyrWK0TCrKTM8oyU3MzNE1NDDQNTQ01jXXNTKy0Eus0k3SSy3VT U7NKylKBMrqJZYX6xVX5ibnpOjlpZZsYgTGEAMQ7GB8fCz5EKMkB5OSKG/m8S1RQnxJ+SmVGY nFGfFFpTmpxYcYZTg4lCR4r10EygkWpaanVqRl5gCjGSYtwcGjJML7HiTNW1yQmFucmQ6ROsV ozPFs74M2Zo4bL163MQux5OXnpUqJ864AKRUAKc0ozYMbBEsylxhlpYR5GYFOE+IpSC3KzSxB lX/FKM7BqCTM+w1kCk9mXgncvldApzABneIzBeyUkkSElFQDo5TK0gffJ4dtNtt1Ko3RP1qZu 33eDa/eJyoRu1s4nPNOzz7Tt0TxuHmBipPe0Y72++Y73fkv77Cyv7iYKej1rwsqWfZ6ykpRnN der2qwFLb1Tf7z76lN0g71lWFxHOkpCb/Ln6f4b9cyYd50c8Y9gQnhD+6VGiwTOtbTuHCuxQ2 N5ZbXKzM/K7EUZyQaajEXFScCAG5ZfqQtAwAA X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-11.tower-239.messagelabs.com!1521799943!579713!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 7608 invoked from network); 23 Mar 2018 10:12:24 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-11.tower-239.messagelabs.com with AES128-SHA encrypted SMTP; 23 Mar 2018 10:12:24 -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; Fri, 23 Mar 2018 10:12:23 +0000 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id 26CEE3FB7B; Fri, 23 Mar 2018 10:12:23 +0000 (GMT) Message-ID: <84159a4df772e123d850561eff38ece7577e816f.1521799705.git.Adam.Thomson.Opensource@diasemi.com> In-Reply-To: References: From: Adam Thomson Date: Fri, 23 Mar 2018 10:12:23 +0000 Subject: [PATCH v7 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/03/2018 08:40: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);