Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1027213iob; Fri, 13 May 2022 20:10:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjZzrtGLzmES8G1gKdJNv7PJYF4X2vpGgvQZXs+ZkNI395GerR25KI6NlZtXEnlHuiryZW X-Received: by 2002:a5d:598f:0:b0:20c:83c9:b05b with SMTP id n15-20020a5d598f000000b0020c83c9b05bmr6114097wri.343.1652497826462; Fri, 13 May 2022 20:10:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652497826; cv=none; d=google.com; s=arc-20160816; b=JedN2JakwnBYoy8WP0ZhpHUewzuTZIPrfP+F0A/UhQjkVtP/dF7S3vU/Dmc/RI3MaL fgC3LsDz0Ni+AAlzBTuo2dC72LJbRiD10Gu6lJ2nNRsWN54seBISw39vWsZRvAHpgX9b SSadl/pTtLqgivcKolrmTyt0cj6LC5cLg/458tJXteYDkEsV70VhyBPPcW0pMaGMDj4M d1SEQ65xL/18BdrzffzjGEXPcNA9jExW8/zCMgbDJ+kGhcAs9ShQU8wb84VvBF95rdwv SH/uk8wCZisB/xtxDKFUfl3J3JsdG8t1THQUwhs/RivSqjm6YbVYZyPLeB3PisMhdPMe KPjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=MD83ziJ2Qho4XkX8bpjsM8c+Xp4pjhuVQvUvmAtS3rE=; b=HkSTWfTw15bClpt7EvnIZL1Uprv+yJsovTq69qB8uTXvmM+KhWSAlPCuPOFnXbPwiK A7VlP/Lh3u2AWDpUlo2aSlSpg5/IywutAlcFnQ/iMOkpNEOIjiAikszY0B1zmDDusn5F HUiuxd3BcY65CfeJ7ot1Ky7KxCslH1gMxnvP2o3KU5urHEr/Jk37wfYQYiNOmPdGi5mL PV0whDEe2Nrj71aR3eDSTdbGbwHgFVmZePfR6VyzAt00l4V9fO0Zk5Hj/sFcSPqag0Ny K3USJw1AEpXW/zt0UKjTHffaQBEqbLZfNZc4lYDZXk00u+YDLbjAK6WK4moBISsEXkd3 EQFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TUxDegrL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bd14-20020a05600c1f0e00b0038c86bbaad6si6994063wmb.38.2022.05.13.20.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:10:26 -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=@google.com header.s=20210112 header.b=TUxDegrL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F3C783C85DD; Fri, 13 May 2022 16:50:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357030AbiEMNVK (ORCPT + 99 others); Fri, 13 May 2022 09:21:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346448AbiEMNUu (ORCPT ); Fri, 13 May 2022 09:20:50 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8209D3915A for ; Fri, 13 May 2022 06:20:49 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id z2so16261514ejj.3 for ; Fri, 13 May 2022 06:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MD83ziJ2Qho4XkX8bpjsM8c+Xp4pjhuVQvUvmAtS3rE=; b=TUxDegrLBh1U0MnPtFzTADDsXSPEGhcUswvbfcvpQuBefZd31V7+cHEyDPsnW3OZ0f 0xdwW8VJYLh1lAHGUVtCZbqKE3H17sxyE8Jej3wrPitNnrv8cKzUf2Do318YNFvMndhn H8HbOgmsH5zA37wRuaZVlGWWTreTM6159bmhDo+zx81D4CWs036ujwfg5IJyWt5IWtLB FDpmj4f6QPts3veFDiEqL0GisQF1dI0ITml4FEAD/dTfGyw5czclB+19WIs8wPTT3wrO DAfLJ0pbzKTBcQ9OMmsNPuFuQhW8ZVMte89ztEky/fSog+/evVqYW+816VRggyGXa2yK Tg2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MD83ziJ2Qho4XkX8bpjsM8c+Xp4pjhuVQvUvmAtS3rE=; b=5P68FvXVnQ4fKscPtHeYOwhxoimRKTKJUDGqhln2hLGPd1ZQLBx7KGpmcFgw+BN4dB e3HeW3YyfYTwV6jf+Cj5ffY4Nu+5yR8M6WqXsc1rzxsjHynQ4UZtHoBDGqVC68TfDLQx rS9GecZEF/EMhyTAp5C0w0Whh8o7PjUFJIlYF5Uim+fTDmOiSBwrOjhcpTa0aOrq/91b xNKvMM7mfhk1Di0egObgpPnIoDS627Xsrgdimm7fU8fitU2lvHlP/BC5w1Jx/ud6lRb7 ct2e/RPjVKCtTsmOLlPYamfvZNEfOt2tQclk/KyUvrA5nIUPM0oo5ZzaF5gjsWHgxorT Vn0w== X-Gm-Message-State: AOAM5306Q9+Hb5pLvKXG+uOHY2JYiL/WBNSfxfe5XtIkfQDFpN9AlEOp TIdfuEdYK7FEG6oSjdqWYV9yI7ZpdraphsKBTpCbHYHW1MHSOw== X-Received: by 2002:a17:906:58d4:b0:6f4:cebd:c4b with SMTP id e20-20020a17090658d400b006f4cebd0c4bmr4222200ejs.492.1652448047829; Fri, 13 May 2022 06:20:47 -0700 (PDT) MIME-Version: 1.0 References: <20220513044143.1045728-1-tzungbi@kernel.org> <20220513044143.1045728-8-tzungbi@kernel.org> In-Reply-To: <20220513044143.1045728-8-tzungbi@kernel.org> From: Guenter Roeck Date: Fri, 13 May 2022 06:20:36 -0700 Message-ID: Subject: Re: [PATCH v2 7/7] platform/chrome: cros_ec_spi: drop BUG_ON() if `din` isn't large enough To: Tzung-Bi Shih Cc: Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 On Thu, May 12, 2022 at 9:42 PM Tzung-Bi Shih wrote: > > 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 Reviewed-by: Guenter Roeck > --- > 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 >