Skip to contentSkip to conversation

eCryptfs: fix ecryptfs_privileged_open() for read only files

PATCH In review Dan Carpenter 2 participants 3 messages Jun 9, 2012 – Jun 12, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eCryptfs: fix ecryptfs_privileged_open() for read only files

The intent here is to handle read only opens differently. For example, if we don't want to create the file if it doesn't exist. The problem here is that O_RDONLY is 0 and if (x & 0) {... is always false.

---
This is a static checker bug, and I am not very familiar with eCryptfs. Please review carefully.

fs/ecryptfs/kthread.c +1 -1
index 69f994a..d01b364 100644
@@ -149,7 +149,7 @@ int ecryptfs_privileged_open(struct file **lower_file,
 	(*lower_file) = dentry_open(lower_dentry, lower_mnt, flags, cred);
 	if (!IS_ERR(*lower_file))
 		goto out;
-	if (flags & O_RDONLY) {
+	if (!(flags & O_RDWR)) {
 		rc = PTR_ERR((*lower_file));
 		goto out;
 	}
#1 lore raw
Quoted 5 lines · Dan Carpenter

The intent here is to handle read only opens differently. For example, if we don't want to create the file if it doesn't exist. The problem here is that O_RDONLY is 0 and if (x & 0) {... is always false.

Thanks, Dan! I committed a slightly different fix with more context in the commit message (because I had to remind myself what was going on with that conditional in the first place).

http://git.kernel.org/?p=linux/kernel/git/tyhicks/ecryptfs.git;a=commitdiff;h=91425d9b57c024bf8b28055b6a480809fe0941ee

Tyler

Quoted 21 lines

---
This is a static checker bug, and I am not very familiar with eCryptfs. Please review carefully.

fs/ecryptfs/kthread.c +1 -2
index 69f994a..d01b364 100644
@@ -149,7 +149,7 @@ int ecryptfs_privileged_open(struct file **lower_file,
 	(*lower_file) = dentry_open(lower_dentry, lower_mnt, flags, cred);
 	if (!IS_ERR(*lower_file))
 		goto out;
-	if (flags & O_RDONLY) {
+	if (!(flags & O_RDWR)) {
 		rc = PTR_ERR((*lower_file));
 		goto out;
 	}
--

To unsubscribe from this list: send the line "unsubscribe ecryptfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 5 lines · Tyler Hicks
Quoted 4 lines · Dan Carpenter

The intent here is to handle read only opens differently. For example, if we don't want to create the file if it doesn't exist. The problem here is that O_RDONLY is 0 and if (x & 0) {... is always false.

Quoted 8 lines
Quoted 1 line

Thanks, Dan! I committed a slightly different fix with more context in the commit message (because I had to remind myself what was going on with that conditional in the first place).

http://git.kernel.org/?p=linux/kernel/git/tyhicks/ecryptfs.git;a=commitdiff;h‘425d9b57c024bf8b28055b6a480809fe0941ee

Looks good.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html