~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/cap_helpers.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include "cap_helpers.h"
  3 
  4 /* Avoid including <sys/capability.h> from the libcap-devel package,
  5  * so directly declare them here and use them from glibc.
  6  */
  7 int capget(cap_user_header_t header, cap_user_data_t data);
  8 int capset(cap_user_header_t header, const cap_user_data_t data);
  9 
 10 int cap_enable_effective(__u64 caps, __u64 *old_caps)
 11 {
 12         struct __user_cap_data_struct data[_LINUX_CAPABILITY_U32S_3];
 13         struct __user_cap_header_struct hdr = {
 14                 .version = _LINUX_CAPABILITY_VERSION_3,
 15         };
 16         __u32 cap0 = caps;
 17         __u32 cap1 = caps >> 32;
 18         int err;
 19 
 20         err = capget(&hdr, data);
 21         if (err)
 22                 return err;
 23 
 24         if (old_caps)
 25                 *old_caps = (__u64)(data[1].effective) << 32 | data[0].effective;
 26 
 27         if ((data[0].effective & cap0) == cap0 &&
 28             (data[1].effective & cap1) == cap1)
 29                 return 0;
 30 
 31         data[0].effective |= cap0;
 32         data[1].effective |= cap1;
 33         err = capset(&hdr, data);
 34         if (err)
 35                 return err;
 36 
 37         return 0;
 38 }
 39 
 40 int cap_disable_effective(__u64 caps, __u64 *old_caps)
 41 {
 42         struct __user_cap_data_struct data[_LINUX_CAPABILITY_U32S_3];
 43         struct __user_cap_header_struct hdr = {
 44                 .version = _LINUX_CAPABILITY_VERSION_3,
 45         };
 46         __u32 cap0 = caps;
 47         __u32 cap1 = caps >> 32;
 48         int err;
 49 
 50         err = capget(&hdr, data);
 51         if (err)
 52                 return err;
 53 
 54         if (old_caps)
 55                 *old_caps = (__u64)(data[1].effective) << 32 | data[0].effective;
 56 
 57         if (!(data[0].effective & cap0) && !(data[1].effective & cap1))
 58                 return 0;
 59 
 60         data[0].effective &= ~cap0;
 61         data[1].effective &= ~cap1;
 62         err = capset(&hdr, data);
 63         if (err)
 64                 return err;
 65 
 66         return 0;
 67 }
 68 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php