diff options
Diffstat (limited to 'net/core/sock.c')
| -rw-r--r-- | net/core/sock.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/net/core/sock.c b/net/core/sock.c index b4fff008136f..664ee4295b6f 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
| @@ -145,6 +145,55 @@ | |||
| 145 | static DEFINE_MUTEX(proto_list_mutex); | 145 | static DEFINE_MUTEX(proto_list_mutex); |
| 146 | static LIST_HEAD(proto_list); | 146 | static LIST_HEAD(proto_list); |
| 147 | 147 | ||
| 148 | /** | ||
| 149 | * sk_ns_capable - General socket capability test | ||
| 150 | * @sk: Socket to use a capability on or through | ||
| 151 | * @user_ns: The user namespace of the capability to use | ||
| 152 | * @cap: The capability to use | ||
| 153 | * | ||
| 154 | * Test to see if the opener of the socket had when the socket was | ||
| 155 | * created and the current process has the capability @cap in the user | ||
| 156 | * namespace @user_ns. | ||
| 157 | */ | ||
| 158 | bool sk_ns_capable(const struct sock *sk, | ||
| 159 | struct user_namespace *user_ns, int cap) | ||
| 160 | { | ||
| 161 | return file_ns_capable(sk->sk_socket->file, user_ns, cap) && | ||
| 162 | ns_capable(user_ns, cap); | ||
| 163 | } | ||
| 164 | EXPORT_SYMBOL(sk_ns_capable); | ||
| 165 | |||
| 166 | /** | ||
| 167 | * sk_capable - Socket global capability test | ||
| 168 | * @sk: Socket to use a capability on or through | ||
| 169 | * @cap: The global capbility to use | ||
| 170 | * | ||
| 171 | * Test to see if the opener of the socket had when the socket was | ||
| 172 | * created and the current process has the capability @cap in all user | ||
| 173 | * namespaces. | ||
| 174 | */ | ||
| 175 | bool sk_capable(const struct sock *sk, int cap) | ||
| 176 | { | ||
| 177 | return sk_ns_capable(sk, &init_user_ns, cap); | ||
| 178 | } | ||
| 179 | EXPORT_SYMBOL(sk_capable); | ||
| 180 | |||
| 181 | /** | ||
| 182 | * sk_net_capable - Network namespace socket capability test | ||
| 183 | * @sk: Socket to use a capability on or through | ||
| 184 | * @cap: The capability to use | ||
| 185 | * | ||
| 186 | * Test to see if the opener of the socket had when the socke was created | ||
| 187 | * and the current process has the capability @cap over the network namespace | ||
| 188 | * the socket is a member of. | ||
| 189 | */ | ||
| 190 | bool sk_net_capable(const struct sock *sk, int cap) | ||
| 191 | { | ||
| 192 | return sk_ns_capable(sk, sock_net(sk)->user_ns, cap); | ||
| 193 | } | ||
| 194 | EXPORT_SYMBOL(sk_net_capable); | ||
| 195 | |||
| 196 | |||
| 148 | #ifdef CONFIG_MEMCG_KMEM | 197 | #ifdef CONFIG_MEMCG_KMEM |
| 149 | int mem_cgroup_sockets_init(struct mem_cgroup *memcg, struct cgroup_subsys *ss) | 198 | int mem_cgroup_sockets_init(struct mem_cgroup *memcg, struct cgroup_subsys *ss) |
| 150 | { | 199 | { |
