Received: by 10.223.185.116 with SMTP id b49csp822519wrg; Sat, 10 Feb 2018 21:12:35 -0800 (PST) X-Google-Smtp-Source: AH8x227m+S71c9nOHbVz1Y8ugSsRDN2DumkFZonKI+I8Yx99aN44MnHuOMgLzZh9yH8JCpbia5Xy X-Received: by 10.99.149.2 with SMTP id p2mr2665967pgd.122.1518325955521; Sat, 10 Feb 2018 21:12:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518325955; cv=none; d=google.com; s=arc-20160816; b=ywRxa5fpib4ow3lxqvwarUymTs6XmMUcmv6Vg7YtuZuzzioxrMfrlgXaZEkabBPO+/ 9IAhsU1V+vkQkM/TUhFFs/xnvQ2X14OFPCkl5WZDoDW99k/4LX4kh3ys48epXQsDH/IR wYKfrorohESsUlnm+kbWy/u76Chftx4en0k/NFu+/V167PdRuIwCydGMvhZibwUm3YJ/ FmpBNuEept3rebH0sDsA2RLHmxJI5398q0vhbvLqLnHHPYzoqmYFr63AZS+Ghsif5LVh nHzhKd8sNJUaEHcp9YEI/XBtM4E/wYYStL+9ME+AKR5XLDiCuTKIuTis3adTWZ6md2HM ovKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=RjuZ2v/1ESR1cHPUsIiaG7rpeDFHh4wHDjm9vyaHPhw=; b=kWOTB3rCQGNZ9W6qIl4ZH6CpY4gxMPV7womcIBlkAPUIsC8L2DEQVmKHNGDhegkDwr sXiqBR6RustG5FvR0asBSV6BlRyZ86eE95Kyg4EAdxxQjkrc7ApmrEY88Nn723SOk85g mmMow3cWpkuivHp4WEcy9A0LrqQFbFRuuWlXfv74U99q5/16Obq3sIXvrwxTopxHFTla 2j+bfxCgRafNLHIvK8ccHGmbr2qfTgi8h6rELQu4GIO3wyLSYD4D7pJnBD5u3gAzG38s XjYondJwLSsR5zn0kwX/B/PpxiLvznjKN9s+PLHPR1GR7PG3BQjwVFGMs949GXdv3jpH +naQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o18si4295902pfa.407.2018.02.10.21.12.22; Sat, 10 Feb 2018 21:12:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753795AbeBKFKZ (ORCPT + 99 others); Sun, 11 Feb 2018 00:10:25 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41438 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752646AbeBKEdm (ORCPT ); Sat, 10 Feb 2018 23:33:42 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKc-0002hL-EK; Sun, 11 Feb 2018 04:33:38 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKX-0004SK-88; Sun, 11 Feb 2018 04:33:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Jarkko Sakkinen" , "Alexander Steffen" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 11/79] tpm-dev-common: Reject too short writes In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Alexander Steffen commit ee70bc1e7b63ac8023c9ff9475d8741e397316e7 upstream. tpm_transmit() does not offer an explicit interface to indicate the number of valid bytes in the communication buffer. Instead, it relies on the commandSize field in the TPM header that is encoded within the buffer. Therefore, ensure that a) enough data has been written to the buffer, so that the commandSize field is present and b) the commandSize field does not announce more data than has been written to the buffer. This should have been fixed with CVE-2011-1161 long ago, but apparently a correct version of that patch never made it into the kernel. Signed-off-by: Alexander Steffen Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen [bwh: Backported to 3.2: - s/priv/chip/ - Adjust filename, context] Signed-off-by: Ben Hutchings --- drivers/char/tpm/tpm.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c @@ -1114,6 +1114,12 @@ ssize_t tpm_write(struct file *file, con return -EFAULT; } + if (in_size < 6 || + in_size < be32_to_cpu(*((__be32 *) (chip->data_buffer + 2)))) { + mutex_unlock(&chip->buffer_mutex); + return -EINVAL; + } + /* atomic tpm command send and result receive */ out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE); if (out_size < 0) {