13 Feb, 2019

1 commit

  • [ Upstream commit 0464ed24380905d640030d368cd84a4e4d1e15e2 ]

    Currently seq_buf_puts() will happily create a non null-terminated
    string for you in the buffer. This is particularly dangerous if the
    buffer is on the stack.

    For example:

    char buf[8];
    char secret = "secret";
    struct seq_buf s;

    seq_buf_init(&s, buf, sizeof(buf));
    seq_buf_puts(&s, "foo");
    printk("Message is %s\n", buf);

    Can result in:

    Message is fooªªªªªsecret

    We could require all users to memset() their buffer to zero before
    use. But that seems likely to be forgotten and lead to bugs.

    Instead we can change seq_buf_puts() to always leave the buffer in a
    null-terminated state.

    The only downside is that this makes the buffer 1 character smaller
    for seq_buf_puts(), but that seems like a good trade off.

    Link: http://lkml.kernel.org/r/20181019042109.8064-1-mpe@ellerman.id.au

    Acked-by: Kees Cook
    Signed-off-by: Michael Ellerman
    Signed-off-by: Steven Rostedt (VMware)
    Signed-off-by: Sasha Levin

    Michael Ellerman
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

24 Dec, 2015

1 commit

  • commit 5ac48378414d ("tracing: Use trace_seq_used() and seq_buf_used()
    instead of len") changed the tracing code to use trace_seq_used() and
    seq_buf_used() instead of using the seq_buf len directly to avoid
    overflow issues, but missed a spot in seq_buf_to_user() that makes use
    of s->len.

    Cleaned up the code a bit as well per suggestion of Steve Rostedt.

    Link: http://lkml.kernel.org/r/1447703848-2951-1-git-send-email-jsnitsel@redhat.com

    Signed-off-by: Jerry Snitselaar
    Signed-off-by: Steven Rostedt

    Jerry Snitselaar
     

05 Mar, 2015

1 commit

  • In seq_buf_bprintf(), bstr_printf() is used to copy the format into the
    buffer remaining in the seq_buf structure. The return of bstr_printf()
    is the amount of characters written to the buffer excluding the '\0',
    unless the line was truncated!

    If the line copied does not fit, it is truncated, and a '\0' is added
    to the end of the buffer. But in this case, '\0' is included in the length
    of the line written. To know if the buffer had overflowed, the return
    length will be the same or greater than the length of the buffer passed in.

    The check in seq_buf_bprintf() only checked if the length returned from
    bstr_printf() would fit in the buffer, as the seq_buf_bprintf() is only
    to be an all or nothing command. It either writes all the string into
    the seq_buf, or none of it. If the string is truncated, the pointers
    inside the seq_buf must be reset to what they were when the function was
    called. This is not the case. On overflow, it copies only part of the string.

    The fix is to change the overflow check to see if the length returned from
    bstr_printf() is less than the length remaining in the seq_buf buffer, and not
    if it is less than or equal to as it currently does. Then seq_buf_bprintf()
    will know if the write from bstr_printf() was truncated or not.

    Link: http://lkml.kernel.org/r/1425500481.2712.27.camel@perches.com

    Cc: stable@vger.kernel.org
    Reported-by: Joe Perches
    Signed-off-by: Steven Rostedt

    Steven Rostedt (Red Hat)
     

04 Mar, 2015

1 commit

  • In seq_buf_vprintf(), vsnprintf() is used to copy the format into the
    buffer remaining in the seq_buf structure. The return of vsnprintf()
    is the amount of characters written to the buffer excluding the '\0',
    unless the line was truncated!

    If the line copied does not fit, it is truncated, and a '\0' is added
    to the end of the buffer. But in this case, '\0' is included in the length
    of the line written. To know if the buffer had overflowed, the return
    length will be the same as the length of the buffer passed in.

    The check in seq_buf_vprintf() only checked if the length returned from
    vsnprintf() would fit in the buffer, as the seq_buf_vprintf() is only
    to be an all or nothing command. It either writes all the string into
    the seq_buf, or none of it. If the string is truncated, the pointers
    inside the seq_buf must be reset to what they were when the function was
    called. This is not the case. On overflow, it copies only part of the string.

    The fix is to change the overflow check to see if the length returned from
    vsnprintf() is less than the length remaining in the seq_buf buffer, and not
    if it is less than or equal to as it currently does. Then seq_buf_vprintf()
    will know if the write from vsnpritnf() was truncated or not.

    Cc: stable@vger.kernel.org
    Signed-off-by: Steven Rostedt

    Steven Rostedt (Red Hat)
     

14 Feb, 2015

1 commit

  • Now that all bitmap formatting usages have been converted to
    '%*pb[l]', the separate formatting functions are unnecessary. The
    following functions are removed.

    * bitmap_scn[list]printf()
    * cpumask_scnprintf(), cpulist_scnprintf()
    * [__]nodemask_scnprintf(), [__]nodelist_scnprintf()
    * seq_bitmap[_list](), seq_cpumask[_list](), seq_nodemask[_list]()
    * seq_buf_bitmask()

    Signed-off-by: Tejun Heo
    Cc: Rusty Russell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tejun Heo
     

20 Nov, 2014

1 commit

  • The seq_buf functions are rather useful outside of tracing. Instead
    of having it be dependent on CONFIG_TRACING, move the code into lib/
    and allow other users to have access to it even when tracing is not
    configured.

    The seq_buf utility is similar to the seq_file utility, but instead of
    writing sending data back up to userland, it writes it into a buffer
    defined at seq_buf_init(). This allows us to send a descriptor around
    that writes printf() formatted strings into it that can be retrieved
    later.

    It is currently used by the tracing facility for such things like trace
    events to convert its binary saved data in the ring buffer into an
    ASCII human readable context to be displayed in /sys/kernel/debug/trace.

    It can also be used for doing NMI prints safely from NMI context into
    the seq_buf and retrieved later and dumped to printk() safely. Doing
    printk() from an NMI context is dangerous because an NMI can preempt
    a current printk() and deadlock on it.

    Link: http://lkml.kernel.org/p/20140619213952.058255809@goodmis.org

    Tested-by: Jiri Kosina
    Acked-by: Jiri Kosina
    Reviewed-by: Petr Mladek
    Signed-off-by: Steven Rostedt

    Steven Rostedt (Red Hat)