diff mbox series

hv_sock: Extract hvs_send_data() helper that takes only header

Message ID 20211207063217.2591451-1-keescook@chromium.org (mailing list archive)
State Accepted
Commit c0e084e342a8046d06c4172b6ccb4db5d7633156
Delegated to: Netdev Maintainers
Headers show
Series hv_sock: Extract hvs_send_data() helper that takes only header | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 33 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Kees Cook Dec. 7, 2021, 6:32 a.m. UTC
When building under -Warray-bounds, the compiler is especially
conservative when faced with casts from a smaller object to a larger
object. While this has found many real bugs, there are some cases that
are currently false positives (like here). With this as one of the last
few instances of the warning in the kernel before -Warray-bounds can be
enabled globally, rearrange the functions so that there is a header-only
version of hvs_send_data(). Silences this warning:

net/vmw_vsock/hyperv_transport.c: In function 'hvs_shutdown_lock_held.constprop':
net/vmw_vsock/hyperv_transport.c:231:32: warning: array subscript 'struct hvs_send_buf[0]' is partly outside array bounds of 'struct vmpipe_proto_header[1]' [-Warray-bounds]
  231 |         send_buf->hdr.pkt_type = 1;
      |         ~~~~~~~~~~~~~~~~~~~~~~~^~~
net/vmw_vsock/hyperv_transport.c:465:36: note: while referencing 'hdr'
  465 |         struct vmpipe_proto_header hdr;
      |                                    ^~~

This change results in no executable instruction differences.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 net/vmw_vsock/hyperv_transport.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

Wei Liu Dec. 7, 2021, 12:03 p.m. UTC | #1
On Mon, Dec 06, 2021 at 10:32:17PM -0800, Kees Cook wrote:
> When building under -Warray-bounds, the compiler is especially
> conservative when faced with casts from a smaller object to a larger
> object. While this has found many real bugs, there are some cases that
> are currently false positives (like here). With this as one of the last
> few instances of the warning in the kernel before -Warray-bounds can be
> enabled globally, rearrange the functions so that there is a header-only
> version of hvs_send_data(). Silences this warning:
> 
> net/vmw_vsock/hyperv_transport.c: In function 'hvs_shutdown_lock_held.constprop':
> net/vmw_vsock/hyperv_transport.c:231:32: warning: array subscript 'struct hvs_send_buf[0]' is partly outside array bounds of 'struct vmpipe_proto_header[1]' [-Warray-bounds]
>   231 |         send_buf->hdr.pkt_type = 1;
>       |         ~~~~~~~~~~~~~~~~~~~~~~~^~~
> net/vmw_vsock/hyperv_transport.c:465:36: note: while referencing 'hdr'
>   465 |         struct vmpipe_proto_header hdr;
>       |                                    ^~~
> 
> This change results in no executable instruction differences.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Wei Liu <wei.liu@kernel.org>
patchwork-bot+netdevbpf@kernel.org Dec. 8, 2021, 6:10 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  6 Dec 2021 22:32:17 -0800 you wrote:
> When building under -Warray-bounds, the compiler is especially
> conservative when faced with casts from a smaller object to a larger
> object. While this has found many real bugs, there are some cases that
> are currently false positives (like here). With this as one of the last
> few instances of the warning in the kernel before -Warray-bounds can be
> enabled globally, rearrange the functions so that there is a header-only
> version of hvs_send_data(). Silences this warning:
> 
> [...]

Here is the summary with links:
  - hv_sock: Extract hvs_send_data() helper that takes only header
    https://git.kernel.org/netdev/net-next/c/c0e084e342a8

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
index 19189cf30a72..e111e13b6660 100644
--- a/net/vmw_vsock/hyperv_transport.c
+++ b/net/vmw_vsock/hyperv_transport.c
@@ -225,14 +225,20 @@  static size_t hvs_channel_writable_bytes(struct vmbus_channel *chan)
 	return round_down(ret, 8);
 }
 
+static int __hvs_send_data(struct vmbus_channel *chan,
+			   struct vmpipe_proto_header *hdr,
+			   size_t to_write)
+{
+	hdr->pkt_type = 1;
+	hdr->data_size = to_write;
+	return vmbus_sendpacket(chan, hdr, sizeof(*hdr) + to_write,
+				0, VM_PKT_DATA_INBAND, 0);
+}
+
 static int hvs_send_data(struct vmbus_channel *chan,
 			 struct hvs_send_buf *send_buf, size_t to_write)
 {
-	send_buf->hdr.pkt_type = 1;
-	send_buf->hdr.data_size = to_write;
-	return vmbus_sendpacket(chan, &send_buf->hdr,
-				sizeof(send_buf->hdr) + to_write,
-				0, VM_PKT_DATA_INBAND, 0);
+	return __hvs_send_data(chan, &send_buf->hdr, to_write);
 }
 
 static void hvs_channel_cb(void *ctx)
@@ -468,7 +474,7 @@  static void hvs_shutdown_lock_held(struct hvsock *hvs, int mode)
 		return;
 
 	/* It can't fail: see hvs_channel_writable_bytes(). */
-	(void)hvs_send_data(hvs->chan, (struct hvs_send_buf *)&hdr, 0);
+	(void)__hvs_send_data(hvs->chan, &hdr, 0);
 	hvs->fin_sent = true;
 }