Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp941463iob; Fri, 13 May 2022 17:12:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbFFRoh0zhzjQKILyDT3gGsLvo0Ldkc8DqPO/HinUNcMFuEyj4MXDetKHqiZCgi86LB3L3 X-Received: by 2002:adf:f6c4:0:b0:20a:cd34:9f68 with SMTP id y4-20020adff6c4000000b0020acd349f68mr5683402wrp.122.1652487157903; Fri, 13 May 2022 17:12:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652487157; cv=none; d=google.com; s=arc-20160816; b=oY9sVw1dOjK1Qhqz8mv9Fceuw1wSMKGr1lmiLNvvpWfC0dUSJYI++hDictV5bYfBx4 UkOTjP0ERA4OSLCafVwom4+wTPHK8r96h7PLhEoKHFr3IAvN/aR4hE5i9FG+2C2Sgr/6 g8Sb66UaFKEFmC4y7TX6wk5IOUYESdiv47m7SmA3qWXg1OrPPoMvevFbRVQ35/oXP3Zy sy4URGUzOP90iyC+0XaFQX0Qvelg3RI6t/rlyaaxEe962pyh6SjB08Qz2Z9IkXk7QXwK cywWq366pko4oKIo/c2XXzPOVLIRwcACr8l6ahh2P7+wbIow5WQ98a1n9HL1lW6gDZYY kNKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Qr8Jz4eySvOXBnW4PcPPk5PSK39i7K5ptuTlBYxqtF8=; b=jE1GGF4usMqO210e96QmcRWrvJtMVppWRWrOTqcMBa6ZR/0mOQMKDrS8hBsOsO+F+3 h6VEQDX27/1F+o5LEFONOfwn7hibseKBmKo9CaCPbo6OHJEKx58mYLQwyBLv2KLqe6V8 NKQjGQSXwH/+G+4bEDFfqf9QkbkKS0Xt3IFGdknvNKu+qItGunVKeJbUirFQn+pN3kSH ZENU5mXCxBZ+9POVOAM8fkMPiWky92ttqgPsH6Xe3J9kr+Glm7mf4Z7RDUFdgEMrl4s5 AR4loqY1IUdzYFVMsmqvzFt6e1/tvcXdp+dqtatQWSyyXlub3AJAbzIhYoiNn+dMw3av osdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="E2g/x+oV"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l15-20020a5d6d8f000000b0020ccc2dc48esi3613811wrs.575.2022.05.13.17.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 17:12:37 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="E2g/x+oV"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BF5E531AFB2; Fri, 13 May 2022 16:13:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377036AbiEMEmY (ORCPT + 99 others); Fri, 13 May 2022 00:42:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377012AbiEMEmF (ORCPT ); Fri, 13 May 2022 00:42:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDC9CBCE87 for ; Thu, 12 May 2022 21:42:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8D770B82B5C for ; Fri, 13 May 2022 04:42:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 487D2C34100; Fri, 13 May 2022 04:42:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652416922; bh=Pm5xt1pWIVuJwfVzV4nlj6lC7Q/VLMkt5So5beSne8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E2g/x+oVgM+TCsbGPt9EbAG9Ib1RHIMhd/fBeFWggR/qTlSH3vGhnos5vAmyCEG6q nr854v6lA3G+oOEkJyxzjYyD/PXc2BtfdBBxJHhSWacWelVsazmB4zyCowqTCn5Ph9 EwhGNszHoXiG1Gsf5NXWfGT+ubGEECx5YY82epBuWF+0rRqKix0h17nwguMBQkhP55 QpeDdccGz1J05Nt339D8d11PsFjaaGo9kGL9DCH6TsGuj5lsSAMFVYF1C1sGhBC/d9 wYO/vgVL7Y7XG066Y8uE2IFx81/8cVaPI1kgZdJgNPuvsfIIwYv0eeYh/s8hvSfU0e jAEN+9QQvXrAA== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] platform/chrome: cros_ec_spi: drop BUG_ON() if `din` isn't large enough Date: Fri, 13 May 2022 12:41:43 +0800 Message-Id: <20220513044143.1045728-8-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog In-Reply-To: <20220513044143.1045728-1-tzungbi@kernel.org> References: <20220513044143.1045728-1-tzungbi@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is overkill to crash the kernel if the `din` buffer is going to full or overflow. Drop the BUG_ON() and return -EINVAL instead. Signed-off-by: Tzung-Bi Shih --- Changes from v1: - Separate from the original 6th patch. drivers/platform/chrome/cros_ec_spi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_spi.c b/drivers/platform/chrome/cros_ec_spi.c index 5264615f46af..7360b3ff6e4f 100644 --- a/drivers/platform/chrome/cros_ec_spi.c +++ b/drivers/platform/chrome/cros_ec_spi.c @@ -160,7 +160,8 @@ static int receive_n_bytes(struct cros_ec_device *ec_dev, u8 *buf, int n) struct spi_message msg; int ret; - BUG_ON(buf - ec_dev->din + n > ec_dev->din_size); + if (buf - ec_dev->din + n > ec_dev->din_size) + return -EINVAL; memset(&trans, 0, sizeof(trans)); trans.cs_change = 1; @@ -197,7 +198,8 @@ static int cros_ec_spi_receive_packet(struct cros_ec_device *ec_dev, unsigned long deadline; int todo; - BUG_ON(ec_dev->din_size < EC_MSG_PREAMBLE_COUNT); + if (ec_dev->din_size < EC_MSG_PREAMBLE_COUNT) + return -EINVAL; /* Receive data until we see the header byte */ deadline = jiffies + msecs_to_jiffies(EC_MSG_DEADLINE_MS); @@ -304,7 +306,8 @@ static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, unsigned long deadline; int todo; - BUG_ON(ec_dev->din_size < EC_MSG_PREAMBLE_COUNT); + if (ec_dev->din_size < EC_MSG_PREAMBLE_COUNT) + return -EINVAL; /* Receive data until we see the header byte */ deadline = jiffies + msecs_to_jiffies(EC_MSG_DEADLINE_MS); -- 2.36.0.550.gb090851708-goog