From cc7ea4f7012d9547d01f6722e64e99b38a07806d Mon Sep 17 00:00:00 2001 From: Pranav Mahesh Phansalkar Date: Mon, 29 Jan 2024 14:15:52 +0530 Subject: [PATCH] net: qrtr: Add condition to check data length while logging For non QMI packets having data length less than eight bytes, skb_copy_bits fails to copy packet data to log buffer. So, Add condition to check data length. If the data length is less than eight bytes, send actual data length to skb_copy_bits. Change-Id: I2181016f224952d214a8f39fb06b47ace01dc51a Signed-off-by: Pranav Mahesh Phansalkar --- net/qrtr/af_qrtr.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index a3e3a0b9b9e4..487ab6c360f6 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -3,6 +3,7 @@ * Copyright (c) 2015, Sony Mobile Communications Inc. * Copyright (c) 2013, The Linux Foundation. All rights reserved. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. */ #include #include @@ -246,7 +247,8 @@ static void qrtr_log_tx_msg(struct qrtr_node *node, struct qrtr_hdr_v1 *hdr, type = le32_to_cpu(hdr->type); if (type == QRTR_TYPE_DATA) { - skb_copy_bits(skb, QRTR_HDR_MAX_SIZE, &pl_buf, sizeof(pl_buf)); + skb_copy_bits(skb, sizeof(*hdr), &pl_buf, hdr->size > sizeof(pl_buf) ? + sizeof(pl_buf) : hdr->size); QRTR_INFO(node->ilc, "TX DATA: Len:0x%x CF:0x%x src[0x%x:0x%x] dst[0x%x:0x%x] [%08x %08x] [%s]\n", hdr->size, hdr->confirm_rx, @@ -294,7 +296,8 @@ static void qrtr_log_rx_msg(struct qrtr_node *node, struct sk_buff *skb) cb = (struct qrtr_cb *)skb->cb; if (cb->type == QRTR_TYPE_DATA) { - skb_copy_bits(skb, 0, &pl_buf, sizeof(pl_buf)); + skb_copy_bits(skb, 0, &pl_buf, skb->len > sizeof(pl_buf) ? + sizeof(pl_buf) : skb->len); QRTR_INFO(node->ilc, "RX DATA: Len:0x%x CF:0x%x src[0x%x:0x%x] dst[0x%x:0x%x] [%08x %08x]\n", skb->len, cb->confirm_rx, cb->src_node, cb->src_port,