1. Dec 03, 2023
  2. Dec 02, 2023
    • Alexei Starovoitov's avatar
      Merge branch 'bpf-file-verification-with-lsm-and-fsverity' · 6685aadc
      Alexei Starovoitov authored
      Song Liu says:
      
      ====================
      bpf: File verification with LSM and fsverity
      
      Changes v14 => v15:
      1. Fix selftest build without CONFIG_FS_VERITY. (Alexei)
      2. Add Acked-by from KP.
      
      Changes v13 => v14:
      1. Add "static" for bpf_fs_kfunc_set.
      2. Add Acked-by from Christian Brauner.
      
      Changes v12 => v13:
      1. Only keep 4/9 through 9/9 of v12, as the first 3 patches already
         applied;
      2. Use new macro __bpf_kfunc_[start|end]_defs().
      
      Changes v11 => v12:
      1. Fix typo (data_ptr => sig_ptr) in bpf_get_file_xattr().
      
      Changes v10 => v11:
      1. Let __bpf_dynptr_data() return const void *. (Andrii)
      2. Optimize code to reuse output from __bpf_dynptr_size(). (Andrii)
      3. Add __diag_ignore_all("-Wmissing-declarations") for kfunc definition.
      4. Fix an off indentation. (Andrii)
      
      Changes v9 => v10:
      1. Remove WARN_ON_ONCE() from check_reg_const_str. (Alexei)
      
      Changes v8 => v9:
      1. Fix test_progs kfunc_dynptr_param/dynptr_data_null.
      
      Changes v7 => v8:
      1. Do not use bpf_dynptr_slice* in the kernel. Add __bpf_dynptr_data* and
         use them in ther kernel. (Andrii)
      
      Changes v6 => v7:
      1. Change "__const_str" annotation to "__str". (Alexei, Andrii)
      2. Add KF_TRUSTED_ARGS flag for both new kfuncs. (KP)
      3. Only allow bpf_get_file_xattr() to read xattr with "user." prefix.
      4. Add Acked-by from Eric Biggers.
      
      Changes v5 => v6:
      1. Let fsverity_init_bpf() return void. (Eric Biggers)
      2. Sort things in alphabetic orders. (Eric Biggers)
      
      Changes v4 => v5:
      1. Revise commit logs. (Alexei)
      
      Changes v3 => v4:
      1. Fix error reported by CI.
      2. Update comments of bpf_dynptr_slice* that they may return error pointer.
      
      Changes v2 => v3:
      1. Rebase and resolve conflicts.
      
      Changes v1 => v2:
      1. Let bpf_get_file_xattr() use const string for arg "name". (Alexei)
      2. Add recursion prevention with allowlist. (Alexei)
      3. Let bpf_get_file_xattr() use __vfs_getxattr() to avoid recursion,
         as vfs_getxattr() calls into other LSM hooks.
      4. Do not use dynptr->data directly, use helper insteadd. (Andrii)
      5. Fixes with bpf_get_fsverity_digest. (Eric Biggers)
      6. Add documentation. (Eric Biggers)
      7. Fix some compile warnings. (kernel test robot)
      
      This set enables file verification with BPF LSM and fsverity.
      
      In this solution, fsverity is used to provide reliable and efficient hash
      of files; and BPF LSM is used to implement signature verification (against
      asymmetric keys), and to enforce access control.
      
      This solution can be used to implement access control in complicated cases.
      For example: only signed python binary and signed python script and access
      special files/devices/ports.
      
      Thanks,
      Song
      ====================
      
      Link: https://lore.kernel.org/r/20231129234417.856536-1-song@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      6685aadc
    • Song Liu's avatar
      selftests/bpf: Add test that uses fsverity and xattr to sign a file · 1030e915
      Song Liu authored
      
      
      This selftests shows a proof of concept method to use BPF LSM to enforce
      file signature. This test is added to verify_pkcs7_sig, so that some
      existing logic can be reused.
      
      This file signature method uses fsverity, which provides reliable and
      efficient hash (known as digest) of the file. The file digest is signed
      with asymmetic key, and the signature is stored in xattr. At the run time,
      BPF LSM reads file digest and the signature, and then checks them against
      the public key.
      
      Note that this solution does NOT require FS_VERITY_BUILTIN_SIGNATURES.
      fsverity is only used to provide file digest. The signature verification
      and access control is all implemented in BPF LSM.
      
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20231129234417.856536-7-song@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      1030e915
    • Song Liu's avatar
      selftests/bpf: Add tests for filesystem kfuncs · 341f06fd
      Song Liu authored
      
      
      Add selftests for two new filesystem kfuncs:
        1. bpf_get_file_xattr
        2. bpf_get_fsverity_digest
      
      These tests simply make sure the two kfuncs work. Another selftest will be
      added to demonstrate how to use these kfuncs to verify file signature.
      
      CONFIG_FS_VERITY is added to selftests config. However, this is not
      sufficient to guarantee bpf_get_fsverity_digest works. This is because
      fsverity need to be enabled at file system level (for example, with tune2fs
      on ext4). If local file system doesn't have this feature enabled, just skip
      the test.
      
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20231129234417.856536-6-song@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      341f06fd
    • Song Liu's avatar
      selftests/bpf: Sort config in alphabetic order · 6b0ae456
      Song Liu authored
      
      
      Move CONFIG_VSOCKETS up, so the CONFIGs are in alphabetic order.
      
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20231129234417.856536-5-song@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      6b0ae456
    • Song Liu's avatar
      Documentation/bpf: Add documentation for filesystem kfuncs · 0de267d9
      Song Liu authored
      
      
      Add a brief introduction for file system kfuncs:
      
        bpf_get_file_xattr()
        bpf_get_fsverity_digest()
      
      The documentation highlights the strategy to avoid recursions of these
      kfuncs.
      
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20231129234417.856536-4-song@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      0de267d9
    • Song Liu's avatar
      bpf, fsverity: Add kfunc bpf_get_fsverity_digest · 67814c00
      Song Liu authored
      
      
      fsverity provides fast and reliable hash of files, namely fsverity_digest.
      The digest can be used by security solutions to verify file contents.
      
      Add new kfunc bpf_get_fsverity_digest() so that we can access fsverity from
      BPF LSM programs. This kfunc is added to fs/verity/measure.c because some
      data structure used in the function is private to fsverity
      (fs/verity/fsverity_private.h).
      
      To avoid recursion, bpf_get_fsverity_digest is only allowed in BPF LSM
      programs.
      
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Acked-by: default avatarEric Biggers <ebiggers@google.com>
      Link: https://lore.kernel.org/r/20231129234417.856536-3-song@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      67814c00
    • Song Liu's avatar
      bpf: Add kfunc bpf_get_file_xattr · ac9c05e0
      Song Liu authored
      
      
      It is common practice for security solutions to store tags/labels in
      xattrs. To implement similar functionalities in BPF LSM, add new kfunc
      bpf_get_file_xattr().
      
      The first use case of bpf_get_file_xattr() is to implement file
      verifications with asymmetric keys. Specificially, security applications
      could use fsverity for file hashes and use xattr to store file signatures.
      (kfunc for fsverity hash will be added in a separate commit.)
      
      Currently, only xattrs with "user." prefix can be read with kfunc
      bpf_get_file_xattr(). As use cases evolve, we may add a dedicated prefix
      for bpf_get_file_xattr().
      
      To avoid recursion, bpf_get_file_xattr can be only called from LSM hooks.
      
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Acked-by: default avatarChristian Brauner <brauner@kernel.org>
      Acked-by: default avatarKP Singh <kpsingh@kernel.org>
      Link: https://lore.kernel.org/r/20231129234417.856536-2-song@kernel.org
      
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      ac9c05e0
  3. Dec 01, 2023
  4. Nov 30, 2023
    • Paolo Abeni's avatar
      Merge branch 'net-ethernet-convert-to-platform-remove-callback-returning-void' · 7e022268
      Paolo Abeni authored
      Uwe Kleine-König says:
      
      ====================
      net: ethernet: Convert to platform remove callback returning void
      
      in (implicit) v1 of this series
      (https://lore.kernel.org/netdev/20231117091655.872426-1-u.kleine-koenig@pengutronix.de)
      I tried to address the resource leaks in the three cpsw drivers. However
      this is hard to get right without being able to test the changes. So
      here comes a series that just converts all drivers below
      drivers/net/ethernet to use .remove_new() and adds a comment about the
      potential leaks for someone else to fix the problem.
      
      See commit 5c5a7680 ("platform: Provide a remove callback that
      returns no value") for an extended explanation and the eventual goal.
      The TL;DR; is to prevent bugs like the three noticed here.
      
      Note this series results in no change of behaviour apart from improving
      the error message for the three cpsw drivers from
      
      	remove callback returned a non-zero value. This will be ignored.
      
      to
      
      	Failed to resume device (-ESOMETHING)
      ====================
      
      Link: https://lore.kernel.org/r/20231128173823.867512-1-u.kleine-koenig@pengutronix.de
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      7e022268
    • Uwe Kleine-König's avatar
      net: ethernet: ezchip: Convert to platform remove callback returning void · 7ec1bb2c
      Uwe Kleine-König authored
      
      
      The .remove() callback for a platform driver returns an int which makes
      many driver authors wrongly assume it's possible to do error handling by
      returning an error code. However the value returned is ignored (apart
      from emitting a warning) and this typically results in resource leaks.
      
      To improve here there is a quest to make the remove callback return
      void. In the first step of this quest all drivers are converted to
      .remove_new(), which already returns void. Eventually after all drivers
      are converted, .remove_new() will be renamed to .remove().
      
      Trivially convert this driver from always returning zero in the remove
      callback to the void returning variant.
      
      Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      7ec1bb2c
    • Uwe Kleine-König's avatar
      net: ethernet: ti: cpsw-new: Convert to platform remove callback returning void · a76772e2
      Uwe Kleine-König authored
      
      
      The .remove() callback for a platform driver returns an int which makes
      many driver authors wrongly assume it's possible to do error handling by
      returning an error code. However the value returned is ignored (apart
      from emitting a warning) and this typically results in resource leaks.
      
      To improve here there is a quest to make the remove callback return
      void. In the first step of this quest all drivers are converted to
      .remove_new(), which already returns void. Eventually after all drivers
      are converted, .remove_new() will be renamed to .remove().
      
      Replace the error path returning a non-zero value by an error message
      and a comment that there is more to do. With that this patch results in
      no change of behaviour in this driver apart from improving the error
      message.
      
      Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Reviewed-by: default avatarRoger Quadros <rogerq@kernel.org>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      a76772e2
    • Uwe Kleine-König's avatar
      net: ethernet: ti: cpsw: Convert to platform remove callback returning void · 7ac3f867
      Uwe Kleine-König authored
      
      
      The .remove() callback for a platform driver returns an int which makes
      many driver authors wrongly assume it's possible to do error handling by
      returning an error code. However the value returned is ignored (apart
      from emitting a warning) and this typically results in resource leaks.
      
      To improve here there is a quest to make the remove callback return
      void. In the first step of this quest all drivers are converted to
      .remove_new(), which already returns void. Eventually after all drivers
      are converted, .remove_new() will be renamed to .remove().
      
      Replace the error path returning a non-zero value by an error message
      and a comment that there is more to do. With that this patch results in
      no change of behaviour in this driver apart from improving the error
      message.
      
      Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Reviewed-by: default avatarRoger Quadros <rogerq@kernel.org>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      7ac3f867