1. 10 Apr, 2020 1 commit
    • Vasily Averin's avatar
      fs/seq_file.c: seq_read(): add info message about buggy .next functions · 3bfa7e14
      Vasily Averin authored
      Patch series "seq_file .next functions should increase position index".
      In Aug 2018 NeilBrown noticed commit 1f4aace6 ("fs/seq_file.c:
      simplify seq_file iteration code and interface")
      "Some ->next functions do not increment *pos when they return NULL...
      Note that such ->next functions are buggy and should be fixed.  A simple
      demonstration is dd if=/proc/swaps bs=1000 skip=1 Choose any block size
      larger than the size of /proc/swaps.  This will always show the whole
      last line of /proc/swaps"
      Described problem is still actual.  If you make lseek into middle of
      last output line following read will output end of last line and whole
      last line once again.
        $ dd if=/proc/swaps bs=1  # usual output
        Filename				Type		Size	Used	Priority
        /dev/dm-0                             partition	4194812	97536	-2
        104+0 records in
        104+0 records out
        104 bytes copied
        $ dd if=/proc/swaps bs=40 skip=1    # last line was generated twice
        dd: /proc/swaps: cannot skip to specified offset
        v/dm-0                                partition	4194812	97536	-2
        /dev/dm-0                             partition	4194812	97536	-2
        3+1 records in
        3+1 records out
        131 bytes copied
      There are lot of other affected files, I've found 30+ including
      /proc/net/ip_tables_matches and /proc/sysvipc/*
      I've sent patches into maillists of affected subsystems already, this
      patch-set fixes the problem in files related to pstore, tracing, gcov,
      sysvipc and other subsystems processed via linux-kernel@ mailing list
      This patch (of 4):
      Add debug code to seq_read() to detect missed or out-of-tree incorrect
      .next seq_file functions.
      [akpm@linux-foundation.org: s/pr_info/pr_info_ratelimited/, per Qian Cai]
      Signed-off-by: default avatarVasily Averin <vvs@virtuozzo.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Cc: NeilBrown <neilb@suse.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Manfred Spraul <manfred@colorfullife.com>
      Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
      Cc: Waiman Long <longman@redhat.com>
      Link: http://lkml.kernel.org/r/244674e5-760c-86bd-d08a-047042881748@virtuozzo.com
      Link: http://lkml.kernel.org/r/7c24087c-e280-e580-5b0c-0cdaeb14cd18@virtuozzo.com
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  2. 07 Apr, 2020 1 commit
  3. 13 Aug, 2019 1 commit
  4. 03 Jul, 2019 1 commit
    • J. Bruce Fields's avatar
      nfsd: escape high characters in binary data · ea053e16
      J. Bruce Fields authored
      I'm exposing some information about NFS clients in pseudofiles.  I
      expect to eventually have simple tools to help read those pseudofiles.
      But it's also helpful if the raw files are human-readable to the extent
      possible.  It aids debugging and makes them usable on systems that don't
      have the latest nfs-utils.
      A minor challenge there is opaque client-generated protocol objects like
      state owners and client identifiers.  Some clients generate those to
      include handy information in plain ascii.  But they may also include
      arbitrary byte sequences.
      I think the simplest approach is to limit to isprint(c) && isascii(c)
      and escape everything else.
      That means you can just cat the file and get something that looks OK.
      Also, I'm trying to keep these files legal YAML, which requires them to
      UTF-8, and this is a simple way to guarantee that.
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
  5. 08 Apr, 2019 1 commit
    • Gustavo A. R. Silva's avatar
      fs: mark expected switch fall-throughs · 0a4c9265
      Gustavo A. R. Silva authored
      In preparation to enabling -Wimplicit-fallthrough, mark switch cases
      where we are expecting to fall through.
      This patch fixes the following warnings:
      fs/affs/affs.h:124:38: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/configfs/dir.c:1692:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/configfs/dir.c:1694:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ceph/file.c:249:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/hash.c:233:15: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/hash.c:246:15: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext2/inode.c:1237:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext2/inode.c:1244:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/indirect.c:1182:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/indirect.c:1188:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/indirect.c:1432:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ext4/indirect.c:1440:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/f2fs/node.c:618:8: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/f2fs/node.c:620:8: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/btrfs/ref-verify.c:522:15: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/gfs2/bmap.c:711:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/gfs2/bmap.c:722:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/jffs2/fs.c:339:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/nfsd/nfs4proc.c:429:12: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ufs/util.h:62:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/ufs/util.h:43:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/fcntl.c:770:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/seq_file.c:319:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/libfs.c:148:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/libfs.c:150:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/signalfd.c:178:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
      fs/locks.c:1473:16: warning: this statement may fall through [-Wimplicit-fallthrough=]
      Warning level 3 was used: -Wimplicit-fallthrough=3
      This patch is part of the ongoing efforts to enabling
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
  6. 17 Aug, 2018 1 commit
    • NeilBrown's avatar
      fs/seq_file.c: simplify seq_file iteration code and interface · 1f4aace6
      NeilBrown authored
      The documentation for seq_file suggests that it is necessary to be able
      to move the iterator to a given offset, however that is not the case.
      If the iterator is stored in the private data and is stable from one
      read() syscall to the next, it is only necessary to support first/next
      interactions.  Implementing this in a client is a little clumsy.
       - if ->start() is given a pos of zero, it should go to start of
       - if ->start() is given the name pos that was given to the most recent
         next() or start(), it should restore the iterator to state just
         before that last call
       - if ->start is given another number, it should set the iterator one
         beyond the start just before the last ->start or ->next call.
      Also, the documentation says that the implementation can interpret the
      pos however it likes (other than zero meaning start), but seq_file
      increments the pos sometimes which does impose on the implementation.
      This patch simplifies the interface for first/next iteration and
      simplifies the code, while maintaining complete backward compatability.
       - if ->start() is given a pos of zero, it should return an iterator
         placed at the start of the sequence
       - if ->start() is given a non-zero pos, it should return the iterator
         in the same state it was after the last ->start or ->next.
      This is particularly useful for interators which walk the multiple
      chains in a hash table, e.g.  using rhashtable_walk*.  See
      fs/gfs2/glock.c and drivers/staging/lustre/lustre/llite/vvp_dev.c
      A large part of achieving this is to *always* call ->next after ->show
      has successfully stored all of an entry in the buffer.  Never just
      increment the index instead.  Also:
       - always pass &m->index to ->start() and ->next(), never a temp
       - don't clear ->from when ->count is zero, as ->from is dead when
         ->count is zero.
      Some ->next functions do not increment *pos when they return NULL.  To
      maintain compatability with this, we still need to increment m->index in
      one place, if ->next didn't increment it.  Note that such ->next
      functions are buggy and should be fixed.  A simple demonstration is
         dd if=/proc/swaps bs=1000 skip=1
      Choose any block size larger than the size of /proc/swaps.  This will
      always show the whole last line of /proc/swaps.
      This patch doesn't work around buggy next() functions for this case.
      [neilb@suse.com: ensure ->from is valid]
        Link: http://lkml.kernel.org/r/87601ryb8a.fsf@notabene.neil.brown.name
      Signed-off-by: default avatarNeilBrown <neilb@suse.com>
      Acked-by: Jonathan Corbet <corbet@lwn.net>	[docs]
      Tested-by: default avatarJann Horn <jannh@google.com>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: Kees Cook <keescook@chromium.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  7. 26 May, 2018 1 commit
  8. 11 Apr, 2018 6 commits
  9. 20 Jan, 2018 1 commit
  10. 02 Nov, 2017 1 commit
    • Greg Kroah-Hartman's avatar
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman authored
      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 <5
      All documentation files were explicitly excluded.
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
         For non */uapi/* files that summary was:
         SPDX license identifier                            # files
         GPL-2.0                                              11139
         and resulted in the first patch in this series.
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
         SPDX license identifier                            # files
         GPL-2.0 WITH Linux-syscall-note                        930
         and resulted in the second patch in this series.
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
         SPDX license identifier                            # files
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
         and that resulted in the third patch in this series.
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      Reviewed-by: default avatarKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: default avatarPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
  11. 09 May, 2017 1 commit
    • Michal Hocko's avatar
      mm: introduce kv[mz]alloc helpers · a7c3e901
      Michal Hocko authored
      Patch series "kvmalloc", v5.
      There are many open coded kmalloc with vmalloc fallback instances in the
      tree.  Most of them are not careful enough or simply do not care about
      the underlying semantic of the kmalloc/page allocator which means that
      a) some vmalloc fallbacks are basically unreachable because the kmalloc
      part will keep retrying until it succeeds b) the page allocator can
      invoke a really disruptive steps like the OOM killer to move forward
      which doesn't sound appropriate when we consider that the vmalloc
      fallback is available.
      As it can be seen implementing kvmalloc requires quite an intimate
      knowledge if the page allocator and the memory reclaim internals which
      strongly suggests that a helper should be implemented in the memory
      subsystem proper.
      Most callers, I could find, have been converted to use the helper
      instead.  This is patch 6.  There are some more relying on __GFP_REPEAT
      in the networking stack which I have converted as well and Eric Dumazet
      was not...
  12. 24 Dec, 2016 1 commit
  13. 23 Dec, 2016 1 commit
  14. 08 Oct, 2016 1 commit
  15. 27 Aug, 2016 1 commit
    • Vegard Nossum's avatar
      fs/seq_file: fix out-of-bounds read · 088bf2ff
      Vegard Nossum authored
      seq_read() is a nasty piece of work, not to mention buggy.
      It has (I think) an old bug which allows unprivileged userspace to read
      beyond the end of m->buf.
      I was getting these:
          BUG: KASAN: slab-out-of-bounds in seq_read+0xcd2/0x1480 at addr ffff880116889880
          Read of size 2713 by task trinity-c2/1329
          CPU: 2 PID: 1329 Comm: trinity-c2 Not tainted 4.8.0-rc1+ #96
          Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org 04/01/2014
          Call Trace:
          Object at ffff880116889100, in cache kmalloc-4096 size: 4096
          PID = 1329
          PID = 0
          (stack is not available)
          Memory state around the buggy address:
           ffff88011688a000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           ffff88011688a080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
          >ffff88011688a100: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
           ffff88011688a180: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
           ffff88011688a200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
          Disabling lock debugging due to kernel taint
      This seems to be the same thing that Dave Jones was seeing here:
      There are multiple issues here:
        1) If we enter the function with a non-empty buffer, there is an attempt
           to flush it. But it was not clearing m->from after doing so, which
           means that if we try to do this flush twice in a row without any call
           to traverse() in between, we are going to be reading from the wrong
           place -- the splat above, fixed by this patch.
        2) If there's a short write to userspace because of page faults, the
           buffer may already contain multiple lines (i.e. pos has advanced by
           more than 1), but we don't save the progress that was made so the
           next call will output what we've already returned previously. Since
           that is a much less serious issue (and I have a headache after
           staring at seq_read() for the past 8 hours), I'll leave that for now.
      Link: http://lkml.kernel.org/r/1471447270-32093-1-git-send-email-vegard.nossum@oracle.com
      Signed-off-by: default avatarVegard Nossum <vegard.nossum@oracle.com>
      Reported-by: default avatarDave Jones <davej@codemonkey.org.uk>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  16. 14 Apr, 2016 1 commit
    • Linus Torvalds's avatar
      Make file credentials available to the seqfile interfaces · 34dbbcdb
      Linus Torvalds authored
      A lot of seqfile users seem to be using things like %pK that uses the
      credentials of the current process, but that is actually completely
      wrong for filesystem interfaces.
      The unix semantics for permission checking files is to check permissions
      at _open_ time, not at read or write time, and that is not just a small
      detail: passing off stdin/stdout/stderr to a suid application and making
      the actual IO happen in privileged context is a classic exploit
      So if we want to be able to look at permissions at read time, we need to
      use the file open credentials, not the current ones.  Normal file
      accesses can just use "f_cred" (or any of the helper functions that do
      that, like file_ns_capable()), but the seqfile interfaces do not have
      any such options.
      It turns out that seq_file _does_ save away the user_ns information of
      the file, though.  Since user_ns is just part of the full credential
      information, replace that special case with saving off the cred pointer
      instead, and suddenly seq_file has all the permission information it
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  17. 07 Nov, 2015 3 commits
  18. 11 Sep, 2015 1 commit
    • Joe Perches's avatar
      fs/seq_file: convert int seq_vprint/seq_printf/etc... returns to void · 6798a8ca
      Joe Perches authored
      The seq_<foo> function return values were frequently misused.
      See: commit 1f33c41c
       ("seq_file: Rename seq_overflow() to
           seq_has_overflowed() and make public")
      All uses of these return values have been removed, so convert the
      return types to void.
      o Move seq_put_decimal_<type> and seq_escape prototypes closer the
        other seq_vprintf prototypes
      o Reorder seq_putc and seq_puts to return early on overflow
      o Add argument names to seq_vprintf and seq_printf
      o Update the seq_escape kernel-doc
      o Convert a couple of leading spaces to tabs in seq_escape
      Signed-off-by: default avatarJoe Perches <joe@perches.com>
      Cc: Al Viro <viro@ZenIV.linux.org.uk>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Mark Brown <broonie@kernel.org>
      Cc: Stephen Rothwell <sfr@canb.auug.org.au>
      Cc: Joerg Roedel <jroedel@suse.de>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  19. 10 Sep, 2015 1 commit
  20. 01 Jul, 2015 2 commits
  21. 23 Jun, 2015 1 commit
  22. 03 Jun, 2015 1 commit
  23. 14 Feb, 2015 1 commit
  24. 13 Dec, 2014 1 commit
    • David Rientjes's avatar
      fs, seq_file: fallback to vmalloc instead of oom kill processes · 5cec38ac
      David Rientjes authored
      Since commit 058504ed
       ("fs/seq_file: fallback to vmalloc allocation"),
      seq_buf_alloc() falls back to vmalloc() when the kmalloc() for contiguous
      memory fails.  This was done to address order-4 slab allocations for
      reading /proc/stat on large machines and noticed because
      PAGE_ALLOC_COSTLY_ORDER < 4, so there is no infinite loop in the page
      allocator when allocating new slab for such high-order allocations.
      Contiguous memory isn't necessary for caller of seq_buf_alloc(), however.
      Other GFP_KERNEL high-order allocations that are <=
      PAGE_ALLOC_COSTLY_ORDER will simply loop forever in the page allocator and
      oom kill processes as a result.
      We don't want to kill processes so that we can allocate contiguous memory
      in situations when contiguous memory isn't necessary.
      This patch does the kmalloc() allocation with __GFP_NORETRY for high-order
      allocations.  This still utilizes memory compaction and direct reclaim in
      the allocation path, the only difference is that it will fail immediately
      instead of oom kill processes when out of memory.
      [akpm@linux-foundation.org: add comment]
      Signed-off-by: default avatarDavid Rientjes <rientjes@google.com>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  25. 30 Oct, 2014 1 commit
  26. 03 Jul, 2014 1 commit
    • Heiko Carstens's avatar
      fs/seq_file: fallback to vmalloc allocation · 058504ed
      Heiko Carstens authored
      There are a couple of seq_files which use the single_open() interface.
      This interface requires that the whole output must fit into a single
      E.g.  for /proc/stat allocation failures have been observed because an
      order-4 memory allocation failed due to memory fragmentation.  In such
      situations reading /proc/stat is not possible anymore.
      Therefore change the seq_file code to fallback to vmalloc allocations
      which will usually result in a couple of order-0 allocations and hence
      also work if memory is fragmented.
      For reference a call trace where reading from /proc/stat failed:
        sadc: page allocation failure: order:4, mode:0x1040d0
        CPU: 1 PID: 192063 Comm: sadc Not tainted 3.10.0-123.el7.s390x #1
        Call Trace:
      Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Tested-by: default avatarDavid Rientjes <rientjes@google.com>
      Cc: Ian Kent <raven@themaw.net>
      Cc: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
      Cc: Thorsten Diehl <thorsten.diehl@de.ibm.com>
      Cc: Andrea Righi <andrea@betterlinux.com>
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Stefan Bader <stefan.bader@canonical.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  27. 19 Nov, 2013 1 commit
  28. 15 Nov, 2013 1 commit
  29. 25 Oct, 2013 1 commit
    • Gu Zheng's avatar
      seq_file: always update file->f_pos in seq_lseek() · 05e16745
      Gu Zheng authored
      This issue was first pointed out by Jiaxing Wang several months ago, but no
      further comments:
      As we know pread() does not change f_pos, so after pread(), file->f_pos
      and m->read_pos become different. And seq_lseek() does not update file->f_pos
      if offset equals to m->read_pos, so after pread() and seq_lseek()(lseek to
      m->read_pos), then a subsequent read may read from a wrong position, the
      following program produces the problem:
          char str1[32] = { 0 };
          char str2[32] = { 0 };
          int poffset = 10;
          int count = 20;
          /*open any seq file*/
          int fd = open("/proc/modules", O_RDONLY);
          pread(fd, str1, count, poffset);
          printf("pread:%s\n", str1);
          /*seek to where m->read_pos is*/
          lseek(fd, poffset+count, SEEK_SET);
          /*supposed to read from poffset+count, but this read from position 0*/
          read(fd, str2, count);
          printf("read:%s\n", str2);
      out put:
       ck_netbios_ns 12665
      nf_conntrack_netbios_ns 12665 0 - Live 0xffffffffa038b000
      nf_conntrack_broadcast 12589 1 nf_conntrack_netbios_ns, Live 0xffffffffa0386000
      So we always update file->f_pos to offset in seq_lseek() to fix this issue.
      Signed-off-by: default avatarJiaxing Wang <hello.wjx@gmail.com>
      Signed-off-by: default avatarGu Zheng <guz.fnst@cn.fujitsu.com>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
  30. 08 Jul, 2013 1 commit
  31. 09 Apr, 2013 1 commit
    • Al Viro's avatar
      new helper: single_open_size() · 2043f495
      Al Viro authored
      Same as single_open(), but preallocates the buffer of given size.
      Doesn't make any sense for sizes up to PAGE_SIZE and doesn't make
      sense if output of show() exceeds PAGE_SIZE only rarely - seq_read()
      will take care of growing the buffer and redoing show().  If you
      _know_ that it will be large, it might make more sense to look into
      saner iterator, rather than go with single-shot one.  If that's
      impossible, single_open_size() might be for you.
      Again, don't use that without a good reason; occasionally that's really
      the best way to go, but very often there are better solutions.
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
  32. 28 Feb, 2013 1 commit