Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp3915409ybe; Mon, 16 Sep 2019 03:37:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+3WTvUPQyrF/MOS5LdHoOAFNPPp/I4G4x0jpGqv2XM2lXtIhoBbTN32NpIV6ZtC6zd8NN X-Received: by 2002:a17:906:b6d0:: with SMTP id ec16mr25266914ejb.206.1568630261355; Mon, 16 Sep 2019 03:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568630261; cv=none; d=google.com; s=arc-20160816; b=zU5XHqYqQBV8d+G6JTzlJW1NBQUtP6xhYOC5xp45aITsJpAXm+LZZOTv7dAgx3HehP 84lbu2JO+186SzQTDDCib0GPv4omV6rVA0SYhUEsfzLEDvK8s3y3mu1lCALsAwlOigs/ QPr5TTikMy5VtNyUO3XA85LAXyLZaH4on0pccoNKbU4hpTG8fD3hrLpA3Np5iJuREHPW EaX+ifzsghbnXU+VmQLhLCe9F1G5tTIbEbLmbCwtf4juqpjUnRovvpwITmfItOdliCbE QEI7Ngbk7tGIVqXthqVYgpmACIJMeHF1wAT7WG+mOczJbPnCX3TnM9Af4AoGlAUCqXsJ fETw== 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 :message-id:date:subject:cc:to:from; bh=5U7t1fFKLjpXfrGqc1ysq0+2IhNJ56dpXqzqdyINCEk=; b=eBPtM7iEWJquBegHniHo0+PM2j8lVAJTklMxRdzfXTeQGbq3d4XMOBf3IBENz6QOyY 6vPzirgOXURC0zDEG9Uy2zJGtQpWrjwavbsvmwjPztvR1+uFPP/ooJqqQmVbyvkNynWM 5Lcnrhypr0NIEENYvmxOHEndH/wnyqBUBDLTDFU+jKP7/cpg5HdkszqmcDC+2ic5M0uL P0JAZZQt/a4YtT0HntK+m7QA6/exzi1Rfp4gBAXZMKiLNbOx4HYtnSL5p/bvz4RFh6ut URbiMIRCfuuUrkJYkHSBWIKcHQmcXjuOYzPVj5/7uQpKXthU8cVDgYWywaaryFWpZw8T LaFQ== 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 qp4si5400263ejb.171.2019.09.16.03.37.18; Mon, 16 Sep 2019 03:37:41 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731304AbfIPIuS (ORCPT + 99 others); Mon, 16 Sep 2019 04:50:18 -0400 Received: from mga18.intel.com ([134.134.136.126]:19905 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728142AbfIPIuS (ORCPT ); Mon, 16 Sep 2019 04:50:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Sep 2019 01:50:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,512,1559545200"; d="scan'208";a="193381785" Received: from unknown (HELO localhost) ([10.252.55.169]) by FMSMGA003.fm.intel.com with ESMTP; 16 Sep 2019 01:50:13 -0700 From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Jarkko Sakkinen , Mimi Zohar , stable@vger.kernel.org, Peter Huewe , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] tpm: Wrap the buffer from the caller to tpm_buf in tpm_send() Date: Mon, 16 Sep 2019 11:50:08 +0300 Message-Id: <20190916085008.22239-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org tpm_send() does not give anymore the result back to the caller. This would require another memcpy(), which kind of tells that the whole approach is somewhat broken. Instead, as Mimi suggested, this commit just wraps the data to the tpm_buf, and thus the result will not go to the garbage. Obviously this assumes from the caller that it passes large enough buffer, which makes the whole API somewhat broken because it could be different size than @buflen but since trusted keys is the only module using this API right now I think that this fix is sufficient for the moment. In the near future the plan is to replace the parameters with a tpm_buf created by the caller. Reported-by: Mimi Zohar Suggested-by: Mimi Zohar Cc: stable@vger.kernel.org Fixes: 412eb585587a ("use tpm_buf in tpm_transmit_cmd() as the IO parameter") Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-interface.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index d9ace5480665..2459d36dd8cc 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -358,13 +358,9 @@ int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen) if (!chip) return -ENODEV; - rc = tpm_buf_init(&buf, 0, 0); - if (rc) - goto out; - - memcpy(buf.data, cmd, buflen); + buf.data = cmd; rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to a send a command"); - tpm_buf_destroy(&buf); + out: tpm_put_ops(chip); return rc; -- 2.20.1