From patchwork Thu Jan 16 21:19:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thorsten Blum X-Patchwork-Id: 13942323 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAFA481727 for ; Thu, 16 Jan 2025 21:20:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737062456; cv=none; b=pkkTphb6S0TV78VY2aqZeYsTw5jo1IAZBkKZ3yNy+xNK8o5EU2F0AH+CUTuGk98Yh1H9KNHJ38mvDo0FS7WRAOD8HFjDitBs+yJXzgws0UvLxdCOfSs7rKuvTF7N+N0ZX7/PasaB7/vtd3ZUInjxjpap8gIUNmZaq8NIowzyLMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737062456; c=relaxed/simple; bh=MjLB8cGPzHtA3JKM+gbMrilrolSPKow+VzxyU+G4jko=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uUYXNT2h/Z9dTPf+VXpXozxbCAqZ6sX67E5xgN55D6xPPDZeT4MZAgoegBNGxXxu9RWNPYGbQAC0Alen6PziEDIKmFb6srF2EmJg5KK17mSTzQVRTmvSXSq27DAW28JnSCg6iR+zVdcOSPRdSn8EkwKpYrB0FyoF6cHAwYhbCtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PnHTtpth; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PnHTtpth" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1737062446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=2Syu9PoY8qUbezBkyLynlw3MObrHBcpVaz9Wa9zY10Q=; b=PnHTtpthJIwc1z9MljiV1oUxKhACxW70+pfWhahgBpTN8qBaJy4W7uXZHIPbNZSTlxbJko gB/A2PGO6mxxtviZ4B72ZbiquVCNSF4c1+LoXobKOEOdGTPAYPbNbZs+D9GbYQW7gz81Ww +YTqKbFAAufys3rJac5s7S2yF0DcNaw= From: Thorsten Blum To: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hardening@vger.kernel.org, Roman Kisel , Thorsten Blum , linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] hv_netvsc: Replace one-element array with flexible array member Date: Thu, 16 Jan 2025 22:19:32 +0100 Message-ID: <20250116211932.139564-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Replace the deprecated one-element array with a modern flexible array member in the struct nvsp_1_message_send_receive_buffer_complete. Use struct_size_t(,,1) instead of sizeof() to maintain the same size. Compile-tested only. Link: https://github.com/KSPP/linux/issues/79 Signed-off-by: Thorsten Blum Tested-by: Roman Kisel Reviewed-by: Roman Kisel --- Changes in v2: - Replace sizeof() with struct_size_t(,,1) to maintain the same size after feedback from Roman Kisel (thanks!) - Link to v1: https://lore.kernel.org/r/20250116201635.47870-2-thorsten.blum@linux.dev/ --- drivers/net/hyperv/hyperv_net.h | 2 +- drivers/net/hyperv/netvsc.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h index e690b95b1bbb..234db693cefa 100644 --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -464,7 +464,7 @@ struct nvsp_1_message_send_receive_buffer_complete { * LargeOffset SmallOffset */ - struct nvsp_1_receive_buffer_section sections[1]; + struct nvsp_1_receive_buffer_section sections[]; } __packed; /* diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 9afb08dbc350..d6f5b9ea3109 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -866,7 +866,8 @@ static void netvsc_send_completion(struct net_device *ndev, case NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE: if (msglen < sizeof(struct nvsp_message_header) + - sizeof(struct nvsp_1_message_send_receive_buffer_complete)) { + struct_size_t(struct nvsp_1_message_send_receive_buffer_complete, + sections, 1)) { netdev_err(ndev, "nvsp_msg1 length too small: %u\n", msglen); return;