All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ubifs: atomically set inode->i_flags in ubifs_set_inode_flags()
       [not found] <1397465159-45836-1-git-send-email-zhenzhang.zhang@huawei.com>
@ 2014-04-15  6:15 ` Zhang Zhen
  2014-04-15 13:31   ` Artem Bityutskiy
  0 siblings, 1 reply; 3+ messages in thread
From: Zhang Zhen @ 2014-04-15  6:15 UTC (permalink / raw)
  To: dedekind1, adrian.hunter; +Cc: linux-mtd

Use set_mask_bits() to atomically set i_flags instead of clearing out the
S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the
UBIFS_IMMUTABLE, UBIFS_APPEND_FL, etc. flags, since this opens up a race
where an immutable file has the immutable flag cleared for a brief
window of time.

Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
---
 fs/ubifs/ioctl.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/fs/ubifs/ioctl.c b/fs/ubifs/ioctl.c
index 648b143..5d6df97 100644
--- a/fs/ubifs/ioctl.c
+++ b/fs/ubifs/ioctl.c
@@ -27,6 +27,7 @@
 #include <linux/compat.h>
 #include <linux/mount.h>
 #include "ubifs.h"
+#include <linux/bitops.h>

 /**
  * ubifs_set_inode_flags - set VFS inode flags.
@@ -37,16 +38,18 @@
 void ubifs_set_inode_flags(struct inode *inode)
 {
 	unsigned int flags = ubifs_inode(inode)->flags;
+	unsigned int new_fl = 0;

-	inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_DIRSYNC);
 	if (flags & UBIFS_SYNC_FL)
-		inode->i_flags |= S_SYNC;
+		new_fl |= S_SYNC;
 	if (flags & UBIFS_APPEND_FL)
-		inode->i_flags |= S_APPEND;
+		new_fl |= S_APPEND;
 	if (flags & UBIFS_IMMUTABLE_FL)
-		inode->i_flags |= S_IMMUTABLE;
+		new_fl |= S_IMMUTABLE;
 	if (flags & UBIFS_DIRSYNC_FL)
-		inode->i_flags |= S_DIRSYNC;
+		new_fl |= S_DIRSYNC;
+	set_mask_bits(&inode->i_flags,
+			S_SYNC|S_APPEND|S_IMMUTABLE|S_DIRSYNC, new_fl);
 }

 /*
-- 
1.8.5.5


.

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

* Re: [PATCH] ubifs: atomically set inode->i_flags in ubifs_set_inode_flags()
  2014-04-15  6:15 ` [PATCH] ubifs: atomically set inode->i_flags in ubifs_set_inode_flags() Zhang Zhen
@ 2014-04-15 13:31   ` Artem Bityutskiy
  2014-04-16  2:09     ` Zhang Zhen
  0 siblings, 1 reply; 3+ messages in thread
From: Artem Bityutskiy @ 2014-04-15 13:31 UTC (permalink / raw)
  To: Zhang Zhen; +Cc: linux-mtd, adrian.hunter

On Tue, 2014-04-15 at 14:15 +0800, Zhang Zhen wrote:
> Use set_mask_bits() to atomically set i_flags instead of clearing out the
> S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the
> UBIFS_IMMUTABLE, UBIFS_APPEND_FL, etc. flags, since this opens up a race
> where an immutable file has the immutable flag cleared for a brief
> window of time.
> 
> Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>

Looks correct to me. Does it fix a real-life bug or just a hypothetical
issue? Also, did you test it?

-- 
Best Regards,
Artem Bityutskiy

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

* Re: [PATCH] ubifs: atomically set inode->i_flags in ubifs_set_inode_flags()
  2014-04-15 13:31   ` Artem Bityutskiy
@ 2014-04-16  2:09     ` Zhang Zhen
  0 siblings, 0 replies; 3+ messages in thread
From: Zhang Zhen @ 2014-04-16  2:09 UTC (permalink / raw)
  To: dedekind1; +Cc: linux-mtd, adrian.hunter

On 2014/4/15 21:31, Artem Bityutskiy wrote:
> On Tue, 2014-04-15 at 14:15 +0800, Zhang Zhen wrote:
>> Use set_mask_bits() to atomically set i_flags instead of clearing out the
>> S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the
>> UBIFS_IMMUTABLE, UBIFS_APPEND_FL, etc. flags, since this opens up a race
>> where an immutable file has the immutable flag cleared for a brief
>> window of time.
>>
>> Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
> 
> Looks correct to me. Does it fix a real-life bug or just a hypothetical
> issue? Also, did you test it?
> 
Hi,

It's just a hypothetical issue.

I noticed the commit 00a1a053ebe5febcfc2ec498bd894f035ad2aa06 added the function
set_mask_bits() to atomically set i_flags, and it is also useful to UBIFS.
So i fix it.

Sorry, Because of lacking of test board, i can only guarantee that it has no compile error.

Best regards!

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

end of thread, other threads:[~2014-04-16  2:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1397465159-45836-1-git-send-email-zhenzhang.zhang@huawei.com>
2014-04-15  6:15 ` [PATCH] ubifs: atomically set inode->i_flags in ubifs_set_inode_flags() Zhang Zhen
2014-04-15 13:31   ` Artem Bityutskiy
2014-04-16  2:09     ` Zhang Zhen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.