OSDN Git Service

Bluetooth: mgmt: Pessimize compile-time bounds-check
authorKees Cook <keescook@chromium.org>
Wed, 18 Aug 2021 04:39:12 +0000 (21:39 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 19 Aug 2021 14:51:53 +0000 (16:51 +0200)
commita31e5a4158d03595ca4258b94397d4097be0ebe4
tree3f1eec94e13eb8345d9a2533c86420ad2f1dacf5
parentecb71f2566673553bc067e5b0036756871d0b9d3
Bluetooth: mgmt: Pessimize compile-time bounds-check

After gaining __alloc_size hints, GCC thinks it can reach a memcpy()
with eir_len == 0 (since it can't see into the rewrite of status).
Instead, check eir_len == 0, avoiding this future warning:

In function 'eir_append_data',
    inlined from 'read_local_oob_ext_data_complete' at net/bluetooth/mgmt.c:7210:12:
./include/linux/fortify-string.h:54:29: warning: '__builtin_memcpy' offset 5 is out of the bounds [0, 3] [-Warray-bounds]
...
net/bluetooth/hci_request.h:133:2: note: in expansion of macro 'memcpy'
  133 |  memcpy(&eir[eir_len], data, data_len);
      |  ^~~~~~

Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: linux-bluetooth@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/mgmt.c