[Devel] [PATCH RHEL9 COMMIT] ms/hv_sock: Extract hvs_send_data() helper that takes only header

Konstantin Khorenko khorenko at virtuozzo.com
Fri Nov 3 21:03:17 MSK 2023


The commit is pushed to "branch-rh9-5.14.0-284.25.1.vz9.30.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-284.25.1.vz9.30.10
------>
commit bf93e8655a7237f3e6298bbfae9d5bb0d1929fbe
Author: Kees Cook <keescook at chromium.org>
Date:   Mon Dec 6 22:32:17 2021 -0800

    ms/hv_sock: Extract hvs_send_data() helper that takes only header
    
    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 at chromium.org>
    Acked-by: Wei Liu <wei.liu at kernel.org>
    Link: https://lore.kernel.org/r/20211207063217.2591451-1-keescook@chromium.org
    Signed-off-by: Jakub Kicinski <kuba at kernel.org>
    
    Getting rid of compilation warnings.
    
    https://virtuozzo.atlassian.net/browse/PSBM-148793
    
    Feature: fix ms/drivers
    
    (cherry picked from commit c0e084e342a8046d06c4172b6ccb4db5d7633156)
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 net/vmw_vsock/hyperv_transport.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
index d6c20168b43a..59c3e2697069 100644
--- a/net/vmw_vsock/hyperv_transport.c
+++ b/net/vmw_vsock/hyperv_transport.c
@@ -228,14 +228,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)
@@ -473,7 +479,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;
 }
 


More information about the Devel mailing list