lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 23 Oct 2022 23:47:18 +0800
From:   kernel test robot <lkp@...el.com>
To:     KaiLong Wang <wangkailong@...i.cn>, davem@...emloft.net,
        yoshfuji@...ux-ipv6.org, dsahern@...nel.org, edumazet@...gle.com,
        kuba@...nel.org, pabeni@...hat.com
Cc:     llvm@...ts.linux.dev, kbuild-all@...ts.01.org,
        netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] net: replace ternary operator with min()

Hi KaiLong,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]
[also build test WARNING on net/master linus/master v6.1-rc1 next-20221021]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/KaiLong-Wang/net-replace-ternary-operator-with-min/20221023-211341
patch link:    https://lore.kernel.org/r/4e5c1182.347.18404f42721.Coremail.wangkailong%40jari.cn
patch subject: [PATCH] net: replace ternary operator with min()
config: i386-randconfig-a013
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f816f1331754a52709034b8a73ce44ffe4722b90
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review KaiLong-Wang/net-replace-ternary-operator-with-min/20221023-211341
        git checkout f816f1331754a52709034b8a73ce44ffe4722b90
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/ipv4/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@...el.com>

All warnings (new ones prefixed by >>):

>> net/ipv4/igmp.c:2574:14: warning: comparison of distinct pointer types ('typeof (count) *' (aka 'int *') and 'typeof (msf->imsf_numsrc) *' (aka 'unsigned int *')) [-Wcompare-distinct-pointer-types]
           copycount = min(count, msf->imsf_numsrc);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:45:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(x, y, <)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
>> net/ipv4/igmp.c:2621:14: warning: comparison of distinct pointer types ('typeof (count) *' (aka 'int *') and 'typeof (gsf->gf_numsrc) *' (aka 'unsigned int *')) [-Wcompare-distinct-pointer-types]
           copycount = min(count, gsf->gf_numsrc);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:45:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(x, y, <)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   2 warnings generated.


vim +2574 net/ipv4/igmp.c

  2441	
  2442	int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
  2443	{
  2444		int err = 0;
  2445		struct ip_mreqn	imr;
  2446		__be32 addr = msf->imsf_multiaddr;
  2447		struct ip_mc_socklist *pmc;
  2448		struct in_device *in_dev;
  2449		struct inet_sock *inet = inet_sk(sk);
  2450		struct ip_sf_socklist *newpsl, *psl;
  2451		struct net *net = sock_net(sk);
  2452		int leavegroup = 0;
  2453	
  2454		if (!ipv4_is_multicast(addr))
  2455			return -EINVAL;
  2456		if (msf->imsf_fmode != MCAST_INCLUDE &&
  2457		    msf->imsf_fmode != MCAST_EXCLUDE)
  2458			return -EINVAL;
  2459	
  2460		ASSERT_RTNL();
  2461	
  2462		imr.imr_multiaddr.s_addr = msf->imsf_multiaddr;
  2463		imr.imr_address.s_addr = msf->imsf_interface;
  2464		imr.imr_ifindex = ifindex;
  2465		in_dev = ip_mc_find_dev(net, &imr);
  2466	
  2467		if (!in_dev) {
  2468			err = -ENODEV;
  2469			goto done;
  2470		}
  2471	
  2472		/* special case - (INCLUDE, empty) == LEAVE_GROUP */
  2473		if (msf->imsf_fmode == MCAST_INCLUDE && msf->imsf_numsrc == 0) {
  2474			leavegroup = 1;
  2475			goto done;
  2476		}
  2477	
  2478		for_each_pmc_rtnl(inet, pmc) {
  2479			if (pmc->multi.imr_multiaddr.s_addr == msf->imsf_multiaddr &&
  2480			    pmc->multi.imr_ifindex == imr.imr_ifindex)
  2481				break;
  2482		}
  2483		if (!pmc) {		/* must have a prior join */
  2484			err = -EINVAL;
  2485			goto done;
  2486		}
  2487		if (msf->imsf_numsrc) {
  2488			newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr,
  2489							      msf->imsf_numsrc),
  2490					      GFP_KERNEL);
  2491			if (!newpsl) {
  2492				err = -ENOBUFS;
  2493				goto done;
  2494			}
  2495			newpsl->sl_max = newpsl->sl_count = msf->imsf_numsrc;
  2496			memcpy(newpsl->sl_addr, msf->imsf_slist_flex,
  2497			       flex_array_size(msf, imsf_slist_flex, msf->imsf_numsrc));
  2498			err = ip_mc_add_src(in_dev, &msf->imsf_multiaddr,
  2499				msf->imsf_fmode, newpsl->sl_count, newpsl->sl_addr, 0);
  2500			if (err) {
  2501				sock_kfree_s(sk, newpsl,
  2502					     struct_size(newpsl, sl_addr,
  2503							 newpsl->sl_max));
  2504				goto done;
  2505			}
  2506		} else {
  2507			newpsl = NULL;
  2508			(void) ip_mc_add_src(in_dev, &msf->imsf_multiaddr,
  2509					     msf->imsf_fmode, 0, NULL, 0);
  2510		}
  2511		psl = rtnl_dereference(pmc->sflist);
  2512		if (psl) {
  2513			(void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode,
  2514				psl->sl_count, psl->sl_addr, 0);
  2515			/* decrease mem now to avoid the memleak warning */
  2516			atomic_sub(struct_size(psl, sl_addr, psl->sl_max),
  2517				   &sk->sk_omem_alloc);
  2518		} else {
  2519			(void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode,
  2520				0, NULL, 0);
  2521		}
  2522		rcu_assign_pointer(pmc->sflist, newpsl);
  2523		if (psl)
  2524			kfree_rcu(psl, rcu);
  2525		pmc->sfmode = msf->imsf_fmode;
  2526		err = 0;
  2527	done:
  2528		if (leavegroup)
  2529			err = ip_mc_leave_group(sk, &imr);
  2530		return err;
  2531	}
  2532	int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
  2533			 sockptr_t optval, sockptr_t optlen)
  2534	{
  2535		int err, len, count, copycount, msf_size;
  2536		struct ip_mreqn	imr;
  2537		__be32 addr = msf->imsf_multiaddr;
  2538		struct ip_mc_socklist *pmc;
  2539		struct in_device *in_dev;
  2540		struct inet_sock *inet = inet_sk(sk);
  2541		struct ip_sf_socklist *psl;
  2542		struct net *net = sock_net(sk);
  2543	
  2544		ASSERT_RTNL();
  2545	
  2546		if (!ipv4_is_multicast(addr))
  2547			return -EINVAL;
  2548	
  2549		imr.imr_multiaddr.s_addr = msf->imsf_multiaddr;
  2550		imr.imr_address.s_addr = msf->imsf_interface;
  2551		imr.imr_ifindex = 0;
  2552		in_dev = ip_mc_find_dev(net, &imr);
  2553	
  2554		if (!in_dev) {
  2555			err = -ENODEV;
  2556			goto done;
  2557		}
  2558		err = -EADDRNOTAVAIL;
  2559	
  2560		for_each_pmc_rtnl(inet, pmc) {
  2561			if (pmc->multi.imr_multiaddr.s_addr == msf->imsf_multiaddr &&
  2562			    pmc->multi.imr_ifindex == imr.imr_ifindex)
  2563				break;
  2564		}
  2565		if (!pmc)		/* must have a prior join */
  2566			goto done;
  2567		msf->imsf_fmode = pmc->sfmode;
  2568		psl = rtnl_dereference(pmc->sflist);
  2569		if (!psl) {
  2570			count = 0;
  2571		} else {
  2572			count = psl->sl_count;
  2573		}
> 2574		copycount = min(count, msf->imsf_numsrc);
  2575		len = flex_array_size(psl, sl_addr, copycount);
  2576		msf->imsf_numsrc = count;
  2577		msf_size = IP_MSFILTER_SIZE(copycount);
  2578		if (copy_to_sockptr(optlen, &msf_size, sizeof(int)) ||
  2579		    copy_to_sockptr(optval, msf, IP_MSFILTER_SIZE(0))) {
  2580			return -EFAULT;
  2581		}
  2582		if (len &&
  2583		    copy_to_sockptr_offset(optval,
  2584					   offsetof(struct ip_msfilter, imsf_slist_flex),
  2585					   psl->sl_addr, len))
  2586			return -EFAULT;
  2587		return 0;
  2588	done:
  2589		return err;
  2590	}
  2591	
  2592	int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
  2593			 sockptr_t optval, size_t ss_offset)
  2594	{
  2595		int i, count, copycount;
  2596		struct sockaddr_in *psin;
  2597		__be32 addr;
  2598		struct ip_mc_socklist *pmc;
  2599		struct inet_sock *inet = inet_sk(sk);
  2600		struct ip_sf_socklist *psl;
  2601	
  2602		ASSERT_RTNL();
  2603	
  2604		psin = (struct sockaddr_in *)&gsf->gf_group;
  2605		if (psin->sin_family != AF_INET)
  2606			return -EINVAL;
  2607		addr = psin->sin_addr.s_addr;
  2608		if (!ipv4_is_multicast(addr))
  2609			return -EINVAL;
  2610	
  2611		for_each_pmc_rtnl(inet, pmc) {
  2612			if (pmc->multi.imr_multiaddr.s_addr == addr &&
  2613			    pmc->multi.imr_ifindex == gsf->gf_interface)
  2614				break;
  2615		}
  2616		if (!pmc)		/* must have a prior join */
  2617			return -EADDRNOTAVAIL;
  2618		gsf->gf_fmode = pmc->sfmode;
  2619		psl = rtnl_dereference(pmc->sflist);
  2620		count = psl ? psl->sl_count : 0;
> 2621		copycount = min(count, gsf->gf_numsrc);
  2622		gsf->gf_numsrc = count;
  2623		for (i = 0; i < copycount; i++) {
  2624			struct sockaddr_storage ss;
  2625	
  2626			psin = (struct sockaddr_in *)&ss;
  2627			memset(&ss, 0, sizeof(ss));
  2628			psin->sin_family = AF_INET;
  2629			psin->sin_addr.s_addr = psl->sl_addr[i];
  2630			if (copy_to_sockptr_offset(optval, ss_offset,
  2631						   &ss, sizeof(ss)))
  2632				return -EFAULT;
  2633			ss_offset += sizeof(ss);
  2634		}
  2635		return 0;
  2636	}
  2637	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

View attachment "config" of type "text/plain" (155663 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ