Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2226114imm; Thu, 7 Jun 2018 07:21:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIsZwpVHuJV1wRPeNSVR9E+AMGctyeDBNSU0BVInswW8NVS1pPZc7gQhQd75iOjpj847BNq X-Received: by 2002:a17:902:d90f:: with SMTP id c15-v6mr2250757plz.65.1528381272321; Thu, 07 Jun 2018 07:21:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528381272; cv=none; d=google.com; s=arc-20160816; b=bONyUsyk+AzL2+cH6tHdzPX4S6OUB4yYHMkTQNLuJINQYSaoorvU1dmQ/LWeQ7lwO/ KXq0rCOw/XKA67oZBvnMJ5P/lo5lunLrCqcZ/4vvWdtpjgb/Tcl7ON4LOHm2fQyZJDY4 COArUeiQqwNrNYy6oBv4QOdFwF3nLOiH01NP4qQBvusUnVpyKpX4WHBhEQgtQLfxfIZN SG1nE/lL/NBW072HOZ2UQm/BzUpSw3QpdYpUAqf/qJtEKkXRpa0MdxH//m8CIllGElg4 ZPsc6c3+wt076uyVf9Wxv9rO8vWFMCejTD6H8E/DtqMcMV3JIIkKitJZV/MIw2tXJ/Qd WMIA== 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=8XOX9Ilb52B8g5rsaGn/SrAkKePJS9ShuvNrPBhViHU=; b=w3PGJiUypJ2W0F5qimVrJ8lzTMUv3I3FcDIESgV3mvacefiagHCb6VNDsCPx/ToIjM tVPGbDgDG1x3TtHFky9Y51SviksimHo2oOqP00tX/tuHRzNPNgRR8H6uVtSenafe496O +M73PQKarxldLfnRSJt/yywYIm9z3q1Jpq/P8qXlbKNXjuoFWAoFu0tPi7ijQ8DlsBcy qjDAN1v7VkclLS4Xuoh2WVA7xekAl6ZSahP+jP0dPPy3S6nxVevIYrhxrkeAis6llfAI gcsDBFZNVPoTZlGiKidHLJu99GT3Xxwzui04zdvrMavgxpHD7/mDAsY6z7PGAkUrdwon 7myA== 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 b2-v6si10029208pgt.611.2018.06.07.07.20.57; Thu, 07 Jun 2018 07:21:12 -0700 (PDT) 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 S933148AbeFGORt (ORCPT + 99 others); Thu, 7 Jun 2018 10:17:49 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39551 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933099AbeFGOJN (ORCPT ); Thu, 7 Jun 2018 10:09:13 -0400 Received: from [148.252.241.226] (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 1fQvbD-0005Zq-Cw; Thu, 07 Jun 2018 15:09:11 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvbA-00039W-AL; Thu, 07 Jun 2018 15:09:08 +0100 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, "James Morris" , "James Bottomley" , "Jeremy Boone" , "Jarkko Sakkinen" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 298/410] tpm: fix potential buffer overruns caused by bit glitches on the bus In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 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.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Jeremy Boone commit 3be23274755ee85771270a23af7691dc9b3a95db upstream. Discrete TPMs are often connected over slow serial buses which, on some platforms, can have glitches causing bit flips. If a bit does flip it could cause an overrun if it's in one of the size parameters, so sanity check that we're not overrunning the provided buffer when doing a memcpy(). Signed-off-by: Jeremy Boone Signed-off-by: James Bottomley Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: James Morris [bwh: Backported to 3.16: Drop the TPM2 bits] Signed-off-by: Ben Hutchings --- drivers/char/tpm/tpm-interface.c | 4 ++++ drivers/char/tpm/tpm2-cmd.c | 4 ++++ 2 files changed, 8 insertions(+) --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -1029,6 +1029,10 @@ int tpm_get_random(u32 chip_num, u8 *out break; recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len); + if (recd > num_bytes) { + total = -EFAULT; + break; + } memcpy(dest, tpm_cmd.params.getrandom_out.rng_data, recd); dest += recd;