Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/check_spectre.c
          +++ new/usr/src/tools/smatch/src/check_spectre.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   * GNU General Public License for more details.
  13   13   *
  14   14   * You should have received a copy of the GNU General Public License
  15   15   * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
  16   16   */
  17   17  
  18   18  #include "smatch.h"
  19   19  #include "smatch_extra.h"
  20   20  
  21   21  static int my_id;
       22 +extern int second_half_id;
       23 +extern void set_spectre_first_half(struct expression *expr);
  22   24  
  23   25  static int suppress_multiple = 1;
  24   26  
  25   27  static int is_write(struct expression *expr)
  26   28  {
  27   29          return 0;
  28   30  }
  29   31  
  30   32  static int is_read(struct expression *expr)
  31   33  {
↓ open down ↓ 126 lines elided ↑ open up ↑
 158  160          expr = strip_expr(expr);
 159  161          if (!is_array(expr))
 160  162                  return;
 161  163  
 162  164          if (is_impossible_path())
 163  165                  return;
 164  166          if (is_harmless(expr))
 165  167                  return;
 166  168  
 167  169          array_expr = get_array_base(expr);
 168      -        if (suppress_multiple && is_ignored_expr(my_id, array_expr))
      170 +        if (suppress_multiple && is_ignored_expr(my_id, array_expr)) {
      171 +                set_spectre_first_half(expr);
 169  172                  return;
      173 +        }
 170  174  
 171  175          offset = get_array_offset(expr);
 172  176          if (!is_user_rl(offset))
 173  177                  return;
 174  178          if (is_nospec(offset))
 175  179                  return;
 176  180  
 177  181          array_size = get_array_size(array_expr);
 178  182          if (array_size > 0 && get_max_by_type(offset) < array_size)
 179  183                  return;
↓ open down ↓ 5 lines elided ↑ open up ↑
 185  189          if (mask <= array_size)
 186  190                  return;
 187  191  
 188  192          conditions = get_conditions(offset);
 189  193  
 190  194          name = expr_to_str(array_expr);
 191  195          sm_warning("potential spectre issue '%s' [%s]%s",
 192  196                 name,
 193  197                 is_read(expr) ? "r" : "w",
 194  198                 conditions ? " (local cap)" : "");
      199 +
      200 +        set_spectre_first_half(expr);
 195  201          if (suppress_multiple)
 196  202                  add_ignore_expr(my_id, array_expr);
 197  203          free_string(name);
 198  204  }
 199  205  
 200  206  void check_spectre(int id)
 201  207  {
 202  208          my_id = id;
 203  209  
 204  210          suppress_multiple = getenv("FULL_SPECTRE") == NULL;
 205  211  
 206  212          if (option_project != PROJ_KERNEL)
 207  213                  return;
 208  214  
 209  215          add_hook(&array_check, OP_HOOK);
 210  216  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX