diff mbox

btrfs-progs: mkfs rootdir: use lgetxattr() not to follow a symbolic link

Message ID f53cc5d0-24ff-81b7-68db-0c615edf4936@jp.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Misono Tomohiro April 2, 2018, 1:59 a.m. UTC
mkfs-test 016 "rootdir-bad-symbolic-link" fails when selinux is enabled.
This is because add_xattr_item() uses getxattr() and tries to follow a
bad symbolic link for selinux item, which causes ENOENT error.

The line above already uses llistxattr() for getting list of xattr in
order not to follow a symbolic link, so just use lgetxattr() too.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
---
 mkfs/rootdir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Qu Wenruo April 2, 2018, 2:09 a.m. UTC | #1
On 2018年04月02日 09:59, Misono Tomohiro wrote:
> mkfs-test 016 "rootdir-bad-symbolic-link" fails when selinux is enabled.
> This is because add_xattr_item() uses getxattr() and tries to follow a
> bad symbolic link for selinux item, which causes ENOENT error.
> 
> The line above already uses llistxattr() for getting list of xattr in
> order not to follow a symbolic link, so just use lgetxattr() too.
> 
> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>  mkfs/rootdir.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mkfs/rootdir.c b/mkfs/rootdir.c
> index 33c3ff1e..ff00bb0f 100644
> --- a/mkfs/rootdir.c
> +++ b/mkfs/rootdir.c
> @@ -249,7 +249,7 @@ static int add_xattr_item(struct btrfs_trans_handle *trans,
>  		cur_name_len = strlen(cur_name);
>  		next_location += cur_name_len + 1;
>  
> -		ret = getxattr(file_name, cur_name, cur_value, XATTR_SIZE_MAX);
> +		ret = lgetxattr(file_name, cur_name, cur_value, XATTR_SIZE_MAX);
>  		if (ret < 0) {
>  			if (errno == ENOTSUP)
>  				return 0;
>
David Sterba April 6, 2018, 12:59 p.m. UTC | #2
On Mon, Apr 02, 2018 at 10:59:31AM +0900, Misono Tomohiro wrote:
> mkfs-test 016 "rootdir-bad-symbolic-link" fails when selinux is enabled.
> This is because add_xattr_item() uses getxattr() and tries to follow a
> bad symbolic link for selinux item, which causes ENOENT error.
> 
> The line above already uses llistxattr() for getting list of xattr in
> order not to follow a symbolic link, so just use lgetxattr() too.
> 
> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>

Applied and added to 4.16, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/mkfs/rootdir.c b/mkfs/rootdir.c
index 33c3ff1e..ff00bb0f 100644
--- a/mkfs/rootdir.c
+++ b/mkfs/rootdir.c
@@ -249,7 +249,7 @@  static int add_xattr_item(struct btrfs_trans_handle *trans,
 		cur_name_len = strlen(cur_name);
 		next_location += cur_name_len + 1;
 
-		ret = getxattr(file_name, cur_name, cur_value, XATTR_SIZE_MAX);
+		ret = lgetxattr(file_name, cur_name, cur_value, XATTR_SIZE_MAX);
 		if (ret < 0) {
 			if (errno == ENOTSUP)
 				return 0;