CC: [email protected]
TO: Christoph Hellwig <[email protected]>

tree:   git://git.infradead.org/users/hch/misc.git sockptr
head:   ffd998f4245814309d3715c6d03c479f9585abed
commit: ffd998f4245814309d3715c6d03c479f9585abed [46/46] net: pass a sockptr_t 
into ->setsockopt
:::::: branch date: 21 hours ago
:::::: commit date: 21 hours ago
config: i386-randconfig-m021-20200717 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-14) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

smatch warnings:
net/can/j1939/socket.c:675 j1939_sk_setsockopt() warn: passing a valid pointer 
to 'PTR_ERR'

git remote add hch-misc git://git.infradead.org/users/hch/misc.git
git remote update hch-misc
git checkout ffd998f4245814309d3715c6d03c479f9585abed
vim +/PTR_ERR +675 net/can/j1939/socket.c

9d71dd0c700999 The j1939 authors 2018-10-08  647  
9d71dd0c700999 The j1939 authors 2018-10-08  648  static int 
j1939_sk_setsockopt(struct socket *sock, int level, int optname,
ffd998f4245814 Christoph Hellwig 2020-07-16  649                               
sockptr_t optval, unsigned int optlen)
9d71dd0c700999 The j1939 authors 2018-10-08  650  {
9d71dd0c700999 The j1939 authors 2018-10-08  651        struct sock *sk = 
sock->sk;
9d71dd0c700999 The j1939 authors 2018-10-08  652        struct j1939_sock *jsk 
= j1939_sk(sk);
9d71dd0c700999 The j1939 authors 2018-10-08  653        int tmp, count = 0, ret 
= 0;
9d71dd0c700999 The j1939 authors 2018-10-08  654        struct j1939_filter 
*filters = NULL, *ofilters;
9d71dd0c700999 The j1939 authors 2018-10-08  655  
9d71dd0c700999 The j1939 authors 2018-10-08  656        if (level != 
SOL_CAN_J1939)
9d71dd0c700999 The j1939 authors 2018-10-08  657                return -EINVAL;
9d71dd0c700999 The j1939 authors 2018-10-08  658  
9d71dd0c700999 The j1939 authors 2018-10-08  659        switch (optname) {
9d71dd0c700999 The j1939 authors 2018-10-08  660        case SO_J1939_FILTER:
ffd998f4245814 Christoph Hellwig 2020-07-16  661                if 
(!sockptr_is_null(optval)) {
9d71dd0c700999 The j1939 authors 2018-10-08  662                        struct 
j1939_filter *f;
9d71dd0c700999 The j1939 authors 2018-10-08  663                        int c;
9d71dd0c700999 The j1939 authors 2018-10-08  664  
9d71dd0c700999 The j1939 authors 2018-10-08  665                        if 
(optlen % sizeof(*filters) != 0)
9d71dd0c700999 The j1939 authors 2018-10-08  666                                
return -EINVAL;
9d71dd0c700999 The j1939 authors 2018-10-08  667  
9d71dd0c700999 The j1939 authors 2018-10-08  668                        if 
(optlen > J1939_FILTER_MAX *
9d71dd0c700999 The j1939 authors 2018-10-08  669                            
sizeof(struct j1939_filter))
9d71dd0c700999 The j1939 authors 2018-10-08  670                                
return -EINVAL;
9d71dd0c700999 The j1939 authors 2018-10-08  671  
9d71dd0c700999 The j1939 authors 2018-10-08  672                        count = 
optlen / sizeof(*filters);
ffd998f4245814 Christoph Hellwig 2020-07-16  673                        filters 
= memdup_sockptr(optval, optlen);
9d71dd0c700999 The j1939 authors 2018-10-08  674                        if 
(IS_ERR(filters))
9d71dd0c700999 The j1939 authors 2018-10-08 @675                                
return PTR_ERR(filters);
9d71dd0c700999 The j1939 authors 2018-10-08  676  
9d71dd0c700999 The j1939 authors 2018-10-08  677                        for (f 
= filters, c = count; c; f++, c--) {
9d71dd0c700999 The j1939 authors 2018-10-08  678                                
f->name &= f->name_mask;
9d71dd0c700999 The j1939 authors 2018-10-08  679                                
f->pgn &= f->pgn_mask;
9d71dd0c700999 The j1939 authors 2018-10-08  680                                
f->addr &= f->addr_mask;
9d71dd0c700999 The j1939 authors 2018-10-08  681                        }
9d71dd0c700999 The j1939 authors 2018-10-08  682                }
9d71dd0c700999 The j1939 authors 2018-10-08  683  
9d71dd0c700999 The j1939 authors 2018-10-08  684                
lock_sock(&jsk->sk);
9d71dd0c700999 The j1939 authors 2018-10-08  685                ofilters = 
jsk->filters;
9d71dd0c700999 The j1939 authors 2018-10-08  686                jsk->filters = 
filters;
9d71dd0c700999 The j1939 authors 2018-10-08  687                jsk->nfilters = 
count;
9d71dd0c700999 The j1939 authors 2018-10-08  688                
release_sock(&jsk->sk);
9d71dd0c700999 The j1939 authors 2018-10-08  689                kfree(ofilters);
9d71dd0c700999 The j1939 authors 2018-10-08  690                return 0;
9d71dd0c700999 The j1939 authors 2018-10-08  691        case SO_J1939_PROMISC:
9d71dd0c700999 The j1939 authors 2018-10-08  692                return 
j1939_sk_setsockopt_flag(jsk, optval, optlen,
9d71dd0c700999 The j1939 authors 2018-10-08  693                                
                J1939_SOCK_PROMISC);
9d71dd0c700999 The j1939 authors 2018-10-08  694        case SO_J1939_ERRQUEUE:
9d71dd0c700999 The j1939 authors 2018-10-08  695                ret = 
j1939_sk_setsockopt_flag(jsk, optval, optlen,
9d71dd0c700999 The j1939 authors 2018-10-08  696                                
               J1939_SOCK_ERRQUEUE);
9d71dd0c700999 The j1939 authors 2018-10-08  697                if (ret < 0)
9d71dd0c700999 The j1939 authors 2018-10-08  698                        return 
ret;
9d71dd0c700999 The j1939 authors 2018-10-08  699  
9d71dd0c700999 The j1939 authors 2018-10-08  700                if 
(!(jsk->state & J1939_SOCK_ERRQUEUE))
9d71dd0c700999 The j1939 authors 2018-10-08  701                        
skb_queue_purge(&sk->sk_error_queue);
9d71dd0c700999 The j1939 authors 2018-10-08  702                return ret;
9d71dd0c700999 The j1939 authors 2018-10-08  703        case SO_J1939_SEND_PRIO:
9d71dd0c700999 The j1939 authors 2018-10-08  704                if (optlen != 
sizeof(tmp))
9d71dd0c700999 The j1939 authors 2018-10-08  705                        return 
-EINVAL;
ffd998f4245814 Christoph Hellwig 2020-07-16  706                if 
(copy_from_sockptr(&tmp, optval, optlen))
9d71dd0c700999 The j1939 authors 2018-10-08  707                        return 
-EFAULT;
9d71dd0c700999 The j1939 authors 2018-10-08  708                if (tmp < 0 || 
tmp > 7)
9d71dd0c700999 The j1939 authors 2018-10-08  709                        return 
-EDOM;
9d71dd0c700999 The j1939 authors 2018-10-08  710                if (tmp < 2 && 
!capable(CAP_NET_ADMIN))
9d71dd0c700999 The j1939 authors 2018-10-08  711                        return 
-EPERM;
9d71dd0c700999 The j1939 authors 2018-10-08  712                
lock_sock(&jsk->sk);
9d71dd0c700999 The j1939 authors 2018-10-08  713                
jsk->sk.sk_priority = j1939_to_sk_priority(tmp);
9d71dd0c700999 The j1939 authors 2018-10-08  714                
release_sock(&jsk->sk);
9d71dd0c700999 The j1939 authors 2018-10-08  715                return 0;
9d71dd0c700999 The j1939 authors 2018-10-08  716        default:
9d71dd0c700999 The j1939 authors 2018-10-08  717                return 
-ENOPROTOOPT;
9d71dd0c700999 The j1939 authors 2018-10-08  718        }
9d71dd0c700999 The j1939 authors 2018-10-08  719  }
9d71dd0c700999 The j1939 authors 2018-10-08  720  

:::::: The code at line 675 was first introduced by commit
:::::: 9d71dd0c70099914fcd063135da3c580865e924c can: add support of SAE J1939 
protocol

:::::: TO: The j1939 authors <[email protected]>
:::::: CC: Marc Kleine-Budde <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

Attachment: .config.gz
Description: application/gzip

_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to