Skip to content

Commit fe76bd1

Browse files
committed
landlock: Optimize scope enforcement
Do not walk through the domain hierarchy when the required scope is not supported by this domain. This is the same approach as for filesystem and network restrictions. Cc: Günther Noack <[email protected]> Cc: Mikhail Ivanov <[email protected]> Cc: Tahera Fahimi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 059a40b commit fe76bd1

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

security/landlock/task.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,22 @@ static bool is_abstract_socket(struct sock *const sock)
204204
return false;
205205
}
206206

207+
static const struct landlock_ruleset *get_current_unix_scope_domain(void)
208+
{
209+
const union access_masks unix_scope = {
210+
.scope = LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET,
211+
};
212+
213+
return landlock_match_ruleset(landlock_get_current_domain(),
214+
unix_scope);
215+
}
216+
207217
static int hook_unix_stream_connect(struct sock *const sock,
208218
struct sock *const other,
209219
struct sock *const newsk)
210220
{
211221
const struct landlock_ruleset *const dom =
212-
landlock_get_current_domain();
222+
get_current_unix_scope_domain();
213223

214224
/* Quick return for non-landlocked tasks. */
215225
if (!dom)
@@ -225,7 +235,7 @@ static int hook_unix_may_send(struct socket *const sock,
225235
struct socket *const other)
226236
{
227237
const struct landlock_ruleset *const dom =
228-
landlock_get_current_domain();
238+
get_current_unix_scope_domain();
229239

230240
if (!dom)
231241
return 0;
@@ -243,6 +253,10 @@ static int hook_unix_may_send(struct socket *const sock,
243253
return 0;
244254
}
245255

256+
static const union access_masks signal_scope = {
257+
.scope = LANDLOCK_SCOPE_SIGNAL,
258+
};
259+
246260
static int hook_task_kill(struct task_struct *const p,
247261
struct kernel_siginfo *const info, const int sig,
248262
const struct cred *const cred)
@@ -256,6 +270,7 @@ static int hook_task_kill(struct task_struct *const p,
256270
} else {
257271
dom = landlock_get_current_domain();
258272
}
273+
dom = landlock_match_ruleset(dom, signal_scope);
259274

260275
/* Quick return for non-landlocked tasks. */
261276
if (!dom)
@@ -279,7 +294,8 @@ static int hook_file_send_sigiotask(struct task_struct *tsk,
279294

280295
/* Lock already held by send_sigio() and send_sigurg(). */
281296
lockdep_assert_held(&fown->lock);
282-
dom = landlock_file(fown->file)->fown_domain;
297+
dom = landlock_match_ruleset(landlock_file(fown->file)->fown_domain,
298+
signal_scope);
283299

284300
/* Quick return for unowned socket. */
285301
if (!dom)

0 commit comments

Comments
 (0)