From: Naman Jain <namjain@linux.microsoft.com>
To: Shradha Gupta <shradhagupta@linux.microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>
Cc: Shradha Gupta <shradhagupta@microsoft.com>,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
"K. Y. Srinivasan" <kys@microsoft.com>,
Dan Carpenter <error27@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] tools: hv: Zero unused bytes in KVP pool records
Date: Thu, 5 Nov 2026 16:10:08 +0530 [thread overview]
Message-ID: <c1e732c1-fcc6-4437-8891-dbea5e59ed27@linux.microsoft.com> (raw)
In-Reply-To: <20261102102953.432924-1-shradhagupta@linux.microsoft.com>
On 11/2/2026 3:59 PM, Shradha Gupta wrote:
> From: Shradha Gupta <shradhagupta@microsoft.com>
>
> KVP pool files store fixed-size key and value arrays. New records copy only
> the supplied key and value lengths into uninitialized storage, but the
> daemon writes each record in full. This can persist uninitialized heap
> bytes in the unused array tails. Shorter value replacements and
> string-based deletion compaction can also leave stale data in those tails.
>
> Zero new records before populating them, clear values before replacement,
> and copy complete records when compacting a pool after deletion.
>
> Also clear unused tails when loading existing records so GET and
> enumeration do not return legacy residual bytes. These sanitized records
> reach disk on the next successful update to that pool; loading alone does
> not rewrite the file.
>
> The record layout and logical key/value strings are unchanged.
>
> Fixes: db425334e5bb ("Tools: hv: Fully support the new KVP verbs in the user level daemon")
> Signed-off-by: Shradha Gupta <shradhagupta@microsoft.com>
> ---
> tools/hv/hv_kvp_daemon.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 1f64c680b..d57729f60 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -203,6 +203,7 @@ static void kvp_update_mem_state(int pool)
> {
> FILE *filep;
> size_t records_read = 0;
> + size_t i, len;
> struct kvp_record *record = kvp_file_info[pool].records;
> struct kvp_record *readp;
> int num_blocks = kvp_file_info[pool].num_blocks;
> @@ -248,6 +249,15 @@ static void kvp_update_mem_state(int pool)
> break;
> }
>
> + /* Discard stale bytes after strings in existing pool records. */
> + for (i = 0; i < records_read; i++) {
> + len = strnlen(record[i].key, sizeof(record[i].key));
> + memset(record[i].key + len, 0, sizeof(record[i].key) - len);
> + len = strnlen(record[i].value, sizeof(record[i].value));
> + memset(record[i].value + len, 0,
> + sizeof(record[i].value) - len);
> + }
> +
> kvp_file_info[pool].num_blocks = num_blocks;
> kvp_file_info[pool].records = record;
> kvp_file_info[pool].num_records = records_read;
> @@ -327,8 +337,7 @@ static int kvp_key_delete(int pool, const __u8 *key, int key_size)
> j = i;
> k = j + 1;
> for (; k < num_records; k++) {
> - strcpy(record[j].key, record[k].key);
> - strcpy(record[j].value, record[k].value);
> + memcpy(&record[j], &record[k], sizeof(record[j]));
> j++;
> }
>
> @@ -383,6 +392,7 @@ static int kvp_key_add_or_modify(int pool, const __u8 *key, int key_size,
> * Found a match; just update the value -
> * this is the modify case.
> */
> + memset(record[i].value, 0, sizeof(record[i].value));
> memcpy(record[i].value, value, value_size);
> kvp_update_file(pool);
> if (debug)
> @@ -406,6 +416,7 @@ static int kvp_key_add_or_modify(int pool, const __u8 *key, int key_size,
> kvp_file_info[pool].num_blocks++;
>
> }
> + memset(&record[i], 0, sizeof(record[i]));
> memcpy(record[i].value, value, value_size);
> memcpy(record[i].key, key, key_size);
> kvp_file_info[pool].records = record;
>
> base-commit: 20a33c6b6cbe7e4805dfb6cd68816937443aa148
Reviewed-by: Naman Jain <namjain@linux.microsoft.com>
Regards,
Naman
prev parent reply other threads:[~2026-11-05 10:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 10:29 Shradha Gupta
2026-11-05 10:40 ` Naman Jain [this message]
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=c1e732c1-fcc6-4437-8891-dbea5e59ed27@linux.microsoft.com \
--to=namjain@linux.microsoft.com \
--cc=decui@microsoft.com \
--cc=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shradhagupta@linux.microsoft.com \
--cc=shradhagupta@microsoft.com \
--cc=wei.liu@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®