[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 9 Sep 2022 13:07:29 -0700
From: Sathyanarayanan Kuppuswamy
<sathyanarayanan.kuppuswamy@...ux.intel.com>
To: Dave Hansen <dave.hansen@...el.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
Shuah Khan <shuah@...nel.org>
Cc: "H . Peter Anvin" <hpa@...or.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
Tony Luck <tony.luck@...el.com>,
Andi Kleen <ak@...ux.intel.com>,
Kai Huang <kai.huang@...el.com>,
Wander Lairson Costa <wander@...hat.com>,
Isaku Yamahata <isaku.yamahata@...il.com>,
marcelo.cerri@...onical.com, tim.gardner@...onical.com,
khalid.elmously@...onical.com, philip.cox@...onical.com,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
linux-doc@...r.kernel.org
Subject: Re: [PATCH v13 1/3] x86/tdx: Add TDX Guest attestation interface
driver
On 9/9/22 12:41 PM, Dave Hansen wrote:
> On 9/9/22 12:27, Kuppuswamy Sathyanarayanan wrote:
>> + u8 reserved[7] = {0};
> ...
>> + if (!req.reportdata || !req.tdreport || req.subtype ||
>> + req.rpd_len != TDX_REPORTDATA_LEN ||
>> + req.tdr_len != TDX_REPORT_LEN ||
>> + memcmp(req.reserved, reserved, 7))
>> + return -EINVAL;
>
> Huh, so to look for 0's, you:
>
> 1. Declare an on-stack structure with a hard coded, magic numbered field
> that has to be zeroed.
> 2. memcmp() that structure
> 3. Feed memcmp() with another hard coded magic number
>
> I've gotta ask: did you have any reservations writing this code? Were
> there any alarm bells going off saying that something might be wrong?
>
> Using memcmp() itself is probably forgivable. But, the two magic
> numbers are pretty mortal sins in my book. What's going to happen the
> first moment someone wants to repurpose a reserved byte? They're going
> to do:
>
> - __u8 reserved[7];
> + __u8 my_new_byte;
> + __u8 reserved[6];
>
> What's going to happen to the code you wrote? Will it continue to work?
> Or will the memcmp() silently start doing crazy stuff as it overruns
> the structure into garbage land?
>
> What's wrong with:
>
> memchr_inv(&req.reserved, sizeof(req.reserved), 0)
I did not consider the hard coding issue. It is a mistake. Your suggestion
looks better. I will use it.
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
Powered by blists - more mailing lists