1. 28 11月, 2022 12 次提交
  2. 10 11月, 2022 17 次提交
  3. 12 10月, 2022 1 次提交
    • J
      treewide: use prandom_u32_max() when possible, part 1 · 81895a65
      Jason A. Donenfeld 提交于
      Rather than incurring a division or requesting too many random bytes for
      the given range, use the prandom_u32_max() function, which only takes
      the minimum required bytes from the RNG and avoids divisions. This was
      done mechanically with this coccinelle script:
      
      @basic@
      expression E;
      type T;
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      typedef u64;
      @@
      (
      - ((T)get_random_u32() % (E))
      + prandom_u32_max(E)
      |
      - ((T)get_random_u32() & ((E) - 1))
      + prandom_u32_max(E * XXX_MAKE_SURE_E_IS_POW2)
      |
      - ((u64)(E) * get_random_u32() >> 32)
      + prandom_u32_max(E)
      |
      - ((T)get_random_u32() & ~PAGE_MASK)
      + prandom_u32_max(PAGE_SIZE)
      )
      
      @multi_line@
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      identifier RAND;
      expression E;
      @@
      
      -       RAND = get_random_u32();
              ... when != RAND
      -       RAND %= (E);
      +       RAND = prandom_u32_max(E);
      
      // Find a potential literal
      @literal_mask@
      expression LITERAL;
      type T;
      identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
      position p;
      @@
      
              ((T)get_random_u32()@p & (LITERAL))
      
      // Add one to the literal.
      @script:python add_one@
      literal << literal_mask.LITERAL;
      RESULT;
      @@
      
      value = None
      if literal.startswith('0x'):
              value = int(literal, 16)
      elif literal[0] in '123456789':
              value = int(literal, 10)
      if value is None:
              print("I don't know how to handle %s" % (literal))
              cocci.include_match(False)
      elif value == 2**32 - 1 or value == 2**31 - 1 or value == 2**24 - 1 or value == 2**16 - 1 or value == 2**8 - 1:
              print("Skipping 0x%x for cleanup elsewhere" % (value))
              cocci.include_match(False)
      elif value & (value + 1) != 0:
              print("Skipping 0x%x because it's not a power of two minus one" % (value))
              cocci.include_match(False)
      elif literal.startswith('0x'):
              coccinelle.RESULT = cocci.make_expr("0x%x" % (value + 1))
      else:
              coccinelle.RESULT = cocci.make_expr("%d" % (value + 1))
      
      // Replace the literal mask with the calculated result.
      @plus_one@
      expression literal_mask.LITERAL;
      position literal_mask.p;
      expression add_one.RESULT;
      identifier FUNC;
      @@
      
      -       (FUNC()@p & (LITERAL))
      +       prandom_u32_max(RESULT)
      
      @collapse_ret@
      type T;
      identifier VAR;
      expression E;
      @@
      
       {
      -       T VAR;
      -       VAR = (E);
      -       return VAR;
      +       return E;
       }
      
      @drop_var@
      type T;
      identifier VAR;
      @@
      
       {
      -       T VAR;
              ... when != VAR
       }
      Reviewed-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Reviewed-by: NYury Norov <yury.norov@gmail.com>
      Reviewed-by: NKP Singh <kpsingh@kernel.org>
      Reviewed-by: Jan Kara <jack@suse.cz> # for ext4 and sbitmap
      Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> # for drbd
      Acked-by: NJakub Kicinski <kuba@kernel.org>
      Acked-by: Heiko Carstens <hca@linux.ibm.com> # for s390
      Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # for mmc
      Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      81895a65
  4. 11 10月, 2022 1 次提交
    • J
      wifi: iwlwifi: mvm: fix double list_add at iwl_mvm_mac_wake_tx_queue (other cases) · 95b0f666
      Jose Ignacio Tornos Martinez 提交于
      BUGs like this are still reproducible:
      
      [   31.509616] list_add corruption. prev->next should be next (ffff8f8644242300), but was ffff8f86493fd300. (prev=ffff8f86493fd300).
      [   31.521544] ------------[ cut here ]------------
      [   31.526248] kernel BUG at lib/list_debug.c:30!
      [   31.530781] invalid opcode: 0000 [#1] PREEMPT SMP PTI
      [   31.535831] CPU: 1 PID: 626 Comm: wpa_supplicant Not tainted 6.0.0+ #7
      [   31.542450] Hardware name: Dell Inc. Inspiron 660s/0478VN       , BIOS A07 08/24/2012
      [   31.550484] RIP: 0010:__list_add_valid.cold+0x3a/0x5b
      [   31.555537] Code: f2 4c 89 c1 48 89 fe 48 c7 c7 28 20 69 89 e8 4c e3 fd ff 0f 0b 48 89 d1 4c 89 c6 4c 89 ca 48 c7 c7 d0 1f 69 89 e8 35 e3 fd ff <0f> 0b 4c 89 c1 48 c7 c7 78 1f 69 89 e8 24 e3 fd ff 0f 0b 48 c7 c7
      [   31.574605] RSP: 0018:ffff9f6f00dc3748 EFLAGS: 00010286
      [   31.579990] RAX: 0000000000000075 RBX: ffff8f8644242080 RCX: 0000000000000000
      [   31.587155] RDX: 0000000000000201 RSI: ffffffff8967862d RDI: 00000000ffffffff
      [   31.594482] RBP: ffff8f86493fd2e8 R08: 0000000000000000 R09: 00000000ffffdfff
      [   31.601735] R10: ffff9f6f00dc3608 R11: ffffffff89f46128 R12: ffff8f86493fd300
      [   31.608986] R13: ffff8f86493fd300 R14: ffff8f8644242300 R15: ffff8f8643dd3f2c
      [   31.616151] FS:  00007f3bb9a707c0(0000) GS:ffff8f865a300000(0000) knlGS:0000000000000000
      [   31.624447] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [   31.630286] CR2: 00007fe3647d5600 CR3: 00000001125a6002 CR4: 00000000000606e0
      [   31.637539] Call Trace:
      [   31.639936]  <TASK>
      [   31.642143]  iwl_mvm_mac_wake_tx_queue+0x71/0x90 [iwlmvm]
      [   31.647569]  ieee80211_queue_skb+0x4b6/0x720 [mac80211]
      ...
      
      So, it is necessary to extend the applied solution with commit 14a3aacf
      ("iwlwifi: mvm: fix double list_add at iwl_mvm_mac_wake_tx_queue")
      to all other cases where the station queues are invalidated and the related
      lists are not emptied. Because, otherwise as before, if some new element is
      added later to the list in iwl_mvm_mac_wake_tx_queue, it can match with the
      old one and produce the same commented BUG.
      
      That is, in order to avoid this problem completely, we must also remove the
      related lists for the other cases when station queues are invalidated.
      
      Fixes: cfbc6c4c ("iwlwifi: mvm: support mac80211 TXQs model")
      Reported-by: NPetr Stourac <pstourac@redhat.com>
      Tested-by: NPetr Stourac <pstourac@redhat.com>
      Signed-off-by: NJose Ignacio Tornos Martinez <jtornosm@redhat.com>
      Signed-off-by: NKalle Valo <kvalo@kernel.org>
      Link: https://lore.kernel.org/r/20221010081611.145027-1-jtornosm@redhat.com
      95b0f666
  5. 10 10月, 2022 1 次提交
  6. 29 9月, 2022 1 次提交
  7. 28 9月, 2022 1 次提交
    • K
      wifi: iwlwifi: Track scan_cmd allocation size explicitly · 72c08d9f
      Kees Cook 提交于
      In preparation for reducing the use of ksize(), explicitly track the
      size of scan_cmd allocations. This also allows for noticing if the scan
      size changes unexpectedly. Note that using ksize() was already incorrect
      here, in the sense that ksize() would not match the actual allocation
      size, which would trigger future run-time allocation bounds checking.
      (In other words, memset() may know how large scan_cmd was allocated for,
      but ksize() will return the upper bounds of the actually allocated memory,
      causing a run-time warning about an overflow.)
      
      Cc: Gregory Greenman <gregory.greenman@intel.com>
      Cc: Kalle Valo <kvalo@kernel.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Paolo Abeni <pabeni@redhat.com>
      Cc: Luca Coelho <luciano.coelho@intel.com>
      Cc: Johannes Berg <johannes.berg@intel.com>
      Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
      Cc: Miri Korenblit <miriam.rachel.korenblit@intel.com>
      Cc: Ilan Peer <ilan.peer@intel.com>
      Cc: linux-wireless@vger.kernel.org
      Cc: netdev@vger.kernel.org
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NKalle Valo <kvalo@kernel.org>
      Link: https://lore.kernel.org/r/20220923220853.3302056-1-keescook@chromium.org
      72c08d9f
  8. 18 9月, 2022 6 次提交