Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp370563pxb; Thu, 20 Jan 2022 15:23:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8h9qqW9BIKBgLzkEyH0rsKPpW8+LYJRD6HE6udhfrvjqBadNhKcUdAtS17Jz2fmE8/eh8 X-Received: by 2002:a17:902:d2c6:b0:14a:6e28:591c with SMTP id n6-20020a170902d2c600b0014a6e28591cmr1035855plc.85.1642720993857; Thu, 20 Jan 2022 15:23:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642720993; cv=none; d=google.com; s=arc-20160816; b=xj4VayKHmQaVp0UvYNI2mOAn//D7TruEKBKEeRkCKQxriAzfEbX2G8uE2B8A+ZTMbY 8WM4CuAAlHn3xosOGg0H3mo7tCEgMbkyUfs3MCLGOgEDcCxA3LUXAlQsXtXbWTbhnugY moHdRTmOu0pCpRiIDuvanN6CXS6z/a37OpnqnhMEAo8z1gFJvDy6GgygDOy3NX6O65xL 0VTuyfLdN8tjYro2apnIWEjw0+Ylcqa8ReMtN/TUvd9slfGQWs0+16+MbTnMqcLvwiVM 3aPCPwLMFMM6sfJLlSMpn6C+4coTM9UoNDFeutpUbhriLj8VsSu1WNTprJnfYZE+a1a7 zv0w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=iW16hd+cXQQsHyRP7rt+lJ5AICZ50nA5CTVDepKk1SY=; b=H3jAwHoynS2h0CfqE2UakptQzI4JZkJ6uGHhYDoBaxmeLKMdoT3XNAb9EoaDvUDx4R 2Ac2tzJXmuvLmOpJuBFrrot8gBYmZHnCIHZdtS8k3yE2oLpnmmeIHClHSJ2V9AkmQIQb 2G3YA1pkMNVfn9yLDpfM+ToIX3A2S7x82UurlBN9TfaWPyJzd4NTt++qsBXCvRyBr+9J 4hLUzHQFxUqNiOZO3qWCJ5HWoQ07hiFARc675gL4E46qITYVoo0Nk9oVpKtBzR2hrxVp YfSuRp438QRULZdCp1hp2+qWPKFHDi6hPdKgRAIHC1vNxaVeoQn9xoN5oAgBfxae0P9R sO8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hkjqRWJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s193si4804034pgs.318.2022.01.20.15.22.13; Thu, 20 Jan 2022 15:23:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hkjqRWJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348152AbiARSgy (ORCPT + 99 others); Tue, 18 Jan 2022 13:36:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348136AbiARSgx (ORCPT ); Tue, 18 Jan 2022 13:36:53 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3CFCC061401 for ; Tue, 18 Jan 2022 10:36:52 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id i8so14877537pgt.13 for ; Tue, 18 Jan 2022 10:36:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iW16hd+cXQQsHyRP7rt+lJ5AICZ50nA5CTVDepKk1SY=; b=hkjqRWJ4GTUWf/fA1HqqRNXjXZBRWN0KbJB3mPlHa5YoKLe77jPKhe+wjGQu0WRXnp OKWGhgSC2QBrVgvIzuYh8G5csrAG3/M6LoMiY9y0yb9p4hkFmfAoDJFErBjEiWG1Qta5 9IqRb58Pch9kVolf/Or7Uy7XlFzTIVmZXG018= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iW16hd+cXQQsHyRP7rt+lJ5AICZ50nA5CTVDepKk1SY=; b=H9OuAT00VNPT84cP30i5leOGpZJkPtl/Vm1wmkTq8qRSgkL/UeVimMoL74XsV99xcw 3XKO1XLbZKZX0et1ffhSD3/pOMFq/Yf3X/eQs75q4VihTlpl8d1+D1qNLWa3QXKuHNl6 RninIk5+PYFQbwiui/lStcJkLESld8eRaWkow57eJDRqzmso+PMIaJto8G2HFUz8qnHE zBkyim1BmfwgMhJSjJidna/FquOoj0avYurA/ROaoaWtWFosx1HQBz0eOjS6WaS4f9LJ CGnncZfgd4psr8s+tfaXzp1qrUs2HccN01oblk0glSSLESpEUMNGqky1KCelWFpqTpuO n+kw== X-Gm-Message-State: AOAM532wscELfMommNbvBu6Q+1iFdb+BCiQdw1hdPD4bYVszb7o+AlNI gbsvLx8ns4Q/gkRiwNodgsJUjg== X-Received: by 2002:a63:7544:: with SMTP id f4mr24302719pgn.556.1642531012435; Tue, 18 Jan 2022 10:36:52 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w18sm5509171pga.18.2022.01.18.10.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 10:36:52 -0800 (PST) From: Kees Cook To: Peter Huewe Cc: Kees Cook , Jarkko Sakkinen , Jason Gunthorpe , linux-integrity@vger.kernel.org, Stefan Berger , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2] tpm: vtpm_proxy: Double-check to avoid buffer overflow Date: Tue, 18 Jan 2022 10:36:50 -0800 Message-Id: <20220118183650.3386989-1-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1713; h=from:subject; bh=aQ56F/K9EivD7wwGaVgmtBlfGCGvsRBhNwMsTf+3QQw=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBh5wjCHVDaUYrsL2fGabA2P1j4qpg2fjljD/IAr3nW n6XxQjuJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYecIwgAKCRCJcvTf3G3AJrcHEA CE9wB7dgJGERHXIitTtvTPL1be+tJVDIAl87bB3MwfS4vzZgOWJqNTJ/gt3zjvNgavNIcMn3EOd+ZS y9iiiTsLfmIAb0Yl7TQJgeqRMpKVf8OMPrw12CDawZ0/Ed/fWaFwfXxX8FSxDT5xOV3SsmQpZwRMUg S4JealaQ3hCb053471GPtUlthOGmjB+RKIDV++2l6mLXj0pPMQ31OaXlCuqQ27pUiOWibuVos5awWA ulS24UU3Y7cfuGXOwsOxk1Zwz9JF7Sll/40RKpQPhezoNSa7kDdIiUOwJGBWtvcCXBY09+CkU1AykC PuyAlIwJVkP7xm2to/ky6AuSHnu0a4yK6y1z0I72G3VDWmSWo2O2ocs5nfGkDWGGwSmU6SChFcGOC5 pTb3qlaHupazqOOyJSV0hBBMby4GXrSQbXA+giMXA4LfDQF2TwRo5Se5+X5FOk0mgMMPshtQ5chJnZ 6ORLeitCZgEP7QMFLJzVl675Htd6W7dOkSsyhlS0xZ/cGLnafcF2vtyXqgYtDfvnRYgbQDvyj93rb4 LulMmcwhdjpBt+w4rxDmrn321EciKzWZPJSdQrMWapDhDO7D+Xah5e87OvA93AdO1uXziDO8l9edfv HtrRkEQAIgGP/gYGiDdrF8oIGSACvoLIsNcLL7s+T0dsj/jzdeTZCYq2cFSw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When building with -Warray-bounds, this warning was emitted: In function 'memset', inlined from 'vtpm_proxy_fops_read' at drivers/char/tpm/tpm_vtpm_proxy.c:102:2: ./include/linux/fortify-string.h:43:33: warning: '__builtin_memset' pointer overflow between offset 164 and size [2147483648, 4294967295] [-Warray-bounds] 43 | #define __underlying_memset __builtin_memset | ^ There was no checking of the req_len value. To keep this code robust, and to silence the compiler warning, check the size before attempting a memset(). Cc: Peter Huewe Cc: Jarkko Sakkinen Cc: Jason Gunthorpe Cc: linux-integrity@vger.kernel.org Reviewed-by: Stefan Berger Link: https://lore.kernel.org/lkml/4b59d305-6858-1514-751a-37853ad777be@linux.ibm.com Signed-off-by: Kees Cook --- v1: https://lore.kernel.org/lkml/20220113002727.3709495-1-keescook@chromium.org v2: make commit log more accurate, add Reviewed-by --- drivers/char/tpm/tpm_vtpm_proxy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c index 91c772e38bb5..5c865987ba5c 100644 --- a/drivers/char/tpm/tpm_vtpm_proxy.c +++ b/drivers/char/tpm/tpm_vtpm_proxy.c @@ -91,7 +91,7 @@ static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf, len = proxy_dev->req_len; - if (count < len) { + if (count < len || len > sizeof(proxy_dev->buffer)) { mutex_unlock(&proxy_dev->buf_lock); pr_debug("Invalid size in recv: count=%zd, req_len=%zd\n", count, len); -- 2.30.2