Covscan: Don't access garbage
Subsystems (2)
v2 cover Covscan: Don't access garbage
This series collects patches from v1 which resolve situations where garbage might be read, either due to missing initialization of variables or accessing data which went out of scope.
No changes to the actual patches, just splitting into smaller series.
Phil Sutter (7):
ipaddress: Make buffer for filter.flushb static
ipaddress: Avoid accessing uninitialized variable lcl
iplink_can: Prevent overstepping array bounds
ipmaddr: Avoid accessing uninitialized data
ss: Use C99 initializer in netlink_show_one() netem/maketable: Check return value of fstat() tc/q_multiq: Don't pass garbage in TCA_OPTIONS
ip/ipaddress.c | 4 ++-- ip/iplink_can.c | 4 ++-- ip/ipmaddr.c | 2 +- misc/ss.c | 13 +++++++------ netem/maketable.c | 4 ++-- tc/q_multiq.c | 2 +- 6 files changed, 15 insertions(+), 14 deletions(-)
Signature · 1 line
2.13.1
PATCH v2 1/7 ipaddress: Make buffer for filter.flushb static
The buffer is accessed outside of the function defining it, so make it static.
--- ip/ipaddress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/ipaddress.c +1 -1
@@ -1488,7 +1488,7 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)static int ipaddr_flush (void ) {int round =0 ; -char flushb[4096 -512 ]; +static char flushb[4096 -512 ]; filter.flushb = flushb; filter.flushp =0 ;
Signature · 1 line
2.13.1
Re: [iproute PATCH v2 1/7] ipaddress: Make buffer for filter.flushb static
Quoted 4 lines · Phil Sutter
The buffer is accessed outside of the function defining it, so make it static.
Signed-off-by Phil Sutter <[email protected]>
Self-NACK: Access to flushb should be sane since all accessors are called from ipaddr_flush(). Looking at the covscan output again, it merely complained about filter.flusb still pointing to the local buffer when ipaddr_flush() returns.
Cheers, Phil
Re: [iproute PATCH v2 1/7] ipaddress: Make buffer for filter.flushb static
Quoted 4 lines · On Fri, 18 Aug 2017 13:57:03 +0200 Phil Sutter <[email protected]> wrote:
Quoted 3 lines · Phil Sutter
The buffer is accessed outside of the function defining it, so make it static.
Quoted 8 lines
Quoted 1 line
Signed-off-by Phil Sutter <[email protected]>Self-NACK: Access to flushb should be sane since all accessors are called from
ipaddr_flush(). Looking at the covscan output again, it merely complained about filter.flusb still pointing to the local buffer whenipaddr_flush()returns.Cheers, Phil
Ok, dropping this sub-series
PATCH v2 2/7 ipaddress: Avoid accessing uninitialized variable lcl
In reply to Phil SutterIf no address was given, ipaddr_modify() accesses uninitialized data when assigning to req.ifa.ifa_prefixlen.
--- ip/ipaddress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/ipaddress.c +1 -1
@@ -1888,7 +1888,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)char *lcl_arg =NULL ;char *valid_lftp =NULL ;char *preferred_lftp =NULL ; -inet_prefix lcl; +inet_prefix lcl = {};inet_prefix peer;int local_len =0 ;int peer_len =0 ;
Signature · 1 line
2.13.1
PATCH v2 3/7 iplink_can: Prevent overstepping array bounds
In reply to Phil Suttercan_state_names array contains at most CAN_STATE_MAX fields, so allowing an index to it to be equal to that number is wrong. While here, also make sure the array is indeed that big so nothing bad happens if CAN_STATE_MAX ever increases.
--- ip/iplink_can.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ip/iplink_can.c +2 -2
@@ -251,7 +251,7 @@ static int can_parse_opt(struct link_util *lu, int argc, char **argv,return 0 ; } -static const char *can_state_names[] = { +static const char *can_state_names[CAN_STATE_MAX ] = { [CAN_STATE_ERROR_ACTIVE ] ="ERROR-ACTIVE" , [CAN_STATE_ERROR_WARNING ] ="ERROR-WARNING" , [CAN_STATE_ERROR_PASSIVE ] ="ERROR-PASSIVE" ,
@@ -275,7 +275,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])if (tb[IFLA_CAN_STATE ]) {uint32_t state =rta_getattr_u32 (tb[IFLA_CAN_STATE ]); -fprintf (f,"state %s " , state <=CAN_STATE_MAX ? +fprintf (f,"state %s " , state <CAN_STATE_MAX ? can_state_names[state] :"UNKNOWN" ); }
Signature · 1 line
2.13.1
PATCH v2 4/7 ipmaddr: Avoid accessing uninitialized data
In reply to Phil SutterLooks like this can only happen if /proc/net/igmp is malformed, but better be sure.
--- ip/ipmaddr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/ipmaddr.c +1 -1
@@ -136,7 +136,7 @@ static void read_igmp(struct ma_info **result_p)while (fgets (buf,sizeof (buf), fp)) {struct ma_info *ma; -size_t len; +size_t len =0 ;if (buf[0 ] !='\t' ) {sscanf (buf,"%d%s" , &m.index, m.name);
Signature · 1 line
2.13.1
PATCH v2 5/7 ss: Use C99 initializer in netlink_show_one()
In reply to Phil SutterThis has the additional benefit of initializing st.ino to zero which is used later in is_sctp_assoc() function.
--- misc/ss.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
misc/ss.c +7 -6
@@ -3469,17 +3469,18 @@ static int netlink_show_one(struct filter *f, int rq, int wq, unsigned long long sk, unsigned long long cb) { - struct sockstat st; + struct sockstat st = { + .state =SS_CLOSE , + .rq = rq, + .wq = wq, + .local.family =AF_NETLINK , + .remote.family =AF_NETLINK , + };SPRINT_BUF (prot_buf) = {};const char *prot_name;char procname[64 ] = {}; - st.state =SS_CLOSE ; - st.rq = rq; - st.wq = wq; - st.local.family = st.remote.family =AF_NETLINK ; -if (f->f) { st.rport =-1 ; st.lport = pid;
Signature · 1 line
2.13.1
PATCH v2 6/7 netem/maketable: Check return value of fstat()
In reply to Phil SutterOtherwise info.st_size may contain garbage.
--- netem/maketable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
netem/maketable.c +2 -2
@@ -24,8 +24,8 @@ readdoubles(FILE *fp, int *number)int limit;int n=0 , i; -fstat (fileno (fp), &info); -if (info.st_size >0 ) { +if (!fstat (fileno (fp), &info) && + info.st_size >0 ) { limit =2 *info.st_size/sizeof (double );/* @@ approximate */ }else { limit =10000 ;
Signature · 1 line
2.13.1
PATCH v2 7/7 tc/q_multiq: Don't pass garbage in TCA_OPTIONS
In reply to Phil Suttermultiq_parse_opt() doesn't change 'opt' at all. So at least make sure it doesn't fill TCA_OPTIONS attribute with garbage from stack.
--- tc/q_multiq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tc/q_multiq.c +1 -1
@@ -43,7 +43,7 @@ static void explain(void)static int multiq_parse_opt (struct qdisc_util *qu,int argc,char **argv,struct nlmsghdr *n) { -struct tc_multiq_qopt opt; +struct tc_multiq_qopt opt = {};if (argc) {if (strcmp (*argv,"help" ) ==0 ) {
Signature · 1 line
2.13.1