From patchwork Wed Jun 20 18:28:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10478485 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 4479860210 for ; Wed, 20 Jun 2018 18:28:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3645828471 for ; Wed, 20 Jun 2018 18:28:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AB23284BD; Wed, 20 Jun 2018 18:28:45 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 C29C328471 for ; Wed, 20 Jun 2018 18:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754226AbeFTS2n (ORCPT ); Wed, 20 Jun 2018 14:28:43 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:43447 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752133AbeFTS2m (ORCPT ); Wed, 20 Jun 2018 14:28:42 -0400 Received: by mail-pl0-f67.google.com with SMTP id c41-v6so224250plj.10 for ; Wed, 20 Jun 2018 11:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=/t4s4wlDSwOT83qnURylb60VdFe1H4dhzJXobLFZd64=; b=AogPeAx83WYAiLWKW2Vn4r6vzJTda/YDZinWOvH76PM0daovoO66CTVAupqe6GjR05 pmLtP6iAPDE2cYZbe7rx/eMloPUSBi1Jv5uE1aHQmc5yC2wTS90gmisG2J5yRZiWlK5H ghT8F16JACa3VsF28JzhG8+652g7bs9R73EMg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=/t4s4wlDSwOT83qnURylb60VdFe1H4dhzJXobLFZd64=; b=pWyvPc4M3VgPb6U9V2mmin7m4LlM8o4Yhtfl/RJIPh65dtsZyAwKXiDHOWeN4jvxxX 6lVsUZcI/CMu1lunPqEhQkKZSUUNQGmyyuSXPkhke76WYlJAKGSIYObOELpxpyhXQDwI WhldPyhOZTn5PJgTdtXXdcV0NsRgLwDYXZj68lINsmUzEzTu8KdLriHdi6n/ult0r0Ku 6InMb6ZRpW8dRyAl2aDxEAj2n+sXmQgBQLlJ0nc17Eh1UUWPMpz03f3v3sgUmfmbNgz3 As/Ah3lJFwRosD/313F0zj5EPbHqR2DscBuvlEHFLSM6QMJNegzeiwbRYYmz9WNybsuo 5eBg== X-Gm-Message-State: APt69E1F6q4k6xm3e7jOptR0rqihMEQ+aJCZYbyzt19ZiyNci0WDXrhR mlO7DrWRqOZ+X6FRe1JkPKxSTnsIxD8= X-Google-Smtp-Source: ADUXVKL5SHNFucGSNk6eC+My/o6a6d7gSOG+rKy3ps+QheEzkprJAkdETjp8HVtTdLtf4e07R+NYTA== X-Received: by 2002:a17:902:8348:: with SMTP id z8-v6mr24803161pln.239.1529519322476; Wed, 20 Jun 2018 11:28:42 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id p12-v6sm5772661pfi.175.2018.06.20.11.28.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 11:28:41 -0700 (PDT) Date: Wed, 20 Jun 2018 11:28:40 -0700 From: Kees Cook To: Greg Kroah-Hartman Cc: Heikki Krogerus , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH] usb: typec: tps6598x: Remove VLA usage Message-ID: <20180620182840.GA24775@beast> MIME-Version: 1.0 Content-Disposition: inline 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 In the quest to remove all stack VLA usage from the kernel[1], this uses the maximum buffer size and adds a sanity check. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- drivers/usb/typec/tps6598x.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c index 4b4c8d271b27..396193f85e6d 100644 --- a/drivers/usb/typec/tps6598x.c +++ b/drivers/usb/typec/tps6598x.c @@ -81,12 +81,17 @@ struct tps6598x { struct typec_capability typec_cap; }; +#define TPS_MAX_LEN sizeof(u64) + static int tps6598x_block_read(struct tps6598x *tps, u8 reg, void *val, size_t len) { - u8 data[len + 1]; + u8 data[TPS_MAX_LEN + 1]; int ret; + if (WARN_ON(len + 1 > sizeof(data))) + return -EINVAL; + if (!tps->i2c_protocol) return regmap_raw_read(tps->regmap, reg, val, len);