Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3474487imu; Sun, 11 Nov 2018 15:57:07 -0800 (PST) X-Google-Smtp-Source: AJdET5eL3jpYHahPKRA3FoBIaz/2CZG5o+9kfyuCmGY/F3kb6TfcOgcqPM90MUjRZk0GW+u2P2uo X-Received: by 2002:a63:5357:: with SMTP id t23-v6mr15750958pgl.40.1541980627425; Sun, 11 Nov 2018 15:57:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980627; cv=none; d=google.com; s=arc-20160816; b=s7dwLHAusx13Fc5vf+3CLsxYVeZbtO7Mv016UmndBVDYJN5tLxRAJTNFVcHxvOymo4 Vyvyd1NHO8n28YKd/IfqvM0QvgeLrC2T+O0eVl8OFNibs7Yw48P4c+QCc4adu6JQj1oX ZXvFcHZQ8C7wD52NrYdflHgz2Yk14YyUjo+LZXkB4nciJZ7wmw7fQ+sxnrr9CKnkp0sw B75jL0MD4hohgSe5ds+xEGK9ppW+arkBz0izJ/Ym7DhIQ3tM+pEAjID3bWKD/S3zIDuB pDX7aiozpRYa7euy5X78tW9JWTbO5+tlS/K2vw5Pbnp71uyfF0X/ng6j3PNauCE5SLM6 vjww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L2iEE9IBjHf63kOkuzf38wXnIubKkq43xoghWgLR3oE=; b=P71N1+TYoWjE+VjKPsPLzJ1a/UKP4HFCmTYMc7hhh8Sw77zOuxR5xKadjd2HR5EbtP 5CknaRr7dIvHTVd9U7ZD6wtNmoLSf0EzN5Opcc1jo5FKZhWjZ2vMIYHqlA26GoorN2Eo 2aGknprED5Df6Lc4CU6CcxRL8SrpqB5Q9S/zlBmt41pC7FHdtFkN5gIfAlRifbKwg1RE SFSTGRBARPl1i1ISgIBn8M3lixY9FqSZitF1a1irdSRIrfJDH3MCxcubwQRrIB58SZf7 cH4IvEVYT+JML+9HUrJxrlWi9UAqvi+eLXrRdLAkWtqyDNTTG6UBFnhAJW8GKN50jdxp 4fTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FIWJ8XMU; 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 q5si9078614pgk.46.2018.11.11.15.56.52; Sun, 11 Nov 2018 15:57:07 -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; dkim=pass header.i=@kernel.org header.s=default header.b=FIWJ8XMU; 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 S1732967AbeKLJpj (ORCPT + 99 others); Mon, 12 Nov 2018 04:45:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:37238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732619AbeKLIST (ORCPT ); Mon, 12 Nov 2018 03:18:19 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DDCEB215EA; Sun, 11 Nov 2018 22:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975303; bh=OxqoB3U0UqRa9EepOiuIIJg50XpkAyFB1Vz90F3aV+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FIWJ8XMUUELe1sewVNaMjsVQUeGuWlw/ZNaWKjSdckDTI2b04LFwugVq7/0jaCvYy XtVBGe207a3AmgKvpSjFwRd8CFn6go9Vhz2N8QhenZxR484T7vCtc9N6L6ipzibbBW FMpc027YDXMMN41ZDYukLYxwU1XdbMySmz9U3XPg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jarkko Sakkinen Subject: [PATCH 4.19 268/361] tpm: fix response size validation in tpm_get_random() Date: Sun, 11 Nov 2018 14:20:15 -0800 Message-Id: <20181111221654.813027669@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jarkko Sakkinen commit 84b59f6487d82d3ab4247a099aba66d4d17e8b08 upstream. When checking whether the response is large enough to be able to contain the received random bytes in tpm_get_random() and tpm2_get_random(), they fail to take account the header size, which should be added to the minimum size. This commit fixes this issue. Cc: stable@vger.kernel.org Fixes: c659af78eb7b ("tpm: Check size of response before accessing data") Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm-interface.c | 3 ++- drivers/char/tpm/tpm2-cmd.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -1322,7 +1322,8 @@ int tpm_get_random(struct tpm_chip *chip } rlength = be32_to_cpu(tpm_cmd.header.out.length); - if (rlength < offsetof(struct tpm_getrandom_out, rng_data) + + if (rlength < TPM_HEADER_SIZE + + offsetof(struct tpm_getrandom_out, rng_data) + recd) { total = -EFAULT; break; --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -329,7 +329,9 @@ int tpm2_get_random(struct tpm_chip *chi &buf.data[TPM_HEADER_SIZE]; recd = min_t(u32, be16_to_cpu(out->size), num_bytes); if (tpm_buf_length(&buf) < - offsetof(struct tpm2_get_random_out, buffer) + recd) { + TPM_HEADER_SIZE + + offsetof(struct tpm2_get_random_out, buffer) + + recd) { err = -EFAULT; goto out; }