From: Roberto Bergantinos Corpas <rbergant@redhat.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [nfs4-acl-tools PATCH 1/3] nfs4_getfacl/nfs4_setfacl: escape newline+cr from filenames
Date: Fri, 4 Sep 2026 05:39:07 -0400 [thread overview]
Message-ID: <20260904093909.2881028-2-rbergant@redhat.com> (raw)
In-Reply-To: <20260904093909.2881028-1-rbergant@redhat.com>
Filenames can be crafted to contain these special chars, as a result
they can be interpreted as ACE payload on the file that was not
explicitely set. Escape these chars from the path/filename.
Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com>
---
include/libacl_nfs4.h | 1 +
libnfs4acl/nfs4_print_acl.c | 13 +++++++++++++
nfs4_getfacl/nfs4_getfacl.c | 7 +++++--
nfs4_setfacl/nfs4_setfacl.c | 6 ++++--
4 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/include/libacl_nfs4.h b/include/libacl_nfs4.h
index a486390..76c7e5e 100644
--- a/include/libacl_nfs4.h
+++ b/include/libacl_nfs4.h
@@ -217,6 +217,7 @@ extern int nfs4_print_ace_verbose(struct nfs4_ace * ace, u32 isdir);
extern char* nfs4_get_ace_type(struct nfs4_ace*, char*, int);
extern char* nfs4_get_ace_flags(struct nfs4_ace*, char*);
extern char* nfs4_get_ace_access(struct nfs4_ace*, char*, int);
+extern void nfs4_print_escaped_path(FILE *fp, const char *path);
/** misc **/
diff --git a/libnfs4acl/nfs4_print_acl.c b/libnfs4acl/nfs4_print_acl.c
index 61f4d95..5afd682 100644
--- a/libnfs4acl/nfs4_print_acl.c
+++ b/libnfs4acl/nfs4_print_acl.c
@@ -83,3 +83,16 @@ unexp_failed:
fprintf(stderr, "An unexpected failure has occurred. \n");
return;
}
+
+void nfs4_print_escaped_path(FILE *fp, const char *path)
+{
+ const char *s;
+ for (s = path; *s; s++) {
+ if (*s == '\n')
+ fputs("\\n", fp);
+ else if (*s == '\r')
+ fputs("\\r", fp);
+ else
+ fputc(*s, fp);
+ }
+}
diff --git a/nfs4_getfacl/nfs4_getfacl.c b/nfs4_getfacl/nfs4_getfacl.c
index ddb3005..be4652c 100644
--- a/nfs4_getfacl/nfs4_getfacl.c
+++ b/nfs4_getfacl/nfs4_getfacl.c
@@ -163,8 +163,11 @@ static void print_acl_from_path(const char *fpath, enum acl_type type)
}
if (acl != NULL) {
- if (ignore_comment == 0)
- printf("# file: %s\n", fpath);
+ if (ignore_comment == 0) {
+ fputs("# file: ", stdout);
+ nfs4_print_escaped_path(stdout, fpath);
+ fputc('\n', stdout);
+ }
nfs4_print_acl(stdout, acl);
printf("\n");
nfs4_free_acl(acl);
diff --git a/nfs4_setfacl/nfs4_setfacl.c b/nfs4_setfacl/nfs4_setfacl.c
index d10e073..ab4a3d8 100644
--- a/nfs4_setfacl/nfs4_setfacl.c
+++ b/nfs4_setfacl/nfs4_setfacl.c
@@ -545,9 +545,11 @@ static struct nfs4_acl* edit_ACL(struct nfs4_acl *acl, const char *path, const s
}
if (stat->st_mode & S_IFDIR)
- fprintf(tmp_fp, "## Editing NFSv4 ACL for directory: %s\n", path);
+ fputs("## Editing NFSv4 ACL for directory: ", tmp_fp);
else
- fprintf(tmp_fp, "## Editing NFSv4 ACL for file: %s\n", path);
+ fputs("## Editing NFSv4 ACL for file: ", tmp_fp);
+ nfs4_print_escaped_path(tmp_fp, path);
+ fputc('\n', tmp_fp);
nfs4_print_acl(tmp_fp, acl);
rewind(tmp_fp);
--
2.55.0
next prev parent reply other threads:[~2026-09-04 9:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 9:39 [nfs4-acl-tools PATCH 0/3] nfs4-acl-tools hardening fixes Roberto Bergantinos Corpas
2026-09-04 9:39 ` Roberto Bergantinos Corpas [this message]
2026-09-04 9:39 ` [nfs4-acl-tools PATCH 2/3] libnfs4acl: fix various bound checkings against NFS4_MAX_PRINCIPALSIZE Roberto Bergantinos Corpas
2026-09-04 9:39 ` [nfs4-acl-tools PATCH 3/3] nfs4_setacl: do not follow symlinks on do_apply_action/nfs4_setacl_byname Roberto Bergantinos Corpas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260904093909.2881028-2-rbergant@redhat.com \
--to=rbergant@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox