From patchwork Fri May 8 12:33:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 226132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3744C47254 for ; Fri, 8 May 2020 13:14:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D113F218AC for ; Fri, 8 May 2020 13:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588943697; bh=V0RjYQzndmgrEhZdr+EFbf5EKNuTl5UrmHdYyB6ZKv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=RKtZJPHGVc9uxnx8I8kAlLYh7Z8GMx3EtRB2851L17AqyG7XAUnnjfNsBPwybkZzP XGmt1yeTFHxGpjg4h+OeCj5bQLqsiyELLdqpE2JshsFC+IvLgy6N8LVIWIlsXXhDmY nZA8ss6RvO8HqavRvzPis+SUnIvbaiTzhFthRjQQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729420AbgEHMqT (ORCPT ); Fri, 8 May 2020 08:46:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:47276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729415AbgEHMqQ (ORCPT ); Fri, 8 May 2020 08:46:16 -0400 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 D34DA208D6; Fri, 8 May 2020 12:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588941976; bh=V0RjYQzndmgrEhZdr+EFbf5EKNuTl5UrmHdYyB6ZKv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BwYI20wzM2Ktnx4/A1kTarfU4uFCsr6TXhHvlHUrE5sYMzceZo3AX7YPSlL6ituFz LHltVnvrp1k/CkdJns3ZPLPwiWLWrf4/tq/dKzsKxGMdh5xrkQYE0snYUf9y0I0Agj rTG3ushkjWmZD5SG+HhO4qQYVTYx6hU/xx0uKYVQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sasha Levin , Sebastian Reichel Subject: [PATCH 4.4 230/312] power: test_power: correctly handle empty writes Date: Fri, 8 May 2020 14:33:41 +0200 Message-Id: <20200508123140.616507722@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508123124.574959822@linuxfoundation.org> References: <20200508123124.574959822@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Sasha Levin commit 6b9140f39c2aaf76791197fbab0839c0e4af56e8 upstream. Writing 0 length data into test_power makes it access an invalid array location and kill the system. Fixes: f17ef9b2d ("power: Make test_power driver more dynamic.") Signed-off-by: Sasha Levin Signed-off-by: Sebastian Reichel Signed-off-by: Greg Kroah-Hartman --- drivers/power/test_power.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/power/test_power.c +++ b/drivers/power/test_power.c @@ -301,6 +301,8 @@ static int map_get_value(struct battery_ buf[MAX_KEYLENGTH-1] = '\0'; cr = strnlen(buf, MAX_KEYLENGTH) - 1; + if (cr < 0) + return def_val; if (buf[cr] == '\n') buf[cr] = '\0';