• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 12877533250

20 Jan 2025 11:16PM UTC coverage: 0.117%. Remained the same
12877533250

push

github

web-flow
pidfd: cache our own pidfd inode id, and use it at various places (#36060)

This is split out of and preparation for #35224, but makes a ton of
sense on its own

0 of 95 new or added lines in 10 files covered. (0.0%)

4667 existing lines in 34 files now uncovered.

478 of 408040 relevant lines covered (0.12%)

1.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/basic/capability-util.h
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
#pragma once
3

4
#include <stdbool.h>
5
#include <stdint.h>
6
#include <sys/capability.h>
7
#include <sys/types.h>
8

9
#include "macro.h"
10
#include "missing_capability.h"
11
#include "pidref.h"
12

13
/* Special marker used when storing a capabilities mask as "unset". This would need to be updated as soon as
14
 * Linux learns more than 63 caps. */
15
#define CAP_MASK_UNSET UINT64_MAX
16
assert_cc(CAP_LAST_CAP < 64);
17

18
/* All possible capabilities bits on */
19
#define CAP_MASK_ALL UINT64_C(0x7fffffffffffffff)
20

21
/* The largest capability we can deal with, given we want to be able to store cap masks in uint64_t but still
22
 * be able to use UINT64_MAX as indicator for "not set". The latter makes capability 63 unavailable. */
23
#define CAP_LIMIT 62
24

25
static inline bool capability_is_set(uint64_t v) {
26
        return v != CAP_MASK_UNSET;
27
}
28

29
unsigned cap_last_cap(void);
30
int have_effective_cap(int value);
31
int capability_gain_cap_setpcap(cap_t *ret_before_caps);
32
int capability_bounding_set_drop(uint64_t keep, bool right_now);
33
int capability_bounding_set_drop_usermode(uint64_t keep);
34

35
int capability_ambient_set_apply(uint64_t set, bool also_inherit);
36
int capability_update_inherited_set(cap_t caps, uint64_t ambient_set);
37

38
int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities);
39

40
int drop_capability(cap_value_t cv);
41
int keep_capability(cap_value_t cv);
42

43
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(cap_t, cap_free, NULL);
×
44
#define _cleanup_cap_free_ _cleanup_(cap_freep)
45

46
static inline uint64_t all_capabilities(void) {
×
47
        return UINT64_MAX >> (63 - cap_last_cap());
×
48
}
49

UNCOV
50
static inline bool cap_test_all(uint64_t caps) {
×
UNCOV
51
        return FLAGS_SET(caps, all_capabilities());
×
52
}
53

54
/* Identical to linux/capability.h's CAP_TO_MASK(), but uses an unsigned 1U instead of a signed 1 for shifting left, in
55
 * order to avoid complaints about shifting a signed int left by 31 bits, which would make it negative. */
56
#define CAP_TO_MASK_CORRECTED(x) (1U << ((x) & 31U))
57

58
typedef struct CapabilityQuintet {
59
        /* Stores all five types of capabilities in one go. */
60
        uint64_t effective;
61
        uint64_t bounding;
62
        uint64_t inheritable;
63
        uint64_t permitted;
64
        uint64_t ambient;
65
} CapabilityQuintet;
66

67
#define CAPABILITY_QUINTET_NULL (const CapabilityQuintet) { CAP_MASK_UNSET, CAP_MASK_UNSET, CAP_MASK_UNSET, CAP_MASK_UNSET, CAP_MASK_UNSET }
68

UNCOV
69
static inline bool capability_quintet_is_set(const CapabilityQuintet *q) {
×
UNCOV
70
        return capability_is_set(q->effective) ||
×
UNCOV
71
                capability_is_set(q->bounding) ||
×
UNCOV
72
                capability_is_set(q->inheritable) ||
×
UNCOV
73
                capability_is_set(q->permitted) ||
×
UNCOV
74
                capability_is_set(q->ambient);
×
75
}
76

77
static inline bool capability_quintet_is_fully_set(const CapabilityQuintet *q) {
×
78
        return capability_is_set(q->effective) &&
×
79
                capability_is_set(q->bounding) &&
×
80
                capability_is_set(q->inheritable) &&
×
UNCOV
81
                capability_is_set(q->permitted) &&
×
UNCOV
82
                capability_is_set(q->ambient);
×
83
}
84

85
/* Mangles the specified caps quintet taking the current bounding set into account:
86
 * drops all caps from all five sets if our bounding set doesn't allow them.
87
 * Returns true if the quintet was modified. */
88
bool capability_quintet_mangle(CapabilityQuintet *q);
89

90
int capability_quintet_enforce(const CapabilityQuintet *q);
91

92
int capability_get_ambient(uint64_t *ret);
93

94
int pidref_get_capability(const PidRef *pidref, CapabilityQuintet *ret);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc