-----Original Message-----
From: Michael Kelley (LINUX) <redacted>
Sent: Monday, August 7, 2023 10:26 PM
To: Saurabh Sengar <ssengar@linux.microsoft.com>; KY Srinivasan
[off-list ref]; Haiyang Zhang [off-list ref];
wei.liu@kernel.org; Dexuan Cui [off-list ref]
Cc: <redacted>; <redacted>; Saurabh
Singh Sengar [off-list ref]
Subject: RE: [PATCH] hv: hyperv.h: Replace one-element array with flexible-
array member
From: Saurabh Sengar <ssengar@linux.microsoft.com> Sent: Monday, August
7, 2023 2:51 AM
quoted
One-element and zero-length arrays are deprecated. Replace one-element
array in struct vmtransfer_page_packet_header with flexible-array
member. This change fixes below warning:
[ 2.593788]
================================================================
================
quoted
[ 2.593908] UBSAN: array-index-out-of-bounds in
drivers/net/hyperv/netvsc.c:1445:41
quoted
[ 2.593989] index 1 is out of range for type 'vmtransfer_page_range [1]'
[ 2.594049] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 6.5.0-rc4-next-
20230803+ #1
quoted
[ 2.594114] Hardware name: Microsoft Corporation Virtual
Machine/Virtual Machine, BIOS Hyper-V UEFI Release v4.1 04/20/2023
quoted
[ 2.594121] Call Trace:
[ 2.594126] <IRQ>
[ 2.594133] dump_stack_lvl+0x4c/0x70
[ 2.594154] dump_stack+0x14/0x20
[ 2.594162] __ubsan_handle_out_of_bounds+0xa6/0xf0
[ 2.594224] netvsc_poll+0xc01/0xc90 [hv_netvsc]
[ 2.594258] __napi_poll+0x30/0x1e0
[ 2.594320] net_rx_action+0x194/0x2f0
[ 2.594333] __do_softirq+0xde/0x31e
[ 2.594345] __irq_exit_rcu+0x6b/0x90
[ 2.594357] irq_exit_rcu+0x12/0x20
79 more quoted lines
Thanks for your comment, I wanted to have this discussion.
Before sending this patch, I was contemplating whether or not to make this change.
Through my analysis, I arrived at the conclusion that the initial validation code
wasn't entirely accurate. And with the proposed changes it gets more accurate.
IMHO it is more accurate to exclude the size of 'ranges' in the header.
With my limited understanding of this driver, the current "header size validation"
is only to make sure that header is correct. So, that we fetch the range_cnt and
xfer_pageset_id correctly from it. For this to be done I don't find any reason
to include the size of ranges in this check. With inclusion of ranges we are
checking the first 'struct vmtransfer_page_range' size as well which is not required
for fetching above two values.
Once we have the count of ranges we will anyway check the sanity of ranges with
NETVSC_XFER_HEADER_SIZE. This will check "count * (struct vmtransfer_page_range)"
Which is present few lines after.
For a ranges count = 1, I don't see there is any difference between both the checks as
of today.
Please let me know you opinion if you don't find my explanation reasonable.
I don't see any other place this structure's size change will affect.
- Saurabh
Michael