Linux Hardening
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Kees Cook <keescook@chromium.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-kernel@vger.kernel.org, Kalle Valo <kvalo@codeaurora.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH v3 2/2] wl3501_cs: Fix out-of-bounds warnings in wl3501_mgmt_join
Date: Thu, 15 Apr 2021 15:59:20 -0500	[thread overview]
Message-ID: <6a3434e0-5b8e-39d2-c69b-5e0545318192@embeddedor.com> (raw)
In-Reply-To: <202104151257.DC4DA20@keescook>



On 4/15/21 14:58, Kees Cook wrote:
> On Wed, Apr 14, 2021 at 06:45:15PM -0500, Gustavo A. R. Silva wrote:
>> Fix the following out-of-bounds warnings by adding a new structure
>> wl3501_req instead of duplicating the same members in structure
>> wl3501_join_req and wl3501_scan_confirm:
>>
>> arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [39, 108] from the object at 'sig' is out of the bounds of referenced subobject 'beacon_period' with type 'short unsigned int' at offset 36 [-Warray-bounds]
>> arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [25, 95] from the object at 'sig' is out of the bounds of referenced subobject 'beacon_period' with type 'short unsigned int' at offset 22 [-Warray-bounds]
>>
>> Refactor the code, accordingly:
>>
>> $ pahole -C wl3501_req drivers/net/wireless/wl3501_cs.o
>> struct wl3501_req {
>>         u16                        beacon_period;        /*     0     2 */
>>         u16                        dtim_period;          /*     2     2 */
>>         u16                        cap_info;             /*     4     2 */
>>         u8                         bss_type;             /*     6     1 */
>>         u8                         bssid[6];             /*     7     6 */
>>         struct iw_mgmt_essid_pset  ssid;                 /*    13    34 */
>>         struct iw_mgmt_ds_pset     ds_pset;              /*    47     3 */
>>         struct iw_mgmt_cf_pset     cf_pset;              /*    50     8 */
>>         struct iw_mgmt_ibss_pset   ibss_pset;            /*    58     4 */
>>         struct iw_mgmt_data_rset   bss_basic_rset;       /*    62    10 */
>>
>>         /* size: 72, cachelines: 2, members: 10 */
>>         /* last cacheline: 8 bytes */
>> };
>>
>> $ pahole -C wl3501_join_req drivers/net/wireless/wl3501_cs.o
>> struct wl3501_join_req {
>>         u16                        next_blk;             /*     0     2 */
>>         u8                         sig_id;               /*     2     1 */
>>         u8                         reserved;             /*     3     1 */
>>         struct iw_mgmt_data_rset   operational_rset;     /*     4    10 */
>>         u16                        reserved2;            /*    14     2 */
>>         u16                        timeout;              /*    16     2 */
>>         u16                        probe_delay;          /*    18     2 */
>>         u8                         timestamp[8];         /*    20     8 */
>>         u8                         local_time[8];        /*    28     8 */
>>         struct wl3501_req          req;                  /*    36    72 */
>>
>>         /* size: 108, cachelines: 2, members: 10 */
>>         /* last cacheline: 44 bytes */
>> };
>>
>> $ pahole -C wl3501_scan_confirm drivers/net/wireless/wl3501_cs.o
>> struct wl3501_scan_confirm {
>>         u16                        next_blk;             /*     0     2 */
>>         u8                         sig_id;               /*     2     1 */
>>         u8                         reserved;             /*     3     1 */
>>         u16                        status;               /*     4     2 */
>>         char                       timestamp[8];         /*     6     8 */
>>         char                       localtime[8];         /*    14     8 */
>>         struct wl3501_req          req;                  /*    22    72 */
>>         /* --- cacheline 1 boundary (64 bytes) was 30 bytes ago --- */
>>         u8                         rssi;                 /*    94     1 */
>>
>>         /* size: 96, cachelines: 2, members: 8 */
>>         /* padding: 1 */
>>         /* last cacheline: 32 bytes */
>> };
>>
>> The problem is that the original code is trying to copy data into a
>> bunch of struct members adjacent to each other in a single call to
>> memcpy(). Now that a new struct wl3501_req enclosing all those adjacent
>> members is introduced, memcpy() doesn't overrun the length of
>> &sig.beacon_period and &this->bss_set[i].beacon_period, because the
>> address of the new struct object _req_ is used as the destination,
>> instead.
>>
>> This helps with the ongoing efforts to globally enable -Warray-bounds
>> and get us closer to being able to tighten the FORTIFY_SOURCE routines
>> on memcpy().
>>
>> Link: https://github.com/KSPP/linux/issues/109
>> Reported-by: kernel test robot <lkp@intel.com>
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> 
> Awesome! Thank you for this solution.
> 
> Reviewed-by: Kees Cook <keescook@chromium.org>


Thanks, Kees!

--
Gustavo

      reply	other threads:[~2021-04-15 20:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14 23:40 [PATCH v3 0/2] Fix out-of-bounds warnings Gustavo A. R. Silva
2021-04-14 23:43 ` [PATCH v3 1/2] wl3501_cs: Fix out-of-bounds warnings in wl3501_send_pkt Gustavo A. R. Silva
2021-04-22 14:39   ` Kalle Valo
     [not found]   ` <20210422143910.C8B5CC4338A@smtp.codeaurora.org>
2021-04-22 18:30     ` Gustavo A. R. Silva
2021-04-14 23:45 ` [PATCH v3 2/2] wl3501_cs: Fix out-of-bounds warnings in wl3501_mgmt_join Gustavo A. R. Silva
2021-04-15 19:58   ` Kees Cook
2021-04-15 20:59     ` Gustavo A. R. Silva [this message]

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=6a3434e0-5b8e-39d2-c69b-5e0545318192@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=davem@davemloft.net \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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