opnsense-src/sys/contrib/openzfs
Dimitry Andric b426202aaf Fix gcc uninitialized warning in FreeBSD zio_crypt.c
With gcc we are seeing the following -Werror warning:

    In file included from /workspace/src/sys/contrib/openzfs/include/os/freebsd/spl/sys/sunddi.h:28,
                     from /workspace/src/sys/contrib/openzfs/include/sys/zfs_context.h:69:
    In function 'zfs_uio_init',
        inlined from 'zio_do_crypt_data' at /workspace/src/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c:1690:2:
    /workspace/src/sys/contrib/openzfs/include/os/freebsd/spl/sys/uio.h:102:45: error: 'puio_s.uio_offset' is used uninitialized [-Werror=uninitialized]
      102 |                 zfs_uio_soffset(uio) = uio_s->uio_offset;
          |                                        ~~~~~^~~~~~~~~~~~
    /workspace/src/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c: In function 'zio_do_crypt_data':
    /workspace/src/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c:1683:20: note: 'puio_s' declared here
     1683 |         struct uio puio_s, cuio_s;
          |                    ^~~~~~
    In function 'zfs_uio_init',
        inlined from 'zio_do_crypt_data' at /workspace/src/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c:1691:2:
    /workspace/src/sys/contrib/openzfs/include/os/freebsd/spl/sys/uio.h:102:45: error: 'cuio_s.uio_offset' is used uninitialized [-Werror=uninitialized]
      102 |                 zfs_uio_soffset(uio) = uio_s->uio_offset;
          |                                        ~~~~~^~~~~~~~~~~~
    /workspace/src/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c: In function 'zio_do_crypt_data':
    /workspace/src/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c:1683:28: note: 'cuio_s' declared here
     1683 |         struct uio puio_s, cuio_s;
          |                            ^~~~~~

Indeed, `zfs_uio_init()` does:

    static __inline void
    zfs_uio_init(zfs_uio_t *uio, struct uio *uio_s)
    {
            memset(uio, 0, sizeof (zfs_uio_t));
            if (uio_s != NULL) {
                    GET_UIO_STRUCT(uio) = uio_s;
                    zfs_uio_soffset(uio) = uio_s->uio_offset;
            }
    }

while the code in `zio_crypt.c` has:

    /*
     * Primary encryption / decryption entrypoint for zio data.
     */
    int
    zio_do_crypt_data(boolean_t encrypt, zio_crypt_key_t *key,
        dmu_object_type_t ot, boolean_t byteswap, uint8_t *salt, uint8_t *iv,
        uint8_t *mac, uint_t datalen, uint8_t *plainbuf, uint8_t *cipherbuf,
        boolean_t *no_crypt)
    {
            int ret;
            boolean_t locked = B_FALSE;
            uint64_t crypt = key->zk_crypt;
            uint_t keydata_len = zio_crypt_table[crypt].ci_keylen;
            uint_t enc_len, auth_len;
            zfs_uio_t puio, cuio;
            struct uio puio_s, cuio_s;
            uint8_t enc_keydata[MASTER_KEY_MAX_LEN];
            crypto_key_t tmp_ckey, *ckey = NULL;
            freebsd_crypt_session_t *tmpl = NULL;
            uint8_t *authbuf = NULL;

            zfs_uio_init(&puio, &puio_s);
            zfs_uio_init(&cuio, &cuio_s);
            memset(GET_UIO_STRUCT(&puio), 0, sizeof (struct uio));
            memset(GET_UIO_STRUCT(&cuio), 0, sizeof (struct uio));

So between the declaration of `puio_s` and `cuio_s`, there is no
initialization of these variables before `zfs_uio_init()` gets called.

Similar to the Linux variant of zio_crypt.c, I think it would be better
to memset the structs `puio_s` and `cuis_s` _before_ calling
`zfs_uio_init()`.

Reviewed by:    tsoome
MFC after:      3 days
Differential Revision: https://reviews.freebsd.org/D47281

(cherry picked from commit 3ceba58a75)
2024-10-29 22:49:16 +01:00
..
.github zfs: merge openzfs/zfs@c883088df (zfs-2.2-release) into stable/14 2024-02-23 19:37:36 +01:00
cmd zdb: Fix printf formatting of a uint64_t 2024-08-15 16:44:48 +02:00
config zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-09-09 22:41:36 +02:00
contrib zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-09-09 22:41:36 +02:00
etc zfs: merge openzfs/zfs@256659204 (zfs-2.2-release) into stable/14 2024-05-03 23:52:01 +02:00
include zfs: cherry-pick change from openzfs 2024-09-20 18:03:36 +08:00
lib zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-08-13 09:52:28 +02:00
man zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-09-09 22:41:36 +02:00
module Fix gcc uninitialized warning in FreeBSD zio_crypt.c 2024-10-29 22:49:16 +01:00
rpm zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-09-09 22:41:36 +02:00
scripts zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-08-13 09:52:28 +02:00
tests zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-09-09 22:41:36 +02:00
udev zfs: merge openzfs/zfs@256659204 (zfs-2.2-release) into stable/14 2024-05-03 23:52:01 +02:00
.cirrus.yml zfs: merge openzfs/zfs@2407f30bd (zfs-2.2-release) into stable/14 2023-10-08 10:14:19 +02:00
.editorconfig
.gitignore zfs: merge openzfs/zfs@55dd24c4c (zfs-2.2-release) into stable/14 2023-11-22 12:43:59 +01:00
.mailmap zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-08-13 09:52:28 +02:00
AUTHORS zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-08-13 09:52:28 +02:00
autogen.sh zfs: merge openzfs/zfs@59493b63c (master) 2022-12-07 14:10:46 +01:00
CODE_OF_CONDUCT.md zfs: merge openzfs/zfs@9cd71c860 (master) 2023-01-25 19:50:29 +01:00
configure.ac zfs: merge openzfs/zfs@55dd24c4c (zfs-2.2-release) into stable/14 2023-11-22 12:43:59 +01:00
copy-builtin
COPYRIGHT
LICENSE
Makefile.am zfs: merge openzfs/zfs@2163cde45 2022-11-16 21:27:42 +01:00
META zfs: merge openzfs/zfs@33174af15 (zfs-2.2-release) into stable/14 2024-09-09 22:41:36 +02:00
NEWS
NOTICE
README.md zfs: merge openzfs/zfs@494aaaed8 (zfs-2.2-release) into stable/14 2023-12-01 12:31:24 +01:00
RELEASES.md
TEST
zfs.release.in

img

OpenZFS is an advanced file system and volume manager which was originally developed for Solaris and is now maintained by the OpenZFS community. This repository contains the code for running OpenZFS on Linux and FreeBSD.

codecov coverity

Official Resources

Installation

Full documentation for installing OpenZFS on your favorite operating system can be found at the Getting Started Page.

Contribute & Develop

We have a separate document with contribution guidelines.

We have a Code of Conduct.

Release

OpenZFS is released under a CDDL license. For more details see the NOTICE, LICENSE and COPYRIGHT files; UCRL-CODE-235197

Supported Kernels

  • The META file contains the officially recognized supported Linux kernel versions.
  • Supported FreeBSD versions are any supported branches and releases starting from 12.4-RELEASE.