Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp59284ybl; Tue, 7 Jan 2020 14:07:45 -0800 (PST) X-Google-Smtp-Source: APXvYqypeMPRWy6g46lZk8iepO194lGjFVnnRmlwmQZpipn3DrDLEBnwutsRjcgIb/mGkQnvV7s+ X-Received: by 2002:a9d:7501:: with SMTP id r1mr1915539otk.196.1578434865592; Tue, 07 Jan 2020 14:07:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578434865; cv=none; d=google.com; s=arc-20160816; b=iZlJ8WANn6CtvIckIwX/77lCi4s9vZL7ywG3bOR9FE3DLnQgOzx9rNu/86F+7Da5Zd i09tSxN3096FIruSIn/6pJL073FXgHm4kXYOeMrZoVDXxly0IJXWfsW7AEBrKUCrgAvW lK8rfNcEqa/pZXCI2GxkWbRj/mAfryoINAef/tBt8+WmrFZyhPU2DtMA5+sQGIT18Uaa 3vAI9LmP1iVX/b1uaTevutYj1tBPMr9NZE2xaZ0B8USq0lmnWa8TTeXO0JcUqtgrH+Zx Y1fGPeVIVICKRyXSAO7irYvVFoP0ScZSk2Tp5svp8aaBIkDdE53sx/ynT83t0LLRdQ87 N3SA== 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:cc:to:from :subject; bh=uuCKG5MgnhX64GDEHNltYRfjEybZSUiHpDHpDN2w1+Y=; b=s/6+otkiOPjH6VND/aT830pvYUxYZOtDoGzBk20iWi0Nld48Hyn2eELfHcvmFF7aDI Pn/w5Cje6rbkzg+fE4dNPei5VUin9e8m8FMIYYRSMpgi8n3w6gTfU9D4zoeT19u+FsQr CHueJfyqSN5SP9NChdEsR+Cu+Oq5JlRO2jwRFFlwU80Te5LtqiyVG7Oadax4vciZCFML Y4q7USFIUcU/3r+jb8WGkqta7YrSL1JqHuDEEbakvTgmALYJxPx2AyQYpObHSAotMBkq /qvkbzNpYeCsNgUXDnRXhKbFqM7wOGWb1hgix3vHZ1Ybi0Ie8UKcpplLnZjudwWh7XvU sttw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10si635678otf.237.2020.01.07.14.07.32; Tue, 07 Jan 2020 14:07:45 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727417AbgAGWEl (ORCPT + 99 others); Tue, 7 Jan 2020 17:04:41 -0500 Received: from mga11.intel.com ([192.55.52.93]:40523 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727080AbgAGWEk (ORCPT ); Tue, 7 Jan 2020 17:04:40 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jan 2020 14:04:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,407,1571727600"; d="scan'208";a="217317989" Received: from tstruk-mobl1.jf.intel.com (HELO [127.0.1.1]) ([10.7.196.67]) by fmsmga007.fm.intel.com with ESMTP; 07 Jan 2020 14:04:39 -0800 Subject: [PATCH] tpm: handle negative priv->response_len in tpm_common_read From: Tadeusz Struk To: jarkko.sakkinen@linux.intel.com Cc: keescook@chromium.org, tadeusz.struk@intel.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-integrity@vger.kernel.org, labbott@redhat.com Date: Tue, 07 Jan 2020 14:04:48 -0800 Message-ID: <157843468820.24718.10808226634364669421.stgit@tstruk-mobl1> In-Reply-To: References: User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The priv->responce_length can hold the size of an response or an negative error code, and the tpm_common_read() needs to handle both cases correctly. Changed the type of responce_length to signed and accounted for negative value in tpm_common_read() Cc: stable@vger.kernel.org Fixes: d23d12484307 ("tpm: fix invalid locking in NONBLOCKING mode") Reported-by: Laura Abbott Signed-off-by: Tadeusz Struk --- drivers/char/tpm/tpm-dev-common.c | 2 +- drivers/char/tpm/tpm-dev.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c index b23b0b999232..87f449340202 100644 --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -130,7 +130,7 @@ ssize_t tpm_common_read(struct file *file, char __user *buf, priv->response_read = true; ret_size = min_t(ssize_t, size, priv->response_length); - if (!ret_size) { + if (ret_size <= 0) { priv->response_length = 0; goto out; } diff --git a/drivers/char/tpm/tpm-dev.h b/drivers/char/tpm/tpm-dev.h index 1089fc0bb290..f3742bcc73e3 100644 --- a/drivers/char/tpm/tpm-dev.h +++ b/drivers/char/tpm/tpm-dev.h @@ -14,7 +14,7 @@ struct file_priv { struct work_struct timeout_work; struct work_struct async_work; wait_queue_head_t async_wait; - size_t response_length; + ssize_t response_length; bool response_read; bool command_enqueued;