Re: [PATCH v12 2/3] selftests: tdx: Test TDX attestation GetReport support
From: Sathyanarayanan Kuppuswamy
Date: Fri Sep 09 2022 - 01:08:43 EST
On 9/8/22 8:48 PM, Huang, Kai wrote:
> On Wed, 2022-09-07 at 17:27 -0700, Kuppuswamy Sathyanarayanan wrote:
>> +TEST(verify_report)
>> +{
>> + __u8 reportdata[TDX_REPORTDATA_LEN];
>> + struct tdreport tdreport;
>> + struct tdx_report_req req;
>> + int devfd, i;
>> +
>> + devfd = open(TDX_GUEST_DEVNAME, O_RDWR | O_SYNC);
>> +
>> + ASSERT_LT(0, devfd);
>> +
>> + /* Generate sample report data */
>> + for (i = 0; i < TDX_REPORTDATA_LEN; i++)
>> + reportdata[i] = i;
>> +
>> + /* Initialize IOCTL request */
>> + req.subtype = 0;
>> + req.reportdata = (__u64)reportdata;
>> + req.rpd_len = TDX_REPORTDATA_LEN;
>> + req.tdreport = (__u64)&tdreport;
>> + req.tdr_len = sizeof(tdreport);
>> +
>
> 'req' is a local variable, which isn't guaranteed to be zero. Looks you need to
> explicitly clear 'req' otherwise the req.reserved[7] may not be zero.
In the next version, I explicitly set it to 0. I could initialize the struct to
0. But doing it explicitly will show the expected values clearly.
memset(req.reserved, 0, sizeof(req.reserved));
>
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer