Bug #14395
closedzfs: array subscript is partly outside array bounds
100%
Description
Build errors with gcc 11:
In file included from ../../common/fs/zfs/sys/zfs_context.h:58, from ../../common/fs/zfs/sys/dmu.h:48, from ../../common/fs/zfs/sys/zio_crypt.h:23, from ../../common/fs/zfs/zio_crypt.c:20: ../../common/fs/zfs/zio_crypt.c: In function 'zio_crypt_do_dnode_hmac_updates': ../../common/fs/zfs/zio_crypt.c:1073:54: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1073 | adnp->dn_datablkszsec = BSWAP_16(adnp->dn_datablkszsec); | ^~ ../../common/sys/byteorder.h:115:31: note: in definition of macro 'BSWAP_16' 115 | #define BSWAP_16(x) htons(x) | ^ ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ ../../common/fs/zfs/zio_crypt.c:1073:21: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1073 | adnp->dn_datablkszsec = BSWAP_16(adnp->dn_datablkszsec); | ^~ ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ In file included from ../../common/fs/zfs/sys/zfs_context.h:58, from ../../common/fs/zfs/sys/dmu.h:48, from ../../common/fs/zfs/sys/zio_crypt.h:23, from ../../common/fs/zfs/zio_crypt.c:20: ../../common/fs/zfs/zio_crypt.c:1074:50: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1074 | adnp->dn_bonuslen = BSWAP_16(adnp->dn_bonuslen); | ^~ ../../common/sys/byteorder.h:115:31: note: in definition of macro 'BSWAP_16' 115 | #define BSWAP_16(x) htons(x) | ^ ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ ../../common/fs/zfs/zio_crypt.c:1074:21: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1074 | adnp->dn_bonuslen = BSWAP_16(adnp->dn_bonuslen); | ^~ ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ In file included from ../../common/fs/zfs/sys/zfs_context.h:58, from ../../common/fs/zfs/sys/dmu.h:48, from ../../common/fs/zfs/sys/zio_crypt.h:23, from ../../common/fs/zfs/zio_crypt.c:20: ../../common/fs/zfs/zio_crypt.c:1075:50: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1075 | adnp->dn_maxblkid = BSWAP_64(adnp->dn_maxblkid); | ^~ ../../common/sys/byteorder.h:130:32: note: in definition of macro 'BSWAP_64' 130 | #define BSWAP_64(x) htonll(x) | ^ ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ ../../common/fs/zfs/zio_crypt.c:1075:21: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1075 | adnp->dn_maxblkid = BSWAP_64(adnp->dn_maxblkid); | ^~ ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ In file included from ../../common/fs/zfs/sys/zfs_context.h:58, from ../../common/fs/zfs/sys/dmu.h:48, from ../../common/fs/zfs/sys/zio_crypt.h:23, from ../../common/fs/zfs/zio_crypt.c:20: ../../common/fs/zfs/zio_crypt.c:1076:46: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1076 | adnp->dn_used = BSWAP_64(adnp->dn_used); | ^~ ../../common/sys/byteorder.h:130:32: note: in definition of macro 'BSWAP_64' 130 | #define BSWAP_64(x) htonll(x) | ^ ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ ../../common/fs/zfs/zio_crypt.c:1078:24: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1078 | adnp->dn_flags &= DNODE_CRYPT_PORTABLE_FLAGS_MASK; | ^~ ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ ../../common/fs/zfs/zio_crypt.c:1078:24: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1078 | adnp->dn_flags &= DNODE_CRYPT_PORTABLE_FLAGS_MASK; ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ ../../common/fs/zfs/zio_crypt.c:1079:13: error: array subscript 'dnode_phys_t {aka struct dnode_phys}[0]' is partly outside array bounds of 'uint8_t[64]' {aka 'unsigned char[64]'} [-Werror=array-bounds] 1079 | adnp->dn_used = 0; | ^~ ../../common/fs/zfs/zio_crypt.c:1064:17: note: while referencing 'tmp_dncore' 1064 | uint8_t tmp_dncore[offsetof(dnode_phys_t, dn_blkptr)]; | ^~~~~~~~~~ cc1: all warnings being treated as errors
The problem is similar as with few previous issues: we do have large structure, but need only part of its content, so the code does use smaller memory area for this struct. Compiler does not like it.
I really do not want to silence this one, but the problem is, the solution to use full 'struct dnode_phys' may hurt linux, which is known to have problems with large stack allocations.
Actualy... linux has similar fix already in place.
Testing done:
tsoome@test:~$ env DISKS="c3t1d0 c3t2d0 c3t3d0" /opt/zfs-tests/bin/zfstest -c /opt/zfs-tests/runfiles/tsoome.run
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key (run as root) [00:03] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_child (run as root) [00:03] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_format (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_inherit (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_load (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_location (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_pbkdf2iters (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_clones (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_change-key/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_clone/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_encrypted (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_clone/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_create/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_encrypted (run as root) [00:05] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_crypt_combos (run as root) [00:06] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_create/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_diff/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_encrypted (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_diff/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_load-key/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key (run as root) [00:03] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_all (run as root) [00:04] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_file (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_location (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_noop (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_recursive (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_load-key/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_mount/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_encrypted (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_mount/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_promote/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_encryptionroot (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_promote/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_receive/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_encrypted (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_to_encrypted (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_incremental (run as root) [00:03] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_receive/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_rename/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_encrypted_child (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_to_encrypted (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_rename/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_send/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_send/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_set/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_keylocation (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_set/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_unload-key/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_all (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_recursive (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zfs_unload-key/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_create/setup (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_encrypted (run as root) [00:03] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_crypt_combos (run as root) [00:12] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_create/cleanup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_import/setup (run as root) [00:05] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_encrypted (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_encrypted_load (run as root) [00:02] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_import/cleanup (run as root) [00:03] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_scrub/setup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_encrypted_unloaded (run as root) [00:03] [PASS]
Test: /opt/zfs-tests/tests/functional/cli_root/zpool_scrub/cleanup (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/rsend/setup (run as root) [00:01] [PASS]
Test: /opt/zfs-tests/tests/functional/rsend/send-c_recv_dedup (run as root) [00:00] [PASS]
Test: /opt/zfs-tests/tests/functional/rsend/send_encrypted_files (run as root) [00:24] [PASS]
Test: /opt/zfs-tests/tests/functional/rsend/send_encrypted_hierarchy (run as root) [00:04] [PASS]
Test: /opt/zfs-tests/tests/functional/rsend/send_encrypted_props (run as root) [00:07] [PASS]
Test: /opt/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files (run as root) [00:03] [PASS]
Test: /opt/zfs-tests/tests/functional/rsend/send_realloc_encrypted_files (run as root) [02:10] [PASS]
Test: /opt/zfs-tests/tests/functional/rsend/send-wDR_encrypted_zvol (run as root) [00:10] [PASS]
Test: /opt/zfs-tests/tests/functional/rsend/cleanup (run as root) [00:00] [PASS]
Results Summary
PASS 75
Running Time: 00:05:06
Percent passed: 100.0%
Log directory: /var/tmp/test_results/20220131T231359
tsoome@test:~$
Updated by Electric Monk over 1 year ago
- Status changed from In Progress to Closed
- % Done changed from 90 to 100
git commit 0d48c3fdfa345b461d90342d8a96a773f386cb76
commit 0d48c3fdfa345b461d90342d8a96a773f386cb76 Author: Toomas Soome <tsoome@me.com> Date: 2022-01-31T21:53:42.000Z 14395 zfs: array subscript is partly outside array bounds Reviewed by: C Fraire <cfraire@me.com> Reviewed by: Garrett D'Amore <garrett@damore.org> Approved by: Dan McDonald <danmcd@joyent.com>