From: Dave Hansen <dave.hansen@intel.com>
To: Justin Stitt <justinstitt@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>
Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
Kees Cook <keescook@chromium.org>,
Nick Desaulniers <ndesaulniers@google.com>
Subject: Re: [PATCH] x86/tdx: refactor deprecated strncpy
Date: Mon, 11 Sep 2023 11:51:03 -0700 [thread overview]
Message-ID: <69643667-4564-0266-1b26-13833191842c@intel.com> (raw)
In-Reply-To: <20230911-strncpy-arch-x86-coco-tdx-tdx-c-v1-1-4b38155727f3@google.com>
On 9/11/23 11:27, Justin Stitt wrote:
> `strncpy` is deprecated and we should prefer more robust string apis.
I dunno. It actually seems like a pretty good fit here.
> In this case, `message.str` is not expected to be NUL-terminated as it
> is simply a buffer of characters residing in a union which allows for
> named fields representing 8 bytes each. There is only one caller of
> `tdx_panic()` and they use a 59-length string for `msg`:
> | const char *msg = "TD misconfiguration: SEPT_VE_DISABLE attribute must be set.";
I'm not really following this logic.
We need to do the following:
1. Make sure not to over write past the end of 'message'
2. Make sure not to over read past the end of 'msg'
3. Make sure not to leak stack data into the hypercall registers
in the case of short strings.
strncpy() does #1, #2 and #3 just fine.
The resulting string does *NOT* need to be NULL-terminated. See the
comment:
/* VMM assumes '\0' in byte 65, if the message took all 64 bytes */
Are there cases where strncpy() doesn't NULL-terminate the string other
than when the buffer is full?
I actually didn't realize that strncpy() pads its output up to the full
size. I wonder if Kirill used it intentionally or whether he got lucky
here. :)
next prev parent reply other threads:[~2023-09-11 22:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 18:27 Justin Stitt
2023-09-11 18:51 ` Dave Hansen [this message]
2023-09-11 22:01 ` Justin Stitt
2023-09-15 3:07 ` Kees Cook
2023-09-29 18:33 ` Kees Cook
2023-09-29 21:14 ` Ingo Molnar
2023-09-29 21:51 ` Kees Cook
2023-09-29 21:27 ` Dave Hansen
2023-09-29 21:50 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=69643667-4564-0266-1b26-13833191842c@intel.com \
--to=dave.hansen@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=justinstitt@google.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=ndesaulniers@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®