Linux Hardening
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Kalle Valo <kvalo@kernel.org>, Jeff Johnson <quic_jjohnson@quicinc.com>
Cc: ath10k@lists.infradead.org, linux-wireless@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-hardening@vger.kernel.org
Subject: [RFC - is this a bug?] wifi: ath10k: Asking for some light on this, please :)
Date: Tue, 24 Oct 2023 13:50:34 -0600	[thread overview]
Message-ID: <626ae2e7-66f8-423b-b17f-e75c1a6d29b3@embeddedor.com> (raw)

Hi all,

While working on tranforming one-element array `peer_chan_list` in
`struct wmi_tdls_peer_capabilities` into a flex-array member

7187 struct wmi_tdls_peer_capabilities {
...
7199         struct wmi_channel peer_chan_list[1];
7200 } __packed;

the following line caught my attention:

./drivers/net/wireless/ath/ath10k/wmi.c:
8920         memset(skb->data, 0, sizeof(*cmd));

Notice that before the flex-array transformation, we are zeroing 128
bytes in `skb->data` because `sizeof(*cmd) == 128`, see below:

$ pahole -C wmi_10_4_tdls_peer_update_cmd drivers/net/wireless/ath/ath10k/wmi.o
struct wmi_10_4_tdls_peer_update_cmd {
	__le32                     vdev_id;              /*     0     4 */
	struct wmi_mac_addr        peer_macaddr;         /*     4     8 */
	__le32                     peer_state;           /*    12     4 */
	__le32                     reserved[4];          /*    16    16 */
	struct wmi_tdls_peer_capabilities peer_capab;    /*    32    96 */

	/* size: 128, cachelines: 2, members: 5 */
};

So, after the flex-array transformation (and the necessary adjustments
to a few other lines of code) we would be zeroing 104 bytes in
`skb->data` because `sizeof(*cmd) == 104`, see below:

$ pahole -C wmi_10_4_tdls_peer_update_cmd drivers/net/wireless/ath/ath10k/wmi.o
struct wmi_10_4_tdls_peer_update_cmd {
	__le32                     vdev_id;              /*     0     4 */
	struct wmi_mac_addr        peer_macaddr;         /*     4     8 */
	__le32                     peer_state;           /*    12     4 */
	__le32                     reserved[4];          /*    16    16 */
	struct wmi_tdls_peer_capabilities peer_capab;    /*    32    72 */

	/* size: 104, cachelines: 2, members: 5 */
	/* last cacheline: 40 bytes */
};

This difference arises because the size of the element type for the
`peer_chan_list` array, which is `sizeof(struct wmi_channel) == 24 `

$ pahole -C wmi_channel drivers/net/wireless/ath/ath10k/wmi.o
struct wmi_channel {
	__le32                     mhz;                  /*     0     4 */
	__le32                     band_center_freq1;    /*     4     4 */
	__le32                     band_center_freq2;    /*     8     4 */

[..]
                                                /*    20     4 */

	/* size: 24, cachelines: 1, members: 6 */
	/* last cacheline: 24 bytes */
};

is included in `sizeof(*cmd)` before the transformation.

So, my question is: do we really need to zero out those extra 24 bytes in
`skb->data`? or is it rather a bug in the original code?

Thanks!
--
Gustavo


             reply	other threads:[~2023-10-24 19:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-24 19:50 Gustavo A. R. Silva [this message]
2023-10-24 20:11 ` [RFC - is this a bug?] wifi: ath10k: Asking for some light on this, please :) Johannes Berg
2023-10-24 20:41   ` Gustavo A. R. Silva
2023-10-24 20:49     ` Johannes Berg
2023-10-25  2:37       ` Gustavo A. R. Silva
2023-10-25 15:52         ` Jeff Johnson
2023-12-12 23:26           ` Jeff Johnson
2023-10-25  1:06 ` Gustavo A. R. Silva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=626ae2e7-66f8-423b-b17f-e75c1a6d29b3@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=ath10k@lists.infradead.org \
    --cc=gustavoars@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=quic_jjohnson@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox