Re: [PATCH net-next v2] af_unix: Refine UNIX pathname sockets autobind identifier length

From: kernel test robot
Date: Sat Feb 08 2025 - 11:27:54 EST


Hi Liang,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url: https://github.com/intel-lab-lkp/linux/commits/Liang-Jie/af_unix-Refine-UNIX-pathname-sockets-autobind-identifier-length/20250206-134846
base: net-next/main
patch link: https://lore.kernel.org/r/20250206054451.4070941-1-buaajxlj%40163.com
patch subject: [PATCH net-next v2] af_unix: Refine UNIX pathname sockets autobind identifier length
config: hexagon-randconfig-001-20250207 (https://download.01.org/0day-ci/archive/20250209/202502090056.Rl1rtpr5-lkp@xxxxxxxxx/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 6807164500e9920638e2ab0cdb4bf8321d24f8eb)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250209/202502090056.Rl1rtpr5-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/202502090056.Rl1rtpr5-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

>> net/unix/af_unix.c:1222:2: warning: 'snprintf' will always be truncated; specified size is 5, but format string expands to at least 6 [-Wformat-truncation]
1222 | snprintf(addr->name->sun_path + 1, 5, "%05x", ordernum);
| ^
1 warning generated.


vim +/snprintf +1222 net/unix/af_unix.c

1190
1191 static int unix_autobind(struct sock *sk)
1192 {
1193 struct unix_sock *u = unix_sk(sk);
1194 unsigned int new_hash, old_hash;
1195 struct net *net = sock_net(sk);
1196 struct unix_address *addr;
1197 u32 lastnum, ordernum;
1198 int err;
1199
1200 err = mutex_lock_interruptible(&u->bindlock);
1201 if (err)
1202 return err;
1203
1204 if (u->addr)
1205 goto out;
1206
1207 err = -ENOMEM;
1208 addr = kzalloc(sizeof(*addr) + offsetof(struct sockaddr_un, sun_path) +
1209 UNIX_AUTOBIND_LEN, GFP_KERNEL);
1210 if (!addr)
1211 goto out;
1212
1213 addr->len = offsetof(struct sockaddr_un, sun_path) + UNIX_AUTOBIND_LEN;
1214 addr->name->sun_family = AF_UNIX;
1215 refcount_set(&addr->refcnt, 1);
1216
1217 old_hash = sk->sk_hash;
1218 ordernum = get_random_u32();
1219 lastnum = ordernum & 0xFFFFF;
1220 retry:
1221 ordernum = (ordernum + 1) & 0xFFFFF;
> 1222 snprintf(addr->name->sun_path + 1, 5, "%05x", ordernum);
1223
1224 new_hash = unix_abstract_hash(addr->name, addr->len, sk->sk_type);
1225 unix_table_double_lock(net, old_hash, new_hash);
1226
1227 if (__unix_find_socket_byname(net, addr->name, addr->len, new_hash)) {
1228 unix_table_double_unlock(net, old_hash, new_hash);
1229
1230 /* __unix_find_socket_byname() may take long time if many names
1231 * are already in use.
1232 */
1233 cond_resched();
1234
1235 if (ordernum == lastnum) {
1236 /* Give up if all names seems to be in use. */
1237 err = -ENOSPC;
1238 unix_release_addr(addr);
1239 goto out;
1240 }
1241
1242 goto retry;
1243 }
1244
1245 __unix_set_addr_hash(net, sk, addr, new_hash);
1246 unix_table_double_unlock(net, old_hash, new_hash);
1247 err = 0;
1248

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