crypto: ccp - Silence may-be-uninitialized warning in sev_ioctl_do_pdh_export
Subsystems (3)
Herbert Xu
maintainerPATCH 1/1 crypto: ccp - Silence may-be-uninitialized warning in sev_ioctl_do_pdh_export
The recent reordering of code in sev_ioctl_do_pdh_export triggered a false-positive may-be-uninitialized warning from gcc:
In file included from ../include/linux/sched/task.h:13,
from ../include/linux/sched/signal.h:9,
from ../include/linux/rcuwait.h:6,
from ../include/linux/percpu-rwsem.h:7,
from ../include/linux/fs.h:34,
from ../include/linux/compat.h:17,
from ../arch/x86/include/asm/ia32.h:7,
from ../arch/x86/include/asm/elf.h:10,
from ../include/linux/elf.h:6,
from ../include/linux/module.h:19,
from ../drivers/crypto/ccp/sev-dev.c:11:In function ‘copy_to_user’,
inlined from ‘sev_ioctl_do_pdh_export’ at ../drivers/crypto/ccp/sev-dev.c:2036:7,
inlined from ‘sev_ioctl’ at ../drivers/crypto/ccp/sev-dev.c:2249:9:../include/linux/uaccess.h:225:16: warning: ‘input_cert_chain_address’ may be used uninitialized [-Wmaybe-uninitialized]
225 | return _copy_to_user(to, from, n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
../drivers/crypto/ccp/sev-dev.c: In function ‘sev_ioctl’:
../drivers/crypto/ccp/sev-dev.c:1961:22: note: ‘input_cert_chain_address’ was declared here
1961 | void __user *input_cert_chain_address;
| ^~~~~~~~~~~~~~~~~~~~~~~~Silence it by moving the initialisation of the variables in question prior to the NULL check.
drivers/crypto/ccp/sev-dev.c +3 -3
@@ -1968,15 +1968,15 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)memset (&data,0 ,sizeof (data)); + input_pdh_cert_address = (void __user *)input.pdh_cert_address; + input_cert_chain_address = (void __user *)input.cert_chain_address; +/* Userspace wants to query the certificate length. */ if (!input.pdh_cert_address || !input.pdh_cert_len || !input.cert_chain_address) goto cmd; - input_pdh_cert_address = (void __user *)input.pdh_cert_address; - input_cert_chain_address = (void __user *)input.cert_chain_address; -/* Allocate a physically contiguous buffer to store the PDH blob. */ if (input.pdh_cert_len >SEV_FW_BLOB_MAX_SIZE )return -EFAULT ;
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 25 lines · Herbert Xu
The recent reordering of code in
sev_ioctl_do_pdh_exporttriggered a false-positive may-be-uninitialized warning from gcc:In file included from
../include/linux/sched/task.h:13,from ../include/linux/sched/signal.h:9, from ../include/linux/rcuwait.h:6, from ../include/linux/percpu-rwsem.h:7, from ../include/linux/fs.h:34, from ../include/linux/compat.h:17, from ../arch/x86/include/asm/ia32.h:7, from ../arch/x86/include/asm/elf.h:10, from ../include/linux/elf.h:6, from ../include/linux/module.h:19, from ../drivers/crypto/ccp/sev-dev.c:11:In function ‘copy_to_user’,
inlined from ‘sev_ioctl_do_pdh_export’ at../drivers/crypto/ccp/sev-dev.c:2036:7,
inlined from ‘sev_ioctl’ at../drivers/crypto/ccp/sev-dev.c:2249:9:../include/linux/uaccess.h:225:16: warning: ‘input_cert_chain_address’ may be used uninitialized [-Wmaybe-uninitialized]225 | return _copy_to_user(to, from, n); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ ../drivers/crypto/ccp/sev-dev.c: In function ‘sev_ioctl’: ../drivers/crypto/ccp/sev-dev.c:1961:22: note: ‘input_cert_chain_address’ was declared here 1961 | void __user *input_cert_chain_address; | ^~~~~~~~~~~~~~~~~~~~~~~~
Quoted 4 lines
Silence it by moving the initialisation of the variables in question prior to the NULL check.
Signed-off-by Herbert Xu <[email protected]>
Quoted 24 lines
drivers/crypto/ccp/sev-dev.c +3
-3@@ -1968,15 +1968,15 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)memset (&data,0 ,sizeof (data)); + input_pdh_cert_address = (void __user *)input.pdh_cert_address; + input_cert_chain_address = (void __user *)input.cert_chain_address; +/* Userspace wants to query the certificate length. */ if (!input.pdh_cert_address || !input.pdh_cert_len || !input.cert_chain_address) goto cmd; - input_pdh_cert_address = (void __user *)input.pdh_cert_address; - input_cert_chain_address = (void __user *)input.cert_chain_address; -/* Allocate a physically contiguous buffer to store the PDH blob. */ if (input.pdh_cert_len >SEV_FW_BLOB_MAX_SIZE )return -EFAULT ;