mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2/3] ubifs: xattr: preserve the encryption flag when creation fails
@ 2026-11-02 11:56 shao.mingyin
  2026-11-02 13:35 ` Zhihao Cheng
  0 siblings, 1 reply; 3+ messages in thread
From: shao.mingyin @ 2026-11-02 11:56 UTC (permalink / raw)
  To: richard, linux-mtd, chengzhihao1, linux-kernel, stable

create_xattr() clears UBIFS_CRYPT_FL in its error path regardless of
whether this call set the flag.  The flag is also set for every inode
that already carries an encryption context, so a failed setxattr() on
such an inode clears it from the in-memory inode.  The next inode write
then packs ui->flags without UBIFS_CRYPT_FL, and after the next mount
the inode is no longer treated as encrypted although its names and data
still are.  ubifs_jnl_update() can fail before anything is written, for
example when its journal buffer cannot be allocated.

Remember whether this call actually set the flag and only clear it in
that case.

Fixes: d475a507457b ("ubifs: Add skeleton for fscrypto")
Cc: stable@vger.kernel.org
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
index 3b0e8a270f59..7f82ddb9e3f2 100644
--- a/fs/ubifs/xattr.c
+++ b/fs/ubifs/xattr.c
@@ -69,6 +69,7 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
 			const struct fscrypt_name *nm, const void *value, int size)
 {
 	int err, names_len;
+	bool set_crypt = false;
 	struct inode *inode;
 	struct ubifs_inode *ui, *host_ui = ubifs_inode(host);
 	struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
@@ -133,8 +134,10 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
 	 * To avoid multiple updates of the same inode in the same operation,
 	 * let's do it here.
 	 */
-	if (strcmp(fname_name(nm), UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0)
+	if (strcmp(fname_name(nm), UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0) {
+		set_crypt = !(host_ui->flags & UBIFS_CRYPT_FL);
 		host_ui->flags |= UBIFS_CRYPT_FL;
+	}
 
 	err = ubifs_jnl_update(c, host, nm, inode, 0, 1, 0);
 	if (err)
@@ -152,7 +155,8 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
 	host_ui->xattr_size -= CALC_DENT_SIZE(fname_len(nm));
 	host_ui->xattr_size -= CALC_XATTR_BYTES(size);
 	host_ui->xattr_names -= fname_len(nm);
-	host_ui->flags &= ~UBIFS_CRYPT_FL;
+	if (set_crypt)
+		host_ui->flags &= ~UBIFS_CRYPT_FL;
 	mutex_unlock(&host_ui->ui_mutex);
 out_free:
 	make_bad_inode(inode);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/3] ubifs: xattr: preserve the encryption flag when creation fails
  2026-11-02 11:56 [PATCH 2/3] ubifs: xattr: preserve the encryption flag when creation fails shao.mingyin
@ 2026-11-02 13:35 ` Zhihao Cheng
  0 siblings, 0 replies; 3+ messages in thread
From: Zhihao Cheng @ 2026-11-02 13:35 UTC (permalink / raw)
  To: shao.mingyin, richard, linux-mtd, linux-kernel, stable

在 2026/11/2 19:56, shao.mingyin@zte.com.cn 写道:
> create_xattr() clears UBIFS_CRYPT_FL in its error path regardless of
> whether this call set the flag.  The flag is also set for every inode
> that already carries an encryption context, so a failed setxattr() on
> such an inode clears it from the in-memory inode.  The next inode write
> then packs ui->flags without UBIFS_CRYPT_FL, and after the next mount
> the inode is no longer treated as encrypted although its names and data
> still are.  ubifs_jnl_update() can fail before anything is written, for
> example when its journal buffer cannot be allocated.
> 
> Remember whether this call actually set the flag and only clear it in
> that case.
> 
> Fixes: d475a507457b ("ubifs: Add skeleton for fscrypto")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> ---
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
> index 3b0e8a270f59..7f82ddb9e3f2 100644
> --- a/fs/ubifs/xattr.c
> +++ b/fs/ubifs/xattr.c
> @@ -69,6 +69,7 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
>   			const struct fscrypt_name *nm, const void *value, int size)
>   {
>   	int err, names_len;
> +	bool set_crypt = false;
>   	struct inode *inode;
>   	struct ubifs_inode *ui, *host_ui = ubifs_inode(host);
>   	struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
> @@ -133,8 +134,10 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
>   	 * To avoid multiple updates of the same inode in the same operation,
>   	 * let's do it here.
>   	 */
> -	if (strcmp(fname_name(nm), UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0)
> +	if (strcmp(fname_name(nm), UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0) {
> +		set_crypt = !(host_ui->flags & UBIFS_CRYPT_FL);
>   		host_ui->flags |= UBIFS_CRYPT_FL;
> +	}
>   
>   	err = ubifs_jnl_update(c, host, nm, inode, 0, 1, 0);
>   	if (err)
> @@ -152,7 +155,8 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
>   	host_ui->xattr_size -= CALC_DENT_SIZE(fname_len(nm));
>   	host_ui->xattr_size -= CALC_XATTR_BYTES(size);
>   	host_ui->xattr_names -= fname_len(nm);
> -	host_ui->flags &= ~UBIFS_CRYPT_FL;
> +	if (set_crypt)
> +		host_ui->flags &= ~UBIFS_CRYPT_FL;
>   	mutex_unlock(&host_ui->ui_mutex);
>   out_free:
>   	make_bad_inode(inode);
> .
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/3] ubifs: xattr: preserve the encryption flag when creation fails
  2026-11-02 11:50 [PATCH 0/3] ubifs: fix an auth node leak and two error-handling bugs shao.mingyin
@ 2026-11-02 12:13 ` shao.mingyin
  0 siblings, 0 replies; 3+ messages in thread
From: shao.mingyin @ 2026-11-02 12:13 UTC (permalink / raw)
  To: richard, linux-mtd; +Cc: chengzhihao1, linux-kernel, stable

create_xattr() clears UBIFS_CRYPT_FL in its error path regardless of
whether this call set the flag.  The flag is also set for every inode
that already carries an encryption context, so a failed setxattr() on
such an inode clears it from the in-memory inode.  The next inode write
then packs ui->flags without UBIFS_CRYPT_FL, and after the next mount
the inode is no longer treated as encrypted although its names and data
still are.  ubifs_jnl_update() can fail before anything is written, for
example when its journal buffer cannot be allocated.

Remember whether this call actually set the flag and only clear it in
that case.

Fixes: d475a507457b ("ubifs: Add skeleton for fscrypto")
Cc: stable@vger.kernel.org
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
index 3b0e8a270f59..7f82ddb9e3f2 100644
--- a/fs/ubifs/xattr.c
+++ b/fs/ubifs/xattr.c
@@ -69,6 +69,7 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
 			const struct fscrypt_name *nm, const void *value, int size)
 {
 	int err, names_len;
+	bool set_crypt = false;
 	struct inode *inode;
 	struct ubifs_inode *ui, *host_ui = ubifs_inode(host);
 	struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
@@ -133,8 +134,10 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
 	 * To avoid multiple updates of the same inode in the same operation,
 	 * let's do it here.
 	 */
-	if (strcmp(fname_name(nm), UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0)
+	if (strcmp(fname_name(nm), UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0) {
+		set_crypt = !(host_ui->flags & UBIFS_CRYPT_FL);
 		host_ui->flags |= UBIFS_CRYPT_FL;
+	}

 	err = ubifs_jnl_update(c, host, nm, inode, 0, 1, 0);
 	if (err)
@@ -152,7 +155,8 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
 	host_ui->xattr_size -= CALC_DENT_SIZE(fname_len(nm));
 	host_ui->xattr_size -= CALC_XATTR_BYTES(size);
 	host_ui->xattr_names -= fname_len(nm);
-	host_ui->flags &= ~UBIFS_CRYPT_FL;
+	if (set_crypt)
+		host_ui->flags &= ~UBIFS_CRYPT_FL;
 	mutex_unlock(&host_ui->ui_mutex);
 out_free:
 	make_bad_inode(inode);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-02 13:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 11:56 [PATCH 2/3] ubifs: xattr: preserve the encryption flag when creation fails shao.mingyin
2026-11-02 13:35 ` Zhihao Cheng
  -- strict thread matches above, loose matches on Subject: below --
2026-11-02 11:50 [PATCH 0/3] ubifs: fix an auth node leak and two error-handling bugs shao.mingyin
2026-11-02 12:13 ` [PATCH 2/3] ubifs: xattr: preserve the encryption flag when creation fails shao.mingyin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®