Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_data/db/fixup_kernel.sh
          +++ new/usr/src/tools/smatch/src/smatch_data/db/fixup_kernel.sh
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16  
  17   17  /* delete these function pointers which cause false positives */
  18   18  delete from caller_info where function = '(struct file_operations)->open' and type != 0;
  19   19  delete from caller_info where function = '(struct notifier_block)->notifier_call' and type != 0;
  20   20  delete from caller_info where function = '(struct mISDNchannel)->send' and type != 0;
  21   21  delete from caller_info where function = '(struct irq_router)->get' and type != 0;
  22   22  delete from caller_info where function = '(struct irq_router)->set' and type != 0;
  23   23  delete from caller_info where function = '(struct net_device_ops)->ndo_change_mtu' and caller = 'i40e_dbg_netdev_ops_write';
  24   24  delete from caller_info where function = '(struct timer_list)->function' and type != 0;
  25   25  
  26      -/* type 1003 is USER_DATA */
  27      -delete from caller_info where caller = 'hid_input_report' and type = 1003;
  28      -delete from caller_info where caller = 'nes_process_iwarp_aeqe' and type = 1003;
  29      -delete from caller_info where caller = 'oz_process_ep0_urb' and type = 1003;
  30      -delete from caller_info where function = 'dev_hard_start_xmit' and key = '\$' and type = 1003;
  31      -delete from caller_info where function like '%->ndo_start_xmit' and key = '\$' and type = 1003;
  32      -delete from caller_info where caller = 'packet_rcv_fanout' and function = '(struct packet_type)->func' and parameter = 1 and type = 1003;
  33      -delete from caller_info where caller = 'hptiop_probe' and type = 1003;
  34      -delete from caller_info where caller = 'p9_fd_poll' and function = '(struct file_operations)->poll' and type = 1003;
  35      -delete from caller_info where caller = 'proc_reg_poll' and function = 'proc_reg_poll ptr poll' and type = 1003;
  36      -delete from caller_info where function = 'blkdev_ioctl' and type = 1003 and parameter = 0 and key = '\$';
  37      -/* 9017 is USER_DATA3_SET */
       26 +/* 8017 is USER_DATA and  9017 is USER_DATA_SET */
       27 +delete from caller_info where function = 'dev_hard_start_xmit' and type = 8017;
  38   28  delete from return_states where function='vscnprintf' and type = 9017;
  39   29  delete from return_states where function='scnprintf' and type = 9017;
  40   30  delete from return_states where function='vsnprintf' and type = 9017;
  41   31  delete from return_states where function='snprintf' and type = 9017;
  42   32  delete from return_states where function='sprintf' and type = 9017;
  43   33  delete from return_states where function='vscnprintf' and type = 8017;
  44   34  delete from return_states where function='scnprintf' and type = 8017;
  45   35  delete from return_states where function='vsnprintf' and type = 8017;
  46   36  delete from return_states where function='snprintf' and type = 8017;
  47   37  delete from return_states where function='sprintf' and type = 8017;
  48   38  /* There is something setting skb->sk->sk_mark and friends to user_data and */
  49   39  /* because of recursion it gets passed to everything and is impossible to debug */
  50   40  delete from caller_info where function = '__dev_queue_xmit' and type = 8017;
  51   41  delete from caller_info where function = '__netdev_start_xmit' and type = 8017;
       42 +delete from caller_info where function = '(struct packet_type)->func' and type = 8017;
       43 +delete from caller_info where function = '(struct bio)->bi_end_io' and type = 8017;
       44 +delete from caller_info where caller = 'NF_HOOK_COND' and type = 8017;
       45 +delete from caller_info where caller = 'NF_HOOK' and type = 8017;
  52   46  /* comparison doesn't deal with chunks, I guess.  */
  53   47  delete from return_states where function='get_tty_driver' and type = 8017;
  54   48  delete from caller_info where caller = 'snd_ctl_elem_write' and function = '(struct snd_kcontrol)->put' and type = 8017;
  55   49  delete from caller_info where caller = 'snd_ctl_elem_read' and function = '(struct snd_kcontrol)->get' and type = 8017;
  56   50  delete from caller_info where function = 'nf_tables_newexpr' and type = 8017 and key = '\$->family';
  57   51  delete from caller_info where caller = 'fb_set_var' and function = '(struct fb_ops)->fb_set_par' and type = 8017 and parameter = 0;
  58   52  delete from return_states where function = 'tty_lookup_driver' and parameter = 2 and type = 8017;
  59   53  
  60      -insert into caller_info values ('userspace', '', 'compat_sys_ioctl', 0, 0, 1003, 0, '\$', '1');
  61      -insert into caller_info values ('userspace', '', 'compat_sys_ioctl', 0, 0, 1003, 1, '\$', '1');
  62      -insert into caller_info values ('userspace', '', 'compat_sys_ioctl', 0, 0, 1003, 2, '\$', '1');
       54 +insert into caller_info values ('userspace', '', 'compat_sys_ioctl', 0, 0, 8017, 0, '\$', '1');
       55 +insert into caller_info values ('userspace', '', 'compat_sys_ioctl', 0, 0, 8017, 1, '\$', '1');
       56 +insert into caller_info values ('userspace', '', 'compat_sys_ioctl', 0, 0, 8017, 2, '\$', '1');
  63   57  
  64   58  delete from caller_info where function = '(struct timer_list)->function' and parameter = 0;
  65   59  
  66   60  /*
  67   61   * rw_verify_area is a very central function for the kernel.  The 1000000000
  68   62   * isn't accurate but I've picked it so that we can add "pos + count" without
  69   63   * wrapping on 32 bits.
  70   64   */
  71   65  delete from return_states where function = 'rw_verify_area';
  72   66  insert into return_states values ('faked', 'rw_verify_area', 0, 1, '0-1000000000[<=\$3]', 0, 0,   -1,      '', '');
  73   67  insert into return_states values ('faked', 'rw_verify_area', 0, 1, '0-1000000000[<=\$3]', 0, 104,  2, '*\$', '0-1000000000');
  74   68  insert into return_states values ('faked', 'rw_verify_area', 0, 1, '0-1000000000[<=\$3]', 0, 103, 3,  '\$', '0-1000000000');
  75   69  insert into return_states values ('faked', 'rw_verify_area', 0, 2, '(-4095)-(-1)',     0, 0,   -1,      '', '');
  76   70  
  77   71  delete from return_states where function = 'is_kernel_rodata';
  78   72  insert into return_states values ('faked', 'is_kernel_rodata', 0, 1, '1', 0, 0,   -1,  '', '');
  79      -insert into return_states values ('faked', 'is_kernel_rodata', 0, 1, '1', 0, 103,  0,  '\$', '100000000-177777777');
       73 +insert into return_states values ('faked', 'is_kernel_rodata', 0, 1, '1', 0, 103,  0,  '\$', '4096-ptr_max');
  80   74  insert into return_states values ('faked', 'is_kernel_rodata', 0, 2, '0', 0, 0,   -1,  '', '');
  81   75  
  82   76  /*
  83      - * I am a bad person for doing this to __kmalloc() which is a very deep function
  84      - * and can easily be removed instead of to kmalloc().  But kmalloc() is an
  85      - * inline function so it ends up being recorded thousands of times in the
  86      - * database.  Doing this is easier.
  87      - *
  88      - */
  89      -delete from return_states where function = '__kmalloc';
  90      -insert into return_states values ('faked', '__kmalloc', 0, 1, '16', 0,    0,  -1, '', '');
  91      -insert into return_states values ('faked', '__kmalloc', 0, 1, '16', 0, 103,   0, '\$', '0');
  92      -insert into return_states values ('faked', '__kmalloc', 0, 2, '0,500000000-577777777', 0,    0, -1, '', '');
  93      -insert into return_states values ('faked', '__kmalloc', 0, 2, '0,500000000-577777777', 0, 103,  0, '\$', '1-4000000');
  94      -insert into return_states values ('faked', '__kmalloc', 0, 2, '0,500000000-577777777', 0, 1037,  -1, '', 400);
  95      -insert into return_states values ('faked', '__kmalloc', 0, 3, '0', 0,    0,  -1, '', '');
  96      -insert into return_states values ('faked', '__kmalloc', 0, 3, '0', 0,    103,  0, '\$', '4000000-long_max');
  97      -
  98      -/*
  99   77   * Other kmalloc hacking.
 100   78   */
 101      -update return_states set return = '0,500000000-577777777' where function = 'kmalloc_slab' and return = 's64min-s64max';
 102      -update return_states set return = '0,500000000-577777777' where function = 'slab_alloc_node' and return = 's64min-s64max';
 103      -update return_states set return = '0,500000000-577777777' where function = 'kmalloc_large' and return != '0';
 104      -update return_states set return = '0,500000000-577777777' where function = 'kmalloc_order_trace' and return != '0';
 105      -
 106   79  delete from return_states where function = 'vmalloc';
 107      -insert into return_states values ('faked', 'vmalloc', 0, 1, '0,600000000-677777777', 0,    0, -1, '', '');
 108      -insert into return_states values ('faked', 'vmalloc', 0, 1, '0,600000000-677777777', 0, 103,  0, '\$', '1-128000000');
       80 +insert into return_states values ('faked', 'vmalloc', 0, 1, '4096-ptr_max', 0,    0, -1, '', '');
       81 +insert into return_states values ('faked', 'vmalloc', 0, 1, '4096-ptr_max', 0, 103,  0, '\$', '1-128000000');
 109   82  insert into return_states values ('faked', 'vmalloc', 0, 2, '0', 0,    0,  -1, '', '');
 110   83  
 111   84  delete from return_states where function = 'ksize';
 112   85  insert into return_states values ('faked', 'ksize', 0, 1, '0', 0,    0, -1, '', '');
 113   86  insert into return_states values ('faked', 'ksize', 0, 1, '0', 0, 103,  0, '\$', '16');
 114   87  insert into return_states values ('faked', 'ksize', 0, 2, '1-4000000', 0,    0,  -1, '', '');
 115   88  
 116   89  /* store a bunch of capped functions */
 117   90  update return_states set return = '0-u32max[<=\$2]' where function = 'copy_to_user';
 118   91  update return_states set return = '0-u32max[<=\$2]' where function = '_copy_to_user';
↓ open down ↓ 15 lines elided ↑ open up ↑
 134  107  update return_states set return = '0-u32max[==\$0]' where function = '__fswab32';
 135  108  update return_states set return = '0-u16max[==\$0]' where function = '__fswab16';
 136  109  update return_states set return = '0-u64max[==\$0]' where function = '__builtin_bswap64';
 137  110  update return_states set return = '0-u32max[==\$0]' where function = '__builtin_bswap32';
 138  111  update return_states set return = '0-u16max[==\$0]' where function = '__builtin_bswap16';
 139  112  
 140  113  delete from return_states where function = 'bitmap_allocate_region' and return = '1';
 141  114  /* Just delete a lot of returns that everyone ignores */
 142  115  delete from return_states where file = 'drivers/pci/access.c' and (return >= 129 and return <= 137);
 143  116  
 144      -update return_states set return = '(-4095)-s32max[<=\$1]' where function = 'get_user_pages' and return = 's32min-s32max';
 145      -update return_states set return = '(-4095)-s64max[<=\$1]' where function = 'get_user_pages' and return = 's64min-s64max';
 146      -
 147  117  /* Smatch can't parse wait_for_completion() */
 148  118  update return_states set return = '(-108),(-22),0' where function = '__spi_sync' and return = '(-115),(-108),(-22)';
 149  119  
 150  120  delete from caller_info where caller = '__kernel_write';
 151  121  
 152  122  /* We sometimes use pre-allocated 4097 byte buffers for performance critical code but pretend it is always PAGE_SIZE */
 153  123  update caller_info set value = 4096 where caller='kernfs_file_direct_read' and function='(struct kernfs_ops)->read' and type = 1002 and parameter = 1;
 154  124  /* let's pretend firewire doesn't exist */
 155  125  delete from caller_info where caller='init_fw_attribute_group' and function='(struct device_attribute)->show';
 156  126  /* and let's fake the next dev_attr_show() call entirely */
 157  127  delete from caller_info where caller='sysfs_kf_seq_show' and function='(struct sysfs_ops)->show';
 158      -insert into caller_info values ('fake', 'sysfs_kf_seq_show', '(struct sysfs_ops)->show', 0, 0, 1001, 0, '\$', '4096-2117777777777777777');
      128 +insert into caller_info values ('fake', 'sysfs_kf_seq_show', '(struct sysfs_ops)->show', 0, 0, 1001, 0, '\$', '4096-ptr_max');
 159  129  insert into caller_info values ('fake', 'sysfs_kf_seq_show', '(struct sysfs_ops)->show', 0, 0, 1002, 2, '\$', '4096');
 160      -insert into caller_info values ('fake', 'sysfs_kf_seq_show', '(struct sysfs_ops)->show', 0, 0, 1001, 2, '\$', '4096-2117777777777777777');
      130 +insert into caller_info values ('fake', 'sysfs_kf_seq_show', '(struct sysfs_ops)->show', 0, 0, 1001, 2, '\$', '4096-ptr_max');
 161  131  insert into caller_info values ('fake', 'sysfs_kf_seq_show', '(struct sysfs_ops)->show', 0, 0, 0,   -1, ''  , '');
 162  132  /* config fs confuses smatch a little */
 163  133  update caller_info set value = 4096 where caller='fill_read_buffer' and function='(struct configfs_item_operations)->show_attribute' and type = 1002 and parameter = 2;
 164  134  
 165  135  /* smatch sees the memset() but not the subsequent changes */
 166  136  update return_states set value = "" where function = 'gfs2_ea_find' and return = '0' and type = 101 and parameter = 3;
 167  137  
 168  138  delete from type_value where type = '(struct fd)->file';
 169  139  delete from type_value where type = '(struct fd)->flags';
 170  140  
↓ open down ↓ 20 lines elided ↑ open up ↑
 191  161  
 192  162  update return_states set return = '0-32,2147483648-2147483690' where function = '_parse_integer' and return = '0';
 193  163  update return_states set value = '0-u64max' where function = '_parse_integer' and type = 1025 and parameter = 2 and key = '*$';
 194  164  
 195  165  /* delete some function pointers which are sometimes byte units */
 196  166  delete from caller_info where function = '(struct i2c_algorithm)->master_xfer' and type = 1027;
 197  167  
 198  168  /* this if from READ_ONCE().  We can't know anything about the data.  */
 199  169  delete from type_info where key = '(union anonymous)->__val';
 200  170  
      171 +/* This is RIO_BAD_SIZE */
      172 +delete from return_states where file = 'drivers/rapidio/rio-access.c' and return = '129';
      173 +
      174 +/* Smatch sucks at loops */
      175 +delete from return_states where function = 'ata_dev_next' and type = 103;
      176 +
 201  177  EOF
 202  178  
 203  179  # fixme: this is totally broken
 204  180  call_id=$(echo "select distinct call_id from caller_info where function = '__kernel_write';" | sqlite3 $db_file)
 205  181  for id in $call_id ; do
 206      -    echo "insert into caller_info values ('fake', '', '__kernel_write', $id, 0, 1003, 1, '*\$', '');" | sqlite3 $db_file
      182 +    echo "insert into caller_info values ('fake', '', '__kernel_write', $id, 0, 8017, 1, '*\$', '');" | sqlite3 $db_file
 207  183  done
 208  184  
 209  185  for i in $(echo "select distinct return from return_states where function = 'clear_user';" | sqlite3 $db_file ) ; do
 210  186      echo "update return_states set return = \"$i[<=\$1]\" where return = \"$i\" and function = 'clear_user';" | sqlite3 $db_file
 211  187  done
 212  188  
 213  189  echo "select distinct file, function from function_ptr where ptr='(struct rtl_hal_ops)->set_hw_reg';" \
 214  190          | sqlite3 $db_file | sed -e 's/|/ /' | while read file function ; do
 215  191  
 216  192      drv=$(echo $file | perl -ne 's/.*\/rtlwifi\/(.*?)\/sw.c/$1/; print')
↓ open down ↓ 3 lines elided ↑ open up ↑
 220  196  
 221  197      echo "update caller_info
 222  198            set function = '$drv (struct rtl_hal_ops)->set_hw_reg'
 223  199            where function = '(struct rtl_hal_ops)->set_hw_reg' and file like 'drivers/net/wireless/rtlwifi/$drv/%';" \
 224  200           | sqlite3 $db_file
 225  201  
 226  202      echo "insert into function_ptr values ('$file', '$function', '$drv (struct rtl_hal_ops)->set_hw_reg', 1);" \
 227  203           | sqlite3 $db_file
 228  204  done
 229  205  
      206 +
      207 +for func in __kmalloc __kmalloc_track_caller ; do
      208 +
      209 +    cat << EOF | sqlite3 $db_file
      210 +delete from return_states where function = '$func';
      211 +insert into return_states values ('faked', '$func', 0, 1, '16', 0,    0,  -1, '', '');
      212 +insert into return_states values ('faked', '$func', 0, 1, '16', 0, 103,   0, '\$', '0');
      213 +insert into return_states values ('faked', '$func', 0, 2, '4096-ptr_max', 0,    0, -1, '', '');
      214 +insert into return_states values ('faked', '$func', 0, 2, '4096-ptr_max', 0, 103,  0, '\$', '1-4000000');
      215 +insert into return_states values ('faked', '$func', 0, 2, '4096-ptr_max', 0, 1037,  -1, '', 400);
      216 +insert into return_states values ('faked', '$func', 0, 3, '0', 0,    0,  -1, '', '');
      217 +insert into return_states values ('faked', '$func', 0, 3, '0', 0,    103,  0, '\$', '1-long_max');
      218 +EOF
      219 +done
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX