cap_inode_getsecurity: use d_find_any_alias() instead of d_find_alias()
PATCH v2 1/1 cap_inode_getsecurity: use d_find_any_alias() instead of d_find_alias()
In reply to a message not in the archiveEric,
Ping for your attention.
Quoted 36 lines · Eddie.Horng
The code in
cap_inode_getsecurity(), introduced by commit8db6c34f1dbc("Introduce v3 namespaced file capabilities"), should used_find_any_alias()instead ofd_find_alias()do handle unhashed dentry correctly. This is needed, for example, ifexecveat()is called with an open but unlinked overlayfs file, because overlayfs unhashes dentry on unlink.Below reproducer and setup can reproduce the case.
const char* exec="echo";
const char *newargv[] = { "echo", "hello", NULL}; const char *newenviron[] = { NULL };
int fd, err;fd = open(exec, O_PATH); unlink(exec); err = syscall(322/*SYS_execveat*/, fd, "", newargv, newenviron, AT_EMPTY_PATH); if(err<0) fprintf(stderr, "execveat: %s\n", strerror(errno));gcc compile into ~/test/a.out
mount -t overlay -orw,lowerdir=/mnt/l,upperdir=/mnt/u,workdir=/mnt/w
none/mnt/mcd
/mnt/m
cp/bin/echo.
~/test/a.outExpected result:
hello
Actually result:
execveat: Invalid argument
dmesg:
Invalid argument reading file caps for/dev/fd/3
Quoted 5 lines
Suggested-by Amir Goldstein <[email protected]>Acked-by Amir Goldstein <[email protected]>Fixes 8db6c34f1dbc ("Introduce v3 namespaced file capabilities")Signed-off-by Eddie Horng <[email protected]>---
Eddie,
Please post v3 with changes:
- Add acked-by Serge
- Add Cc: <[email protected]> # v4.14
- Reproducer without overlayfs
Thanks,
Amir.
Quoted 22 lines
Changes in v2:
- fix commit message wrapped at 74 chars
- added previous acked-bysecurity/commoncap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/commoncap.c +1
-2@@ -388,7 +388,7 @@ int cap_inode_getsecurity(struct inode *inode, const char *name, void **buffer, if (strcmp(name, "capability") != 0) return -EOPNOTSUPP; - dentry =d_find_alias (inode); + dentry =d_find_any_alias (inode);if (!dentry)return -EINVAL ; --
Quoted 3 lines
2.12.5
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html