Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] fs/affs: Fix basic permission bits to actually work
@ 2020-08-27 15:49 Max Staudt
  2020-08-27 15:51 ` John Paul Adrian Glaubitz
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Max Staudt @ 2020-08-27 15:49 UTC (permalink / raw)
  To: David Sterba
  Cc: linux-fsdevel, Geert Uytterhoeven, linux-m68k, glaubitz,
	linux-kernel, Max Staudt, stable

The basic permission bits (protection bits in AmigaOS) have been broken
in Linux' affs - it would only set bits, but never delete them.
Also, contrary to the documentation, the Archived bit was not handled.

Let's fix this for good, and set the bits such that Linux and classic
AmigaOS can coexist in the most peaceful manner.

Also, update the documentation to represent the current state of things.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Max Staudt <max@enpas.org>
---
 Documentation/filesystems/affs.rst | 16 ++++++++++------
 fs/affs/amigaffs.c                 | 27 +++++++++++++++++++++++++++
 fs/affs/file.c                     | 27 ++++++++++++++++++++++++++-
 3 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/Documentation/filesystems/affs.rst b/Documentation/filesystems/affs.rst
index 7f1a40dce6d3..5776cbd5fa53 100644
--- a/Documentation/filesystems/affs.rst
+++ b/Documentation/filesystems/affs.rst
@@ -110,13 +110,15 @@ The Amiga protection flags RWEDRWEDHSPARWED are handled as follows:
 
   - R maps to r for user, group and others. On directories, R implies x.
 
-  - If both W and D are allowed, w will be set.
+  - W maps to w.
 
   - E maps to x.
 
-  - H and P are always retained and ignored under Linux.
+  - D is ignored.
 
-  - A is always reset when a file is written to.
+  - H, S and P are always retained and ignored under Linux.
+
+  - A is cleared when a file is written to.
 
 User id and group id will be used unless set[gu]id are given as mount
 options. Since most of the Amiga file systems are single user systems
@@ -128,11 +130,13 @@ Linux -> Amiga:
 
 The Linux rwxrwxrwx file mode is handled as follows:
 
-  - r permission will set R for user, group and others.
+  - r permission will allow R for user, group and others.
+
+  - w permission will allow W for user, group and others.
 
-  - w permission will set W and D for user, group and others.
+  - x permission of the user will allow E for plain files.
 
-  - x permission of the user will set E for plain files.
+  - D will be allowed for user, group and others.
 
   - All other flags (suid, sgid, ...) are ignored and will
     not be retained.
diff --git a/fs/affs/amigaffs.c b/fs/affs/amigaffs.c
index f708c45d5f66..7952f885e6c6 100644
--- a/fs/affs/amigaffs.c
+++ b/fs/affs/amigaffs.c
@@ -420,24 +420,51 @@ affs_mode_to_prot(struct inode *inode)
 	u32 prot = AFFS_I(inode)->i_protect;
 	umode_t mode = inode->i_mode;
 
+	/*
+	 * First, clear all RWED bits for owner, group, other.
+	 * Then, recalculate them afresh.
+	 *
+	 * We'll always clear the delete-inhibit bit for the owner,
+	 * as that is the classic single-user mode AmigaOS protection
+	 * bit and we need to stay compatible with all scenarios.
+	 *
+	 * Since multi-user AmigaOS is an extension, we'll only set
+	 * the delete-allow bit if any of the other bits in the same
+	 * user class (group/other) are used.
+	 */
+	prot &= ~(FIBF_NOEXECUTE | FIBF_NOREAD
+		  | FIBF_NOWRITE | FIBF_NODELETE
+		  | FIBF_GRP_EXECUTE | FIBF_GRP_READ
+		  | FIBF_GRP_WRITE   | FIBF_GRP_DELETE
+		  | FIBF_OTR_EXECUTE | FIBF_OTR_READ
+		  | FIBF_OTR_WRITE   | FIBF_OTR_DELETE);
+
+	/* Classic single-user AmigaOS flags. These are inverted. */
 	if (!(mode & 0100))
 		prot |= FIBF_NOEXECUTE;
 	if (!(mode & 0400))
 		prot |= FIBF_NOREAD;
 	if (!(mode & 0200))
 		prot |= FIBF_NOWRITE;
+
+	/* Multi-user extended flags. Not inverted. */
 	if (mode & 0010)
 		prot |= FIBF_GRP_EXECUTE;
 	if (mode & 0040)
 		prot |= FIBF_GRP_READ;
 	if (mode & 0020)
 		prot |= FIBF_GRP_WRITE;
+	if (mode & 0070)
+		prot |= FIBF_GRP_DELETE;
+
 	if (mode & 0001)
 		prot |= FIBF_OTR_EXECUTE;
 	if (mode & 0004)
 		prot |= FIBF_OTR_READ;
 	if (mode & 0002)
 		prot |= FIBF_OTR_WRITE;
+	if (mode & 0007)
+		prot |= FIBF_OTR_DELETE;
 
 	AFFS_I(inode)->i_protect = prot;
 }
diff --git a/fs/affs/file.c b/fs/affs/file.c
index a26a0f96c119..9a137e2f1782 100644
--- a/fs/affs/file.c
+++ b/fs/affs/file.c
@@ -429,6 +429,25 @@ static int affs_write_begin(struct file *file, struct address_space *mapping,
 	return ret;
 }
 
+static int affs_write_end(struct file *file, struct address_space *mapping,
+			  loff_t pos, unsigned int len, unsigned int copied,
+			  struct page *page, void *fsdata)
+{
+	struct inode *inode = mapping->host;
+	int ret;
+
+	ret = generic_write_end(file, mapping, pos, len, copied,
+				page, fsdata);
+
+	/* Clear Archived bit on file writes, as AmigaOS would do */
+	if (AFFS_I(inode)->i_protect & FIBF_ARCHIVED) {
+		AFFS_I(inode)->i_protect &= ~FIBF_ARCHIVED;
+		mark_inode_dirty(inode);
+	}
+
+	return ret;
+}
+
 static sector_t _affs_bmap(struct address_space *mapping, sector_t block)
 {
 	return generic_block_bmap(mapping,block,affs_get_block);
@@ -438,7 +457,7 @@ const struct address_space_operations affs_aops = {
 	.readpage = affs_readpage,
 	.writepage = affs_writepage,
 	.write_begin = affs_write_begin,
-	.write_end = generic_write_end,
+	.write_end = affs_write_end,
 	.direct_IO = affs_direct_IO,
 	.bmap = _affs_bmap
 };
@@ -795,6 +814,12 @@ static int affs_write_end_ofs(struct file *file, struct address_space *mapping,
 	if (tmp > inode->i_size)
 		inode->i_size = AFFS_I(inode)->mmu_private = tmp;
 
+	/* Clear Archived bit on file writes, as AmigaOS would do */
+	if (AFFS_I(inode)->i_protect & FIBF_ARCHIVED) {
+		AFFS_I(inode)->i_protect &= ~FIBF_ARCHIVED;
+		mark_inode_dirty(inode);
+	}
+
 err_first_bh:
 	unlock_page(page);
 	put_page(page);
-- 
2.20.1


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

* Re: [PATCH] fs/affs: Fix basic permission bits to actually work
  2020-08-27 15:49 [PATCH] fs/affs: Fix basic permission bits to actually work Max Staudt
@ 2020-08-27 15:51 ` John Paul Adrian Glaubitz
  2020-08-31  9:38 ` David Sterba
  2020-09-25 10:07 ` John Paul Adrian Glaubitz
  2 siblings, 0 replies; 5+ messages in thread
From: John Paul Adrian Glaubitz @ 2020-08-27 15:51 UTC (permalink / raw)
  To: Max Staudt, David Sterba
  Cc: linux-fsdevel, Geert Uytterhoeven, linux-m68k, linux-kernel, stable

Hi Max!

On 8/27/20 5:49 PM, Max Staudt wrote:
> The basic permission bits (protection bits in AmigaOS) have been broken
> in Linux' affs - it would only set bits, but never delete them.
> Also, contrary to the documentation, the Archived bit was not handled.
> 
> Let's fix this for good, and set the bits such that Linux and classic
> AmigaOS can coexist in the most peaceful manner.
> 
> Also, update the documentation to represent the current state of things.

I haven't tested this yet (obviously) but thanks a lot for fixing this :-).

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaubitz@debian.org
`. `'   Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

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

* Re: [PATCH] fs/affs: Fix basic permission bits to actually work
  2020-08-27 15:49 [PATCH] fs/affs: Fix basic permission bits to actually work Max Staudt
  2020-08-27 15:51 ` John Paul Adrian Glaubitz
@ 2020-08-31  9:38 ` David Sterba
  2020-09-25 10:07 ` John Paul Adrian Glaubitz
  2 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2020-08-31  9:38 UTC (permalink / raw)
  To: Max Staudt
  Cc: David Sterba, linux-fsdevel, Geert Uytterhoeven, linux-m68k,
	glaubitz, linux-kernel, stable

On Thu, Aug 27, 2020 at 05:49:00PM +0200, Max Staudt wrote:
> The basic permission bits (protection bits in AmigaOS) have been broken
> in Linux' affs - it would only set bits, but never delete them.
> Also, contrary to the documentation, the Archived bit was not handled.
> 
> Let's fix this for good, and set the bits such that Linux and classic
> AmigaOS can coexist in the most peaceful manner.
> 
> Also, update the documentation to represent the current state of things.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Max Staudt <max@enpas.org>

Thanks, patch looks good to me, I'll send a pull request to Linus this
week.

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

* Re: [PATCH] fs/affs: Fix basic permission bits to actually work
  2020-08-27 15:49 [PATCH] fs/affs: Fix basic permission bits to actually work Max Staudt
  2020-08-27 15:51 ` John Paul Adrian Glaubitz
  2020-08-31  9:38 ` David Sterba
@ 2020-09-25 10:07 ` John Paul Adrian Glaubitz
  2020-09-25 16:21   ` Max Staudt
  2 siblings, 1 reply; 5+ messages in thread
From: John Paul Adrian Glaubitz @ 2020-09-25 10:07 UTC (permalink / raw)
  To: Max Staudt, David Sterba
  Cc: linux-fsdevel, Geert Uytterhoeven, linux-m68k, linux-kernel, stable

Hi Max!

On 8/27/20 5:49 PM, Max Staudt wrote:
> The basic permission bits (protection bits in AmigaOS) have been broken
> in Linux' affs - it would only set bits, but never delete them.
> Also, contrary to the documentation, the Archived bit was not handled.
> 
> Let's fix this for good, and set the bits such that Linux and classic
> AmigaOS can coexist in the most peaceful manner.
> 
> Also, update the documentation to represent the current state of things.
Has there already been any progress on reviewing this?

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaubitz@debian.org
`. `'   Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

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

* Re: [PATCH] fs/affs: Fix basic permission bits to actually work
  2020-09-25 10:07 ` John Paul Adrian Glaubitz
@ 2020-09-25 16:21   ` Max Staudt
  0 siblings, 0 replies; 5+ messages in thread
From: Max Staudt @ 2020-09-25 16:21 UTC (permalink / raw)
  To: John Paul Adrian Glaubitz, David Sterba
  Cc: linux-fsdevel, Geert Uytterhoeven, linux-m68k, linux-kernel, stable

On 9/25/20 12:07 PM, John Paul Adrian Glaubitz wrote:
> Has there already been any progress on reviewing this?

It has already been merged, and the maintainers have been so kind as to backport it to all maintained stable branches.

Thanks for your help, everyone!


Max

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

end of thread, other threads:[~2020-09-25 16:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 15:49 [PATCH] fs/affs: Fix basic permission bits to actually work Max Staudt
2020-08-27 15:51 ` John Paul Adrian Glaubitz
2020-08-31  9:38 ` David Sterba
2020-09-25 10:07 ` John Paul Adrian Glaubitz
2020-09-25 16:21   ` Max Staudt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).