Skip to content
Snippets Groups Projects
  1. Dec 29, 2023
    • Dmitry Safonov's avatar
      gen_init_cpio: Apply mtime supplied by user to all file types · f3b2306b
      Dmitry Safonov authored
      
      Currently gen_init_cpio -d <timestamp> is applied to symlinks,
      directories and special files. These files are created by
      gen_init_cpio from their description. Without <timestamp> option
      current time(NULL) is used. And regular files that go in initramfs
      are created before cpio generation, so their mtime(s) are preserved.
      
      This is usually not an issue as reproducible builds should rebuild
      everything in the distribution, including binaries, configs and whatever
      other regular files may find their way into kernel's initramfs.
      
      On the other hand, gen_initramfs.sh usage claims:
      >	-d <date>      Use date for all file mtime values
      
      Ar Arista initramfs files are managed with version control system
      that preserves mtime. Those are configs, boot parameters, init scripts,
      version files, platform-specific files, probably some others, too.
      
      While it's certainly possible to work this around by copying the file
      into temp directory and adjusting mtime prior to gen_init_cpio call,
      I don't see why it needs workarounds.
      
      The intended user of -d <date> option is the one that needs to create
      a reproducible build, see commit a8b8017c ("initramfs: Use
      KBUILD_BUILD_TIMESTAMP for generated entries"). If a user wants
      the build reproduction, they use -d <date>, which can be set on all
      types of files, without surprising exceptions and workarounds.
      Let's KISS here and just apply the time that user specified
      with -d option.
      
      Based-on-a-patch-by: default avatarBaptiste Covolato <baptiste@arista.com>
      Link: https://lore.kernel.org/lkml/20181025215133.20138-1-baptiste@arista.com/
      
      
      Signed-off-by: default avatarDmitry Safonov <dima@arista.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      f3b2306b
  2. Apr 16, 2023
  3. Oct 03, 2022
  4. May 10, 2022
  5. Oct 24, 2021
    • Nicolas Schier's avatar
      initramfs: Check timestamp to prevent broken cpio archive · 4c9d410f
      Nicolas Schier authored
      
      Cpio format reserves 8 bytes for an ASCII representation of a time_t timestamp.
      While 2106-02-07 06:28:15 UTC (time_t = 0xffffffff) is still some years in the
      future, a poorly chosen date string for KBUILD_BUILD_TIMESTAMP, converted into
      seconds since the epoch, might lead to exceeded cpio timestamp limits that
      result in a broken cpio archive.  Add timestamp checks to prevent overrun of
      the 8-byte cpio header field.
      
      My colleague Thomas Kühnel discovered the behaviour, when we accidentally fed
      SOURCE_DATE_EPOCH to KBUILD_BUILD_TIMESTAMP as is: some timestamps (e.g.
      1607420928 = 2021-12-08 9:48:48 UTC) will be interpreted by `date` as a valid
      date specification of science fictional times (here: year 160742).  Even though
      this is bad input for KBUILD_BUILD_TIMESTAMP, it should not break the initramfs
      cpio format.
      
      Signed-off-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      Cc: Thomas Kühnel <thomas.kuehnel@avm.de>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      4c9d410f
  6. Oct 13, 2021
  7. Nov 02, 2017
    • 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
         lines).
      
      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>
      b2441318
  8. Nov 13, 2013
    • Michal Nazarewicz's avatar
      gen_init_cpio: avoid NULL pointer dereference and rework env expanding · c725ee54
      Michal Nazarewicz authored
      
      getenv() may return NULL if given environment variable does not exist
      which leads to NULL dereference when calling strncat.
      
      Besides that, the environment variable name was copied to a temporary
      env_var buffer, but this copying can be avoided by simply using the input
      string.
      
      Lastly, the whole loop can be greatly simplified by using the snprintf
      function instead of the playing with strncat.
      
       By the way, the current implementation allows a recursive variable
       expansion, as in:
      
         $ echo 'out ${A} out ' | A='a ${B} a' B=b /tmp/a
         out a b a out
      
       I'm assuming this is just a side effect and not a conscious decision
       (especially as this may lead to infinite loop), but I didn't want to
       change this behaviour without consulting.
      
       If the current behaviour is deamed incorrect, I'll be happy to send
       a patch without recursive processing.
      
      Signed-off-by: default avatarMichal Nazarewicz <mina86@mina86.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Jiri Kosina <jkosina@suse.cz>
      Cc: Jesper Juhl <jj@codesealer.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      c725ee54
  9. Nov 19, 2012
  10. Oct 25, 2012
    • Kees Cook's avatar
      gen_init_cpio: avoid stack overflow when expanding · 20f1de65
      Kees Cook authored
      
      Fix possible overflow of the buffer used for expanding environment
      variables when building file list.
      
      In the extremely unlikely case of an attacker having control over the
      environment variables visible to gen_init_cpio, control over the
      contents of the file gen_init_cpio parses, and gen_init_cpio was built
      without compiler hardening, the attacker can gain arbitrary execution
      control via a stack buffer overflow.
      
        $ cat usr/crash.list
        file foo ${BIG}${BIG}${BIG}${BIG}${BIG}${BIG} 0755 0 0
        $ BIG=$(perl -e 'print "A" x 4096;') ./usr/gen_init_cpio usr/crash.list
        *** buffer overflow detected ***: ./usr/gen_init_cpio terminated
      
      This also replaces the space-indenting with tabs.
      
      Patch based on existing fix extracted from grsecurity.
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Michal Marek <mmarek@suse.cz>
      Cc: Brad Spengler <spender@grsecurity.net>
      Cc: PaX Team <pageexec@freemail.hu>
      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>
      20f1de65
  11. Apr 18, 2011
  12. Jan 05, 2011
  13. Dec 29, 2010
  14. Dec 02, 2010
    • Thomas Chou's avatar
      gen_init_cpio: remove leading `/' from file names · 43f901fb
      Thomas Chou authored
      
      When we extracted the generated cpio archive using "cpio -id" command,
      it complained,
      
      cpio: Removing leading `/' from member names
      var/run
      cpio: Removing leading `/' from member names
      var/lib
      cpio: Removing leading `/' from member names
      var/lib/misc
      
      It is worse with the latest "cpio" or "pax", which tries to overwrite
      the host file system with the leading '/'.
      
      So the leading '/' of file names should be removed. This is consistent
      with the initramfs come with major distributions such as Fedora or
      Debian, etc.
      
      Signed-off-by: default avatarThomas Chou <thomas@wytron.com.tw>
      Acked-by: default avatarMike <Frysinger&lt;vapier@gentoo.org>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>
      43f901fb
  15. Dec 12, 2009
  16. Sep 23, 2009
  17. Dec 03, 2008
    • Sally, Gene's avatar
      kbuild: gen_init_cpio expands shell variables in file names · 3b1ec9fb
      Sally, Gene authored and Sam Ravnborg's avatar Sam Ravnborg committed
      
      Modify gen_init_cpio so that lines that specify files can contain
      what looks like a shell variable that's expanded during processing.
      
      For example:
      
         file /sbin/kinit ${RFS_BASE}/usr/src/klibc/kinit/kinit 0755 0 0
      
      given RFS_BASE is "/some/directory" in the environment
      
      would be expanded to
      
         file /sbin/kinit /some/directory/usr/src/klibc/kinit/kinit 0755 0 0
      
      If several environment variables appear in a line, they are all expanded
      with processing happening from left to right.
      Undefined variables expand to a null string.
      Syntax errors stop processing, letting the existing error handling
      show the user offending line.
      
      This patch helps embedded folks who frequently create several
      RFS directories and then switch between them as they're tuning
      an initramfs.
      
      Signed-off-by: default avatar <gene.sally@timesys.com>
      Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
      3b1ec9fb
  18. Jul 16, 2007
  19. Feb 11, 2007
  20. Apr 19, 2006
  21. Apr 16, 2005
    • Linus Torvalds's avatar
      Linux-2.6.12-rc2 · 1da177e4
      Linus Torvalds authored
      Initial git repository build. I'm not bothering with the full history,
      even though we have it. We can create a separate "historical" git
      archive of that later if we want to, and in the meantime it's about
      3.2GB when imported into git - space that would just make the early
      git days unnecessarily complicated, when we don't have a lot of good
      infrastructure for it.
      
      Let it rip!
      1da177e4
Loading