Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp319424rdb; Thu, 25 Jan 2024 17:09:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLDqg7HiOMv7O2qCwAYWoDijjyCPtWCV7f92MhgpJlclW0b/rQrB0494BlbKr/WuJ89FHK X-Received: by 2002:a05:6a20:d395:b0:19a:bbca:a03a with SMTP id iq21-20020a056a20d39500b0019abbcaa03amr638390pzb.31.1706231353545; Thu, 25 Jan 2024 17:09:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706231353; cv=pass; d=google.com; s=arc-20160816; b=P3ndPNzGPGO8dgsBYYz2LwmFZUEXCtNWYz5TW/WympCEEsvDQ9v9FM7O1HdXrZSqyb IiOirPRMJ5Z5CSfJMxuo1cRaUmplJTwCVKsP6CcCTqHIhFfmNo9L1YKIEW9beqXHiq5Y O70J6EFloJVbiP40mKqkO25TqAkcHFyyNzG1opjQeTRWBgBaLSd87KLXmNUfEPcTGvyU EeXI3wMJujT1uJQHq9gzHBobGxWHLAaJZ62Fov3Y6J47ENIM3dhwslwx9z4Ksn83erXe G5udTr3g8Ixs1UBWG9M4zD+l6Fe1t5oYqFHtKoLONwariHH3XoXXhkYlX6UDEAJBZvP1 DN7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=HGm3KDGKg624qPzuu1040l9P7rf2iGG3nBhtGZZPH+g=; fh=c0RS9tJDAtqDVybWc2FDkrFWL/VP6SSJ+iEF02+pZxw=; b=AflBE5HWyg+6aC/q5duZg2P3c4b+dTLaoMUkvIwwOrsdXi6pTKSBhPBuzr/wTjedA5 OJ7HOZAPDW6+0JDUEynfYcO6pock1DHi2abatD0990mpxtCBPJwOrDGutzZcuzYQf8op gAhM7VOgGXzAlPsyKy0tNcomBQJZE8C0JuNOzgX0jW4m4jgnjKZa4biKxPTeMTxSRTJb 1+pfD20EVYOMOUw29alppLGRHvf2e7CDFDO/qo1oV47fKU+mNbhZqAil0ZL2fyeI+aqj o1EpzjSu6s9We5FDBYR0iX3yNYqw+yFGy+4UH16/6lQo0dTP4F+vyzRY+9JRx3KXyY4k FN0A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=UJoqfeqe; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-39482-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39482-linux.lists.archive=gmail.com@vger.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 i2-20020a17090a974200b0029058da5dc5si2198788pjw.176.2024.01.25.17.09.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 17:09:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39482-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=@linux-foundation.org header.s=korg header.b=UJoqfeqe; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-39482-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39482-linux.lists.archive=gmail.com@vger.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 E67C528B450 for ; Fri, 26 Jan 2024 01:09:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16E2D10EB; Fri, 26 Jan 2024 01:09:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="UJoqfeqe" 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 143D8387; Fri, 26 Jan 2024 01:09:05 +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=1706231346; cv=none; b=dZHa8B3Ge4h9AzJ7dqjGKxrFdji7IOnrO60vTVGcmOm1pNFGY1WapKkoWMdGDnNlRHMUmu8sEYMBU0IhpOU68QSWqmyxYEYF4WX/VWz6GWSxc4hZBYYlTktb3UrBvYkhJGk8xNbZAz/F9wRvfA7uJIG9Yj8EHI0Y21eD3AlijnQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706231346; c=relaxed/simple; bh=ZcNBosLvwzHAld72+LuB55jLJ9C0jyjKAALEGkHTKFM=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=nKLdDST573B76tIl7a8+ep2MsbO5kPNt7U+/jQ9PHzOHHkC3kWC1MjQvDvthvtcSSxIPpouw1IWhG+6FIQSgGTUDNPfu5uUqwZOqLeKqYzWnPRAsU4+CIYBwz01wH86bOqPDqJg1wCbxV01xbb7TZLBCLQk9MQ5mxuAZv/br2dY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=UJoqfeqe; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45CBBC433F1; Fri, 26 Jan 2024 01:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1706231345; bh=ZcNBosLvwzHAld72+LuB55jLJ9C0jyjKAALEGkHTKFM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=UJoqfeqeIy/4MNN+brvu8oK2me7WSipoIos2XaP5hv0zYuiIKPWyMK5YLGSiOgMlp Olif5eyyzRLcw+B5NLyI8Ly0QNOV+oAfNYp9QEdHn1NnYpdwKsWNQdfiSVqWmpuSFT gtSew4R/pju2PGTBvhAj4vpekWnNDxxuq9ptwmWU= Date: Thu, 25 Jan 2024 17:08:58 -0800 From: Andrew Morton To: Roberto Sassu Cc: casey@schaufler-ca.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Roberto Sassu , Hugh Dickins Subject: Re: [PATCH v3 5/5] ramfs: Initialize security of in-memory inodes Message-Id: <20240125170858.1ce723a57c7fd2b9bfb5d28d@linux-foundation.org> In-Reply-To: <20231116090125.187209-6-roberto.sassu@huaweicloud.com> References: <20231116090125.187209-1-roberto.sassu@huaweicloud.com> <20231116090125.187209-6-roberto.sassu@huaweicloud.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 16 Nov 2023 10:01:25 +0100 Roberto Sassu wrote: > From: Roberto Sassu > > Add a call security_inode_init_security() after ramfs_get_inode(), to let > LSMs initialize the inode security field. Skip ramfs_fill_super(), as the > initialization is done through the sb_set_mnt_opts hook. > > Calling security_inode_init_security() call inside ramfs_get_inode() is > not possible since, for CONFIG_SHMEM=n, tmpfs also calls the former after > the latter. > > Pass NULL as initxattrs() callback to security_inode_init_security(), since > the purpose of the call is only to initialize the in-memory inodes. > fwiw, Acked-by: Andrew Morton Please include this in the relevant security tree. > diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c > index 4ac05a9e25bc..8006faaaf0ec 100644 > --- a/fs/ramfs/inode.c > +++ b/fs/ramfs/inode.c > @@ -102,11 +102,20 @@ ramfs_mknod(struct mnt_idmap *idmap, struct inode *dir, > int error = -ENOSPC; > > if (inode) { > + error = security_inode_init_security(inode, dir, > + &dentry->d_name, NULL, > + NULL); > + if (error) { > + iput(inode); > + goto out; > + } > + > d_instantiate(dentry, inode); > dget(dentry); /* Extra count - pin the dentry in core */ > error = 0; > inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); > } > +out: > return error; > } > > @@ -134,6 +143,15 @@ static int ramfs_symlink(struct mnt_idmap *idmap, struct inode *dir, > inode = ramfs_get_inode(dir->i_sb, dir, S_IFLNK|S_IRWXUGO, 0); > if (inode) { > int l = strlen(symname)+1; > + > + error = security_inode_init_security(inode, dir, > + &dentry->d_name, NULL, > + NULL); > + if (error) { > + iput(inode); > + goto out; > + } > + > error = page_symlink(inode, symname, l); > if (!error) { > d_instantiate(dentry, inode); > @@ -143,6 +161,7 @@ static int ramfs_symlink(struct mnt_idmap *idmap, struct inode *dir, > } else > iput(inode); > } > +out: > return error; > } > > @@ -150,12 +169,23 @@ static int ramfs_tmpfile(struct mnt_idmap *idmap, > struct inode *dir, struct file *file, umode_t mode) > { > struct inode *inode; > + int error; > > inode = ramfs_get_inode(dir->i_sb, dir, mode, 0); > if (!inode) > return -ENOSPC; > + > + error = security_inode_init_security(inode, dir, > + &file_dentry(file)->d_name, NULL, > + NULL); > + if (error) { > + iput(inode); > + goto out; > + } > + > d_tmpfile(file, inode); > - return finish_open_simple(file, 0); > +out: > + return finish_open_simple(file, error); > } > > static const struct inode_operations ramfs_dir_inode_operations = { > -- > 2.34.1