Skip to content
Snippets Groups Projects
  1. Dec 12, 2024
  2. Dec 06, 2024
  3. Dec 02, 2024
  4. Dec 01, 2024
    • Linus Torvalds's avatar
      strscpy: write destination buffer only once · 9022ed0e
      Linus Torvalds authored
      
      The point behind strscpy() was to once and for all avoid all the
      problems with 'strncpy()' and later broken "fixed" versions like
      strlcpy() that just made things worse.
      
      So strscpy not only guarantees NUL-termination (unlike strncpy), it also
      doesn't do unnecessary padding at the destination.  But at the same time
      also avoids byte-at-a-time reads and writes by _allowing_ some extra NUL
      writes - within the size, of course - so that the whole copy can be done
      with word operations.
      
      It is also stable in the face of a mutable source string: it explicitly
      does not read the source buffer multiple times (so an implementation
      using "strnlen()+memcpy()" would be wrong), and does not read the source
      buffer past the size (like the mis-design that is strlcpy does).
      
      Finally, the return value is designed to be simple and unambiguous: if
      the string cannot be copied fully, it returns an actual negative error,
      making error handling clearer and simpler (and the caller already knows
      the size of the buffer).  Otherwise it returns the string length of the
      result.
      
      However, there was one final stability issue that can be important to
      callers: the stability of the destination buffer.
      
      In particular, the same way we shouldn't read the source buffer more
      than once, we should avoid doing multiple writes to the destination
      buffer: first writing a potentially non-terminated string, and then
      terminating it with NUL at the end does not result in a stable result
      buffer.
      
      Yes, it gives the right result in the end, but if the rule for the
      destination buffer was that it is _always_ NUL-terminated even when
      accessed concurrently with updates, the final byte of the buffer needs
      to always _stay_ as a NUL byte.
      
      [ Note that "final byte is NUL" here is literally about the final byte
        in the destination array, not the terminating NUL at the end of the
        string itself. There is no attempt to try to make concurrent reads and
        writes give any kind of consistent string length or contents, but we
        do want to guarantee that there is always at least that final
        terminating NUL character at the end of the destination array if it
        existed before ]
      
      This is relevant in the kernel for the tsk->comm[] array, for example.
      Even without locking (for either readers or writers), we want to know
      that while the buffer contents may be garbled, it is always a valid C
      string and always has a NUL character at 'comm[TASK_COMM_LEN-1]' (and
      never has any "out of thin air" data).
      
      So avoid any "copy possibly non-terminated string, and terminate later"
      behavior, and write the destination buffer only once.
      
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      9022ed0e
    • Dr. David Alan Gilbert's avatar
      printf: Remove unused 'bprintf' · f69e6375
      Dr. David Alan Gilbert authored
      bprintf() is unused. Remove it. It was added in the commit 4370aa4a
      ("vsprintf: add binary printf") but as far as I can see was never used,
      unlike the other two functions in that patch.
      
      Link: https://lore.kernel.org/20241002173147.210107-1-linux@treblig.org
      
      
      Reviewed-by: default avatarAndy Shevchenko <andy@kernel.org>
      Acked-by: default avatarPetr Mladek <pmladek@suse.com>
      Signed-off-by: default avatarDr. David Alan Gilbert <linux@treblig.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      f69e6375
  5. Nov 28, 2024
  6. Nov 19, 2024
  7. Nov 16, 2024
  8. Nov 15, 2024
  9. Nov 12, 2024
    • Breno Leitao's avatar
      net: Implement fault injection forcing skb reallocation · 12079a59
      Breno Leitao authored and Paolo Abeni's avatar Paolo Abeni committed
      Introduce a fault injection mechanism to force skb reallocation. The
      primary goal is to catch bugs related to pointer invalidation after
      potential skb reallocation.
      
      The fault injection mechanism aims to identify scenarios where callers
      retain pointers to various headers in the skb but fail to reload these
      pointers after calling a function that may reallocate the data. This
      type of bug can lead to memory corruption or crashes if the old,
      now-invalid pointers are used.
      
      By forcing reallocation through fault injection, we can stress-test code
      paths and ensure proper pointer management after potential skb
      reallocations.
      
      Add a hook for fault injection in the following functions:
      
       * pskb_trim_rcsum()
       * pskb_may_pull_reason()
       * pskb_trim()
      
      As the other fault injection mechanism, protect it under a debug Kconfig
      called CONFIG_FAIL_SKB_REALLOC.
      
      This patch was *heavily* inspired by Jakub's proposal from:
      https://lore.kernel.org/all/20240719174140.47a868e6@kernel.org/
      
      
      
      CC: Akinobu Mita <akinobu.mita@gmail.com>
      Suggested-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
      Reviewed-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
      Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Acked-by: default avatarGuillaume Nault <gnault@redhat.com>
      Link: https://patch.msgid.link/20241107-fault_v6-v6-1-1b82cb6ecacd@debian.org
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      12079a59
    • Alexandru Ardelean's avatar
      lib: util_macros_kunit: add kunit test for util_macros.h · 11131415
      Alexandru Ardelean authored
      A bug was found in the find_closest() (find_closest_descending() is also
      affected after some testing), where for certain values with small
      progressions of 1, 2 & 3, the rounding (done by averaging 2 values) causes
      an incorrect index to be returned.
      
      The bug is described in more detail in the commit which fixes the bug. 
      This commit adds a kunit test to validate that the fix works correctly.
      
      This kunit test adds some of the arrays (from the driver-sphere) that seem
      to produce issues with the 'find_closest()' macro.  Specifically the one
      from ad7606 driver (with which the bug was found) and from the ina2xx
      drivers, which shows the quirk with 'find_closest()' with elements in a
      array that have an interval of 3.
      
      For the find_closest_descending() tests, the same arrays are used as for
      the find_closest(), but in reverse; the idea is that
      'find_closest_descending()' should return the sames indices as
      'find_closest()' but in reverse.
      
      For testing both macros, there are 4 special arrays created, one for
      testing find_closest{_descending}() for arrays of progressions 1, 2, 3 and
      4.  The idea is to show that (for progressions of 1, 2 & 3) the fix works
      as expected.  When removing the fix, the issues should start to show up.
      
      Then an extra array of negative and positive values is added.  There are
      currently no such arrays within drivers, but one could expect that these
      macros behave correctly even for such arrays.
      
      To run this kunit:
        ./tools/testing/kunit/kunit.py run "*util_macros*"
      
      Link: https://lkml.kernel.org/r/20241105145406.554365-2-aardelean@baylibre.com
      
      
      Signed-off-by: default avatarAlexandru Ardelean <aardelean@baylibre.com>
      Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      11131415
  10. Nov 11, 2024
  11. Nov 07, 2024
Loading