Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp457899lqi; Thu, 7 Mar 2024 02:18:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVRWCvLbqQnTA13lkK+V0mIMh2GWs/+2uph60qkMhPq5WoGwF30u7aCTS2HR64+k/yP/e5Tkg29bCs4GPNSts5NsTNTks+MZje5TYORXA== X-Google-Smtp-Source: AGHT+IHWdZvirYolLWHdhLx7YlY2gK+z+2bze9RdOslFbg3j5N1jwvMCf+cxZMPOXVaN7kP67jFT X-Received: by 2002:a17:90a:7890:b0:29b:77b0:10f with SMTP id x16-20020a17090a789000b0029b77b0010fmr4052574pjk.48.1709806699707; Thu, 07 Mar 2024 02:18:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709806699; cv=pass; d=google.com; s=arc-20160816; b=BjptbkNHricE5Kw7iRXbctEb1PItdvaik3gWCmP//BDNSKwVrinAD3UkD3h2DiHXJX b/T540IZpQmj6w11WfeS9rdHSyAv51XLqo3rtS0VL5uzLzBeCCYrYu4SxJY07eRikBJC tE+kGzpRN08wBim3QZou1hAZ+oO3G5nS70C2e3xH0ywbfPVxy3cQMGhUNGWpMWIWm0Gd Fj03Hj37zdaXyw4yFf1hocp/6C0qfY4AsQ6Fqv59sKuYGoteOVdl3KJztcWS39q671D8 fpxXjpEZB1pvN7f/82za6kLcbdZ9o/YoDPJpSiQ5KqpGur/NA9butgEqEeAmNZ/2TGLI Fesg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fJBGtg7A9rrKgJGpFJEvdfvVNfoviioc8uYkOqvDLgA=; fh=GgSHDWyLVhbEQsHj6hElT1BBLmxd4RN/EKSOIush3hI=; b=QLrAO3ip0dBXLHSSv9DMSl6OeGqHCa/g1kJ+snVzHrpJ00SF5369pWpz1UaZm+mQNx g0lGpQyQ9h2qBypVeaHx+UZ3C85EkluRslr9THU/FfWWIfcrx4y7M1VnPeFdBK1u4Yg9 JgwhZAqXr+Gl/qHZ+cUfveeKr8dLvOeK/8eTe6Ghi890cW/hR4qj+IzO3/LMJMpdTG4l USaLLej1IOTwGSgj8z7HZvv01ir7ss1hHQ/XJVglFfvh8zneYO4pTgHc81XlCO0S/B98 ccBtjTmYTeNJfuIO8A9fj3o8u+ndbrxDz+SSx0tVzYrzSgKOmjkTxs+PYhAer6NdCejO swcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N7TG1tNb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-95316-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95316-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a15-20020a17090a8c0f00b0029b09c53385si1362413pjo.43.2024.03.07.02.18.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 02:18:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95316-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N7TG1tNb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-95316-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95316-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1E6D8282B14 for ; Thu, 7 Mar 2024 10:17:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 12DB284FD8; Thu, 7 Mar 2024 10:17:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N7TG1tNb" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 154C884FD6; Thu, 7 Mar 2024 10:17:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709806639; cv=none; b=qeNPMS+7YdXWmi+Xqfn0xIG/GyA0e6b0pcd0y49uXrt+9Vs+z4quWVq+wu/9SFh1cK3gqu9MV3uWTyIHea9E4QGSauPQOGA2bc31lGPEu8KnRrDE8wgTlu+754xNgb11xhpjwxg8LgnWoSchRR2FTZclPXwQ1IDTvb7yMFkI2kk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709806639; c=relaxed/simple; bh=dSfsFSg4cADwP8Sk6K+DLBAvbPx8lxXSyAMiQIkTfkE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rl2nTlx81jZIOwU2GiV9k+HdoE1+xVCzKPeCMEPxqU8N5x9MSBAERFCCvH0dg0i9dNxcLJ99B9wPxmSnwoykhUi0lQ2mFwioo4sXgI93Vq7CdSZ3eTB7UTFS6H69hs5oXEaIE8vwpKTe9Tiib9fbjhycyUm6ij6eebhoKVFTMM8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N7TG1tNb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2020FC433F1; Thu, 7 Mar 2024 10:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709806638; bh=dSfsFSg4cADwP8Sk6K+DLBAvbPx8lxXSyAMiQIkTfkE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N7TG1tNbAzTL6AwHzkSDsH/OlOnRcNBf1OD2UTyJFOQZftoRnPLcZDOJI2XNPHQKq Qh8pQPUphhRBJ2LF2tKooMGUxVShYY2eg5YfkxFZseRBp/n4VcqqSVOG7HtEoPew09 P6O6WIdRaWltEifNpZFxYYqN/6Li5o+8jCymc19DGud2vK7lTHBoFxCHxzoOZmR/MM tWAqbTFae/nWu+im6xPFvNrrE7agij3gHqESmPV8CqQpg4RqOwK/bYzK8bbW2LqUp1 7Z4OkpoEdijpFTMlW/D6E1hnxZMbxg9DWvRVh9cL1c0qcGSVZcvcyO43MbGGp0Fghn NeIMHYomjAx8g== Date: Thu, 7 Mar 2024 11:17:13 +0100 From: Christian Brauner To: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= Cc: =?utf-8?Q?G=C3=BCnther?= Noack , Jann Horn , Paul Moore , Kees Cook , Konstantin Meskhidze , "Serge E . Hallyn" , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH] landlock: Use f_cred in security_file_open() hook Message-ID: <20240307-fehlten-gewinn-18c93d5fb9e6@brauner> References: <20240307095203.1467189-1-mic@digikod.net> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240307095203.1467189-1-mic@digikod.net> On Thu, Mar 07, 2024 at 10:52:03AM +0100, Mickaël Salaün wrote: > Use landlock_cred(file->f_cred)->domain instead of > landlock_get_current_domain() in security_file_open() hook > implementation. > > This should not change the current behavior but could avoid potential > race conditions in case of current task's credentials change. I have no problem with the patch but I'm curious how that credential change could happen behind your back? > > This will also ensure consistency with upcoming audit support relying on > file->f_cred. > > Add and use a new get_fs_domain() helper to mask non-filesystem domains. > > file->f_cred is set by path_openat()/alloc_empty_file()/init_file() just > before calling security_file_alloc(). > > Cc: Christian Brauner > Cc: Günther Noack > Cc: Jann Horn > Cc: Kees Cook > Cc: Paul Moore > Signed-off-by: Mickaël Salaün > Link: https://lore.kernel.org/r/20240307095203.1467189-1-mic@digikod.net > --- > security/landlock/fs.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/security/landlock/fs.c b/security/landlock/fs.c > index 6f0bf1434a2c..c15559432d3d 100644 > --- a/security/landlock/fs.c > +++ b/security/landlock/fs.c > @@ -248,15 +248,18 @@ get_handled_fs_accesses(const struct landlock_ruleset *const domain) > LANDLOCK_ACCESS_FS_INITIALLY_DENIED; > } > > -static const struct landlock_ruleset *get_current_fs_domain(void) > +static const struct landlock_ruleset * > +get_fs_domain(const struct landlock_ruleset *const domain) > { > - const struct landlock_ruleset *const dom = > - landlock_get_current_domain(); > - > - if (!dom || !get_raw_handled_fs_accesses(dom)) > + if (!domain || !get_raw_handled_fs_accesses(domain)) > return NULL; > > - return dom; > + return domain; > +} > + > +static const struct landlock_ruleset *get_current_fs_domain(void) > +{ > + return get_fs_domain(landlock_get_current_domain()); > } > > /* > @@ -1334,7 +1337,8 @@ static int hook_file_open(struct file *const file) > layer_mask_t layer_masks[LANDLOCK_NUM_ACCESS_FS] = {}; > access_mask_t open_access_request, full_access_request, allowed_access; > const access_mask_t optional_access = LANDLOCK_ACCESS_FS_TRUNCATE; > - const struct landlock_ruleset *const dom = get_current_fs_domain(); > + const struct landlock_ruleset *const dom = > + get_fs_domain(landlock_cred(file->f_cred)->domain); > > if (!dom) > return 0; > -- > 2.44.0 >