[PATCH] Truncate UTS_RELEASE for rxrpc version

From: Kenny Ho
Date: Thu May 25 2023 - 17:14:35 EST


UTS_RELEASE has maximum length of 64 which can cause rxrpc_version to
exceed the 65 byte message limit.

Per https://web.mit.edu/kolya/afs/rx/rx-spec
"If a server receives a packet with a type value of 13, and the
client-initiated flag set, it should respond with a 65-byte payload
containing a string that identifies the version of AFS software it is
running."

Current implementation causes compile error when WERROR is turned on and
when UTS_RELEASE exceed the length of 49 (making the version string more
than 64 characters.)

Signed-off-by: Kenny Ho <Kenny.Ho@xxxxxxx>
---
net/rxrpc/local_event.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/rxrpc/local_event.c b/net/rxrpc/local_event.c
index 19e929c7c38b..90af6fbb9266 100644
--- a/net/rxrpc/local_event.c
+++ b/net/rxrpc/local_event.c
@@ -16,8 +16,6 @@
#include <generated/utsrelease.h>
#include "ar-internal.h"

-static const char rxrpc_version_string[65] = "linux-" UTS_RELEASE " AF_RXRPC";
-
/*
* Reply to a version request
*/
@@ -30,6 +28,7 @@ static void rxrpc_send_version_request(struct rxrpc_local *local,
struct sockaddr_rxrpc srx;
struct msghdr msg;
struct kvec iov[2];
+ static char rxrpc_version_string[65];
size_t len;
int ret;

@@ -38,6 +37,12 @@ static void rxrpc_send_version_request(struct rxrpc_local *local,
if (rxrpc_extract_addr_from_skb(&srx, skb) < 0)
return;

+ if (!rxrpc_version_string[0])
+ snprintf(rxrpc_version_string,
+ sizeof(rxrpc_version_string),
+ "linux-%.49s AF_RXRPC",
+ UTS_RELEASE);
+
msg.msg_name = &srx.transport;
msg.msg_namelen = srx.transport_len;
msg.msg_control = NULL;
--
2.25.1