drivers/platform/x86/think-lmi.c:758:14: warning: '%s' directive argument is null

From: kernel test robot
Date: Sat Jan 06 2024 - 15:08:33 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 95c8a35f1c017327eab3b6a2ff5c04255737c856
commit: b49f72e7f96d4ed147447428f2ae5b4cea598ca7 platform/x86: think-lmi: Certificate authentication support
date: 1 year, 10 months ago
config: x86_64-randconfig-004-20240105 (https://download.01.org/0day-ci/archive/20240107/202401070354.MZWdBoO9-lkp@xxxxxxxxx/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240107/202401070354.MZWdBoO9-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401070354.MZWdBoO9-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

drivers/platform/x86/think-lmi.c: In function 'certificate_store':
>> drivers/platform/x86/think-lmi.c:758:14: warning: '%s' directive argument is null [-Wformat-overflow=]
758 | auth_str = kasprintf(GFP_KERNEL, "%s,%s",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
759 | dmi_get_system_info(DMI_PRODUCT_SERIAL),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
760 | setting->signature);
| ~~~~~~~~~~~~~~~~~~~


vim +758 drivers/platform/x86/think-lmi.c

727
728 static ssize_t certificate_store(struct kobject *kobj,
729 struct kobj_attribute *attr,
730 const char *buf, size_t count)
731 {
732 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
733 char *auth_str, *new_cert;
734 char *guid;
735 int ret;
736
737 if (!capable(CAP_SYS_ADMIN))
738 return -EPERM;
739
740 if (!tlmi_priv.certificate_support)
741 return -EOPNOTSUPP;
742
743 new_cert = kstrdup(buf, GFP_KERNEL);
744 if (!new_cert)
745 return -ENOMEM;
746 /* Strip out CR if one is present */
747 strip_cr(new_cert);
748
749 /* If empty then clear installed certificate */
750 if (new_cert[0] == '\0') { /* Clear installed certificate */
751 kfree(new_cert);
752
753 /* Check that signature is set */
754 if (!setting->signature || !setting->signature[0])
755 return -EACCES;
756
757 /* Format: 'serial#, signature' */
> 758 auth_str = kasprintf(GFP_KERNEL, "%s,%s",
759 dmi_get_system_info(DMI_PRODUCT_SERIAL),
760 setting->signature);
761 if (!auth_str)
762 return -ENOMEM;
763
764 ret = tlmi_simple_call(LENOVO_CLEAR_BIOS_CERT_GUID, auth_str);
765 kfree(auth_str);
766 if (ret)
767 return ret;
768
769 kfree(setting->certificate);
770 setting->certificate = NULL;
771 return count;
772 }
773
774 if (setting->cert_installed) {
775 /* Certificate is installed so this is an update */
776 if (!setting->signature || !setting->signature[0]) {
777 kfree(new_cert);
778 return -EACCES;
779 }
780 guid = LENOVO_UPDATE_BIOS_CERT_GUID;
781 /* Format: 'Certificate,Signature' */
782 auth_str = kasprintf(GFP_KERNEL, "%s,%s",
783 new_cert, setting->signature);
784 } else {
785 /* This is a fresh install */
786 if (!setting->valid || !setting->password[0]) {
787 kfree(new_cert);
788 return -EACCES;
789 }
790 guid = LENOVO_SET_BIOS_CERT_GUID;
791 /* Format: 'Certificate,Admin-password' */
792 auth_str = kasprintf(GFP_KERNEL, "%s,%s",
793 new_cert, setting->password);
794 }
795 if (!auth_str) {
796 kfree(new_cert);
797 return -ENOMEM;
798 }
799
800 ret = tlmi_simple_call(guid, auth_str);
801 kfree(auth_str);
802 if (ret) {
803 kfree(new_cert);
804 return ret;
805 }
806
807 kfree(setting->certificate);
808 setting->certificate = new_cert;
809 return count;
810 }
811

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki