From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD006282F14 for ; Sun, 9 Aug 2026 15:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786290352; cv=none; b=VNDQECPwOaQ26rkw3HQUJdy+l2gteiigpN5o3GpsJ8YksgdYfaxwiBR0Y/vGRGBWV5o4P3maMOAU/IDzN7OPMDu6QcscWnFvUAmqvBpOcfHhV9un3QHgcldn4bexmfrBVjqtVvfRSjfFeHPR4B2t62UtArBIWI2unicZjQH7RAQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786290352; c=relaxed/simple; bh=eAMqol1zYgr+7QAqNpjRtuDJ60g/z6FUFiVLJddOzHU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YRcEX5ZRDs0TBvH7v0HjsAGxuY/UJE89rZibAIYRtb5LhounV4TcFychDsqj6ZOhjYgNbNZkvVeAfQCDC4EVKJ1Iy4kpHenMJ5DjWirqHN0bbvuhARsEbKxoWBqqfoA9S/L5ksF7LdAP9YgezWqaTCOtYn5EUrfGTehq2yPK5jA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Il0X/cf8; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Il0X/cf8" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-8201447e8cdso18554797b3.3 for ; Sun, 09 Aug 2026 08:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786290350; x=1786895150; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=hn9JpmrDnY0h+wRK1i77j3APz1tT5vx3twjO5WqH6vM=; b=Il0X/cf8czIYtdi0HbSoViVP2LYI0ZX360MjxpLRm9OyOBNiWxf1VIMaH8zpg+8qQw NxNssyK/xZf33sk32yC8xfLqmfk7ZAqm4zMokJ6PpjVWCZbfxqp1jgd8Cbd2ip8z5ioa t9ngghBCUP4TixxA6G/QJowshsVEUarmcADRQs67iBwJB+7xHyGeXwp+jh8I+3VUSbD1 fzRzZGp8WHvxQqruEqU7e9CLbd5hOCl5CFrj1DI/AWtjv2z9SbnHL6zpn0X4uq2aZFHA owpuSXY/UXV8jCGle18fFsXtrMnWA/Hl3RLrxXDTANhXgUqBBVvVJf0ofDDEZdA9Deil SgMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786290350; x=1786895150; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hn9JpmrDnY0h+wRK1i77j3APz1tT5vx3twjO5WqH6vM=; b=PnSph2y5zQNlFiYzh7cDiYLxf/lY9hfhVxlRSk8TmbZblbv8A7UqrNKSez5AJIfvUY 8wL+CsRAjvSYYxadUR3n23aInR8mLiOPrvU5NhbWwDEk1LlZ6wtr6Cq0HkC4E1+F3nd0 RwzzoX+SpwmC7V9BtB2cuAkzS+jhul1+3LLJOEt/UWg2nYhaqi5jdm0WjvtlRZmSR5V/ nZPtsLHntBNi23FLJAgvJIpsru7jYI+CdDCtRXWYWw3Ai9w7CoF3WZB/Z4beRr43jVz4 xbYLN86TcpkyjfTb48V4gD7+PIdL5JiF6pzFGi+sTjaAyMTOytIVmY5XfABWPd4GVu5o dO1Q== X-Gm-Message-State: AOJu0YyygIMkQZETpatsqSSjMyVSZtfIUtlkJk2a2kBdIDWAA/XD4yL2 XjTBo13I5zPVu9sKAJYFGLeoy8KSjBR2Ep6r8vNUU2KuxkZiu7eVNFAi7Jb1H9Jj X-Gm-Gg: AR+sD11ZmXc5YOfKGtYFtbiskVUnIKFYHMABI8HzPJIaL0jGgTsMEVxmemhNnmtcqnG UW/eZ2q14003GtPSlYjMfoX2nqjI7UgTzchqCzs9ryzjH1I8qOsdGKRj8GpxmpOTMaDJlR/tf8V /nQyjCDxECm0iiy4Z+eLGsboIbZaMgC31kcmo6QJcupBiqdDoYn9YYBu/bHpfh96XYiDfiJbidt I/fUWU/DQdma+Izephmk5S6WwdRtyiYeNMwuSlJ8oJQWMZ2PJCBSsS/JoawRrmir8IL/oPzsppy qG6wWX9O03RHc/eiGkPQwJrHVTVQc/f12Vnqj6bNDwoyKzDLfSHM0dT6PKunAQQlmw/0LUh5bHM pJXjhI+LTI0ggoL7fwHtjVcma8K1fLWsB/PI5KmmhmqIAQrQcX984F8OMUwXhAfUelhO4XtqC7l ayJC6ST5NslM2aaLcKm5PW3nQ8gJvuEskp2rxR3Gyw2oHuwT5uufTGxp4p6cVLeWt1eJabTe0N/ lTXK7YIh2yORy7Sh6M8nhw= X-Received: by 2002:a05:690e:16e3:b0:668:9567:db70 with SMTP id 956f58d0204a3-6699aacf1d5mr15790620d50.40.1786290349820; Sun, 09 Aug 2026 08:45:49 -0700 (PDT) Received: from zenbox ([2600:1700:18fb:6011:4665:53b0:3ac9:3545]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-66acacdbea9sm4838001d50.3.2026.08.09.08.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2026 08:45:49 -0700 (PDT) From: Justin Suess To: gnoack3000@gmail.com, mic@digikod.net Cc: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Justin Suess Subject: [PATCH v4 1/5] landlock: Check landlock_restrict_self(2)'s flags before privileges Date: Sun, 9 Aug 2026 11:45:19 -0400 Message-ID: <20260809154544.1253100-2-utilityemal77@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260809154544.1253100-1-utilityemal77@gmail.com> References: <20260809154544.1253100-1-utilityemal77@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sys_landlock_restrict_self() currently checks the no_new_privs / CAP_SYS_ADMIN requirement before validating the flags argument. An unprivileged caller without no_new_privs thus gets EPERM even when the passed flags are invalid, hiding the EINVAL error. Move the no_new_privs / CAP_SYS_ADMIN check just after the flags check so that malformed calls consistently error out with EINVAL whatever the caller's privileges, the same way seccomp(2) validates its flags before checking no_new_privs. Update the restrict_self_checks_ordering test accordingly. Cc: Mickaël Salaün Signed-off-by: Justin Suess --- Notes: v4: - New patch, following Mickaël's review of the main patch: check the flags argument before the no_new_privs / CAP_SYS_ADMIN requirement, in the same order as seccomp(2). security/landlock/syscalls.c | 8 ++++---- tools/testing/selftests/landlock/base_test.c | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/security/landlock/syscalls.c b/security/landlock/syscalls.c index 36b02892c62f..e3ef7b980c82 100644 --- a/security/landlock/syscalls.c +++ b/security/landlock/syscalls.c @@ -535,6 +535,10 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32, if (!is_initialized()) return -EOPNOTSUPP; + if ((flags | LANDLOCK_MASK_RESTRICT_SELF) != + LANDLOCK_MASK_RESTRICT_SELF) + return -EINVAL; + /* * Similar checks as for seccomp(2), except that an -EPERM may be * returned. @@ -543,10 +547,6 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32, !ns_capable_noaudit(current_user_ns(), CAP_SYS_ADMIN)) return -EPERM; - if ((flags | LANDLOCK_MASK_RESTRICT_SELF) != - LANDLOCK_MASK_RESTRICT_SELF) - return -EINVAL; - /* Translates "off" flag to boolean. */ log_same_exec = !(flags & LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF); /* Translates "on" flag to boolean. */ diff --git a/tools/testing/selftests/landlock/base_test.c b/tools/testing/selftests/landlock/base_test.c index cbd3c1669951..f3c126d5c003 100644 --- a/tools/testing/selftests/landlock/base_test.c +++ b/tools/testing/selftests/landlock/base_test.c @@ -255,8 +255,12 @@ TEST(restrict_self_checks_ordering) /* Checks unprivileged enforcement without no_new_privs. */ drop_caps(_metadata); + /* + * The flags validity is checked before the no_new_privs / + * CAP_SYS_ADMIN requirement. + */ ASSERT_EQ(-1, landlock_restrict_self(-1, -1)); - ASSERT_EQ(EPERM, errno); + ASSERT_EQ(EINVAL, errno); ASSERT_EQ(-1, landlock_restrict_self(-1, 0)); ASSERT_EQ(EPERM, errno); ASSERT_EQ(-1, landlock_restrict_self(ruleset_fd, 0)); -- 2.55.0