net/sunrpc/auth_gss/gss_krb5_mech.c:181 gss_krb5_prepare_enctype_priority_list() warn: unsigned 'i' is never less than zero.

From: kernel test robot
Date: Fri Jun 30 2023 - 10:51:39 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: e55e5df193d247a38a5e1ac65a5316a0adcc22fa
commit: dfe9a123451a6e73306c988eab3dab12df001677 SUNRPC: Enable rpcsec_gss_krb5.ko to be built without CRYPTO_DES
date: 4 months ago
config: x86_64-randconfig-m001-20230629 (https://download.01.org/0day-ci/archive/20230630/202306302221.9wcsHTOG-lkp@xxxxxxxxx/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230630/202306302221.9wcsHTOG-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/202306302221.9wcsHTOG-lkp@xxxxxxxxx/

New smatch warnings:
net/sunrpc/auth_gss/gss_krb5_mech.c:181 gss_krb5_prepare_enctype_priority_list() warn: unsigned 'i' is never less than zero.
net/sunrpc/auth_gss/gss_krb5_mech.c:181 gss_krb5_prepare_enctype_priority_list() warn: unsigned 'i' is never less than zero.

Old smatch warnings:
net/sunrpc/auth_gss/gss_krb5_mech.c:200 supported_gss_krb5_enctype() warn: we never enter this loop
net/sunrpc/auth_gss/gss_krb5_mech.c:210 get_gss_krb5_enctype() warn: we never enter this loop

vim +/i +181 net/sunrpc/auth_gss/gss_krb5_mech.c

17781b2ce41a89 Chuck Lever 2023-01-15 159
17781b2ce41a89 Chuck Lever 2023-01-15 160 static void gss_krb5_prepare_enctype_priority_list(void)
17781b2ce41a89 Chuck Lever 2023-01-15 161 {
17781b2ce41a89 Chuck Lever 2023-01-15 162 static const u32 gss_krb5_enctypes[] = {
dfe9a123451a6e Chuck Lever 2023-01-15 163 #if defined(CONFIG_RPCSEC_GSS_KRB5_ENCTYPES_AES_SHA1)
17781b2ce41a89 Chuck Lever 2023-01-15 164 ENCTYPE_AES256_CTS_HMAC_SHA1_96,
17781b2ce41a89 Chuck Lever 2023-01-15 165 ENCTYPE_AES128_CTS_HMAC_SHA1_96,
dfe9a123451a6e Chuck Lever 2023-01-15 166 #endif
dfe9a123451a6e Chuck Lever 2023-01-15 167 #if defined(CONFIG_RPCSEC_GSS_KRB5_ENCTYPES_DES)
17781b2ce41a89 Chuck Lever 2023-01-15 168 ENCTYPE_DES3_CBC_SHA1,
17781b2ce41a89 Chuck Lever 2023-01-15 169 ENCTYPE_DES_CBC_MD5,
17781b2ce41a89 Chuck Lever 2023-01-15 170 ENCTYPE_DES_CBC_CRC,
17781b2ce41a89 Chuck Lever 2023-01-15 171 ENCTYPE_DES_CBC_MD4,
17781b2ce41a89 Chuck Lever 2023-01-15 172 #endif
17781b2ce41a89 Chuck Lever 2023-01-15 173 };
17781b2ce41a89 Chuck Lever 2023-01-15 174 size_t total, i;
17781b2ce41a89 Chuck Lever 2023-01-15 175 char buf[16];
17781b2ce41a89 Chuck Lever 2023-01-15 176 char *sep;
17781b2ce41a89 Chuck Lever 2023-01-15 177 int n;
17781b2ce41a89 Chuck Lever 2023-01-15 178
17781b2ce41a89 Chuck Lever 2023-01-15 179 sep = "";
17781b2ce41a89 Chuck Lever 2023-01-15 180 gss_krb5_enctype_priority_list[0] = '\0';
17781b2ce41a89 Chuck Lever 2023-01-15 @181 for (total = 0, i = 0; i < ARRAY_SIZE(gss_krb5_enctypes); i++) {
17781b2ce41a89 Chuck Lever 2023-01-15 182 n = sprintf(buf, "%s%u", sep, gss_krb5_enctypes[i]);
17781b2ce41a89 Chuck Lever 2023-01-15 183 if (n < 0)
17781b2ce41a89 Chuck Lever 2023-01-15 184 break;
17781b2ce41a89 Chuck Lever 2023-01-15 185 if (total + n >= sizeof(gss_krb5_enctype_priority_list))
17781b2ce41a89 Chuck Lever 2023-01-15 186 break;
17781b2ce41a89 Chuck Lever 2023-01-15 187 strcat(gss_krb5_enctype_priority_list, buf);
17781b2ce41a89 Chuck Lever 2023-01-15 188 sep = ",";
17781b2ce41a89 Chuck Lever 2023-01-15 189 total += n;
17781b2ce41a89 Chuck Lever 2023-01-15 190 }
17781b2ce41a89 Chuck Lever 2023-01-15 191 }
17781b2ce41a89 Chuck Lever 2023-01-15 192

:::::: The code at line 181 was first introduced by commit
:::::: 17781b2ce41a8915163d7cdada021f809ccd49f0 SUNRPC: Replace KRB5_SUPPORTED_ENCTYPES macro

:::::: TO: Chuck Lever <chuck.lever@xxxxxxxxxx>
:::::: CC: Chuck Lever <chuck.lever@xxxxxxxxxx>

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