Skip to contentSkip to conversation

sysfs_chmod_file() broken in 2.6.33-rc4-git6

PATCH In review Eric W. Biederman 3 participants 12 messages Jan 20, 2010 – Feb 11, 2010 1 message not in the archive Driver core

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 23 lines · Jean Delvare

Hi Eric, Greg,

While working on a driver using 2.6.33-rc4-git6 as my environment, I have found that sysfs_chmod_file() called from a kernel driver no longer works. It doesn't return any error nor print any message in the logs, it simply has no effect. The same code worked fine using kernel 2.6.32. I have bisected it down to the following commit:

commit e61ab4ae48fbf477f5b9fcbec9e1b8dc789920d0

Author: Eric W. Biederman <[email protected]>
Date:   Fri Nov 20 16:08:53 2009 -0800

sysfs: Implement sysfs_getattr & sysfs_permission

With the implementation of sysfs_getattr and sysfs_permission sysfs becomes able to lazily propogate inode attribute changes
from the sysfs_dirents to the vfs inodes. This paves the way
for deleting significant chunks of now unnecessary code.

While doing this we did not reference sysfs_setattr from sysfs_symlink_inode_operations so I added along with sysfs_getattr and sysfs_permission.

Quoted 7 lines

Eric, can you please look at your code again and see if you can find any obvious issue?

Does this fix your issue?

Eric

fs/sysfs/inode.c +17 -18
index 220b758..6a06a1d 100644
@@ -81,24 +81,23 @@ int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = iattr->ia_atime;
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = iattr->ia_mtime;
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = iattr->ia_ctime;
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = iattr->ia_atime;
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = iattr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = iattr->ia_ctime;
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return 0;
 }
#2 lore raw
Quoted 74 lines · Eric W. Biederman
Quoted 23 lines · Jean Delvare

Hi Eric, Greg,

While working on a driver using 2.6.33-rc4-git6 as my environment, I have found that sysfs_chmod_file() called from a kernel driver no longer works. It doesn't return any error nor print any message in the logs, it simply has no effect. The same code worked fine using kernel 2.6.32. I have bisected it down to the following commit:

commit e61ab4ae48fbf477f5b9fcbec9e1b8dc789920d0

Author: Eric W. Biederman <[email protected]>
Date:   Fri Nov 20 16:08:53 2009 -0800

sysfs: Implement sysfs_getattr & sysfs_permission

With the implementation of sysfs_getattr and sysfs_permission sysfs becomes able to lazily propogate inode attribute changes
from the sysfs_dirents to the vfs inodes. This paves the way
for deleting significant chunks of now unnecessary code.

While doing this we did not reference sysfs_setattr from sysfs_symlink_inode_operations so I added along with sysfs_getattr and sysfs_permission.

Quoted 7 lines

Eric, can you please look at your code again and see if you can find any obvious issue?

Does this fix your issue?

Eric

fs/sysfs/inode.c +10 -18
index 220b758..6a06a1d 100644
@@ -81,24 +81,23 @@ int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = iattr->ia_atime;
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = iattr->ia_mtime;
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = iattr->ia_ctime;
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = iattr->ia_atime;

fs/sysfs/inode.c int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr) · line 103

Quoted 10 lines
fs/sysfs/inode.c +7 -0
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = iattr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = iattr->ia_ctime;
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return 0;
 }

Yes, this fixes my problem. Thanks for the fast fix!

Signature · 1 line
Jean Delvare
#3 lore raw
Quoted 79 lines · Jean Delvare
Quoted 78 lines · Eric W. Biederman
Quoted 23 lines · Jean Delvare

Hi Eric, Greg,

While working on a driver using 2.6.33-rc4-git6 as my environment, I have found that sysfs_chmod_file() called from a kernel driver no longer works. It doesn't return any error nor print any message in the logs, it simply has no effect. The same code worked fine using kernel 2.6.32. I have bisected it down to the following commit:

commit e61ab4ae48fbf477f5b9fcbec9e1b8dc789920d0

Author: Eric W. Biederman <[email protected]>
Date:   Fri Nov 20 16:08:53 2009 -0800

sysfs: Implement sysfs_getattr & sysfs_permission

With the implementation of sysfs_getattr and sysfs_permission sysfs becomes able to lazily propogate inode attribute changes
from the sysfs_dirents to the vfs inodes. This paves the way
for deleting significant chunks of now unnecessary code.

While doing this we did not reference sysfs_setattr from sysfs_symlink_inode_operations so I added along with sysfs_getattr and sysfs_permission.

Quoted 7 lines

Eric, can you please look at your code again and see if you can find any obvious issue?

Does this fix your issue?

Eric

fs/sysfs/inode.c +14 -18
index 220b758..6a06a1d 100644
@@ -81,24 +81,23 @@ int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = iattr->ia_atime;
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = iattr->ia_mtime;
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = iattr->ia_ctime;
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = iattr->ia_atime;
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = iattr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = iattr->ia_ctime;
Quoted 8 lines

fs/sysfs/inode.c int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr) · line 103

Quoted 6 lines
fs/sysfs/inode.c +3 -0
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return 0;
 }

Yes, this fixes my problem. Thanks for the fast fix!

Great, Eric, care to resend this so that I can submit it for inclusion?

thanks,

greg k-h

#4 lore raw
Quoted 56 lines · Greg KH
Quoted 46 lines · Jean Delvare
Quoted 45 lines · Eric W. Biederman

Does this fix your issue?

Eric

fs/sysfs/inode.c +14 -18
index 220b758..6a06a1d 100644
@@ -81,24 +81,23 @@ int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = iattr->ia_atime;
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = iattr->ia_mtime;
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = iattr->ia_ctime;
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = iattr->ia_atime;
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = iattr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = iattr->ia_ctime;
Quoted 8 lines

fs/sysfs/inode.c int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr) · line 103

Quoted 6 lines
fs/sysfs/inode.c +3 -0
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return 0;
 }

Yes, this fixes my problem. Thanks for the fast fix!

Quoted 1 line

Great, Eric, care to resend this so that I can submit it for inclusion?

Ping Eric, the patch is still not in Linus' tree.

Signature · 1 line
Jean Delvare
#5 lore raw
Quoted 57 lines · Jean Delvare
Quoted 56 lines · Greg KH
Quoted 54 lines · Jean Delvare
Quoted 41 lines · Eric W. Biederman

Does this fix your issue?

Eric

fs/sysfs/inode.c +10 -18
index 220b758..6a06a1d 100644
@@ -81,24 +81,23 @@ int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = iattr->ia_atime;
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = iattr->ia_mtime;
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = iattr->ia_ctime;
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = iattr->ia_atime;

fs/sysfs/inode.c int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr) · line 103

Quoted 10 lines
fs/sysfs/inode.c +7 -0
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = iattr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = iattr->ia_ctime;
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return 0;
 }

Yes, this fixes my problem. Thanks for the fast fix!

Quoted 3 lines
Quoted 1 line

Great, Eric, care to resend this so that I can submit it for inclusion?

Ping Eric, the patch is still not in Linus' tree.

Nor mine :)

Eric, care to send it to me?

thanks,

greg k-h

#6 lore raw
Quoted 58 lines · Greg KH
Quoted 57 lines · Jean Delvare
Quoted 56 lines · Greg KH
Quoted 54 lines · Jean Delvare
Quoted 41 lines · Eric W. Biederman

Does this fix your issue?

Eric

fs/sysfs/inode.c +10 -18
index 220b758..6a06a1d 100644
@@ -81,24 +81,23 @@ int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = iattr->ia_atime;
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = iattr->ia_mtime;
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = iattr->ia_ctime;
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = iattr->ia_atime;

fs/sysfs/inode.c int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr) · line 103

Quoted 10 lines
fs/sysfs/inode.c +7 -0
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = iattr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = iattr->ia_ctime;
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return 0;
 }

Yes, this fixes my problem. Thanks for the fast fix!

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Great, Eric, care to resend this so that I can submit it for inclusion?

Ping Eric, the patch is still not in Linus' tree.

Nor mine :)

Eric, care to send it to me?

Apologies for the long delay. I have been extremely out of it lately. I am should have a signed off by version sent shortly. I looked and this problem also exists in 2.6.32 but hides because in that case we directly update the vfs inode so sysfs_chmod works until the vfs inode
is evicted. I will send you a patch for 2.6.32 -stable as well.

Eric

#7 lore raw

PATCH 1/1 sysfs: sysfs_sd_setattr set iattrs unconditionally

In reply to Greg KH

There is currently a bug in sysfs_sd_setattr inherited from sysfs_setattr in 2.6.32 where the first time we set the attributes on a sysfs file we allocate backing store but do not set the backing store attributes. Resulting in overly restrictive permissions on sysfs files.

The fix is to simply modify the code so that it always executes when we update the sysfs attributes, as we did in 2.6.31 and earlier.

---
 fs/sysfs/inode.c |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)
fs/sysfs/inode.c +17 -18
index 220b758..6a06a1d 100644
@@ -81,24 +81,23 @@ int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = iattr->ia_atime;
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = iattr->ia_mtime;
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = iattr->ia_ctime;
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = iattr->ia_atime;
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = iattr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = iattr->ia_ctime;
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return 0;
 }
Signature · 1 line
1.6.5.2.143.g8cc62
Tested-by on v1 1/1
#8 lore raw

Re: [PATCH] sysfs: sysfs_sd_setattr set iattrs unconditionally

Quoted 11 lines · Eric W. Biederman

There is currently a bug in sysfs_sd_setattr inherited from sysfs_setattr in 2.6.32 where the first time we set the attributes on a sysfs file we allocate backing store but do not set the backing store attributes. Resulting in overly restrictive permissions on sysfs files.

The fix is to simply modify the code so that it always executes when we update the sysfs attributes, as we did in 2.6.31 and earlier.

Quoted 50 lines
---
 fs/sysfs/inode.c |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)
fs/sysfs/inode.c +17 -18
index 220b758..6a06a1d 100644
@@ -81,24 +81,23 @@ int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = iattr->ia_atime;
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = iattr->ia_mtime;
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = iattr->ia_ctime;
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = iattr->ia_atime;
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = iattr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = iattr->ia_ctime;
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return 0;
 }
Signature · 1 line
Jean Delvare
#9 lore raw

Re: [PATCH] sysfs: sysfs_sd_setattr set iattrs unconditionally

In reply to Eric W. Biederman

Greg I think this patch has slipped through the cracks.
Do I need to resend this regression fix or send it directly to Linus?

chmod and friends have been broken on sysfs since 2.6.32...

Eric

Quoted 62 lines · [email protected] (Eric W. Biederman) writes:

There is currently a bug in sysfs_sd_setattr inherited from sysfs_setattr in 2.6.32 where the first time we set the attributes on a sysfs file we allocate backing store but do not set the backing store attributes. Resulting in overly restrictive permissions on sysfs files.

The fix is to simply modify the code so that it always executes when we update the sysfs attributes, as we did in 2.6.31 and earlier.

---
 fs/sysfs/inode.c |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)
fs/sysfs/inode.c +17 -18
index 220b758..6a06a1d 100644
@@ -81,24 +81,23 @@ int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = iattr->ia_atime;
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = iattr->ia_mtime;
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = iattr->ia_ctime;
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = iattr->ia_atime;
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = iattr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = iattr->ia_ctime;
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return 0;
 }
Signature · 1 line
1.6.5.2.143.g8cc62
#10 lore raw

Re: [PATCH] sysfs: sysfs_sd_setattr set iattrs unconditionally

Quoted 5 lines · Eric W. Biederman

Greg I think this patch has slipped through the cracks.
Do I need to resend this regression fix or send it directly to Linus?

chmod and friends have been broken on sysfs since 2.6.32...

Sorry, I was travelling last week, it's still in my queue, I'll get it to Linus soon.

thanks,

greg k-h

#11 lore raw

Re: [PATCH] sysfs: sysfs_sd_setattr set iattrs unconditionally

Quoted 9 lines · Greg KH
Quoted 5 lines · Eric W. Biederman

Greg I think this patch has slipped through the cracks.
Do I need to resend this regression fix or send it directly to Linus?

chmod and friends have been broken on sysfs since 2.6.32...

Sorry, I was travelling last week, it's still in my queue, I'll get it to Linus soon.

That is a better excuse than my nasty cold. Thanks for taking care of this.

Eric

#12 lore raw

PATCH 1/1 sysfs: sysfs_setattr set iattrs unconditionally

In reply to Greg KH

There is currently a bug in sysfs_setattr where the first time we set the attributes on a sysfs file we allocate backing store but do not set the backing store attributes. Resulting in overly restrictive permissions on sysfs files.

This bug is masked by the fact we that we do update the vfs inode so it will only show up after the vfs inode has been evicted causing surprise sysfs attribute changes.

The fix is to simply modify the code so that it always executes when we update the sysfs attributes, as we did in 2.6.31 and earlier.

This is a backported version of my similiar change for 2.6.33-rc6 against sysfs_sd_setattr, for the stable 2.6.32 tree.

---
 fs/sysfs/inode.c |   47 +++++++++++++++++++++++------------------------
 1 files changed, 23 insertions(+), 24 deletions(-)
fs/sysfs/inode.c +23 -24
index e28cecf..02a022a 100644
@@ -94,30 +94,29 @@ int sysfs_setattr(struct dentry * dentry, struct iattr * iattr)
 		if (!sd_attrs)
 			return -ENOMEM;
 		sd->s_iattr = sd_attrs;
-	} else {
-		/* attributes were changed at least once in past */
-		iattrs = &sd_attrs->ia_iattr;
-
-		if (ia_valid & ATTR_UID)
-			iattrs->ia_uid = iattr->ia_uid;
-		if (ia_valid & ATTR_GID)
-			iattrs->ia_gid = iattr->ia_gid;
-		if (ia_valid & ATTR_ATIME)
-			iattrs->ia_atime = timespec_trunc(iattr->ia_atime,
-					inode->i_sb->s_time_gran);
-		if (ia_valid & ATTR_MTIME)
-			iattrs->ia_mtime = timespec_trunc(iattr->ia_mtime,
-					inode->i_sb->s_time_gran);
-		if (ia_valid & ATTR_CTIME)
-			iattrs->ia_ctime = timespec_trunc(iattr->ia_ctime,
-					inode->i_sb->s_time_gran);
-		if (ia_valid & ATTR_MODE) {
-			umode_t mode = iattr->ia_mode;
-
-			if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
-				mode &= ~S_ISGID;
-			iattrs->ia_mode = sd->s_mode = mode;
-		}
+	}
+	/* attributes were changed at least once in past */
+	iattrs = &sd_attrs->ia_iattr;
+
+	if (ia_valid & ATTR_UID)
+		iattrs->ia_uid = iattr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		iattrs->ia_gid = iattr->ia_gid;
+	if (ia_valid & ATTR_ATIME)
+		iattrs->ia_atime = timespec_trunc(iattr->ia_atime,
+			inode->i_sb->s_time_gran);
+	if (ia_valid & ATTR_MTIME)
+		iattrs->ia_mtime = timespec_trunc(iattr->ia_mtime,
+			inode->i_sb->s_time_gran);
+	if (ia_valid & ATTR_CTIME)
+		iattrs->ia_ctime = timespec_trunc(iattr->ia_ctime,
+			inode->i_sb->s_time_gran);
+	if (ia_valid & ATTR_MODE) {
+		umode_t mode = iattr->ia_mode;
+
+		if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
+			mode &= ~S_ISGID;
+		iattrs->ia_mode = sd->s_mode = mode;
 	}
 	return error;
 }
Signature · 1 line
1.6.5.2.143.g8cc62