Linux NFS development
 help / color / mirror / Atom feed
From: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
To: linux-nfs@vger.kernel.org
Cc: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
Subject: [PATCH 2/3] idmapd: validate NAMETOID names within their fixed-size field
Date: Mon, 31 Aug 2026 10:42:10 +0000	[thread overview]
Message-ID: <20260831104211.2297-3-prabhakar.pujeri@dell.com> (raw)
In-Reply-To: <20260831104211.2297-1-prabhakar.pujeri@dell.com>

imconv() limits len to IDMAP_NAMESZ - 1 and then reads
im_name[len + 1].  An unterminated name makes this read beyond im_name,
while a terminated name can be rejected based on the unrelated byte after
its NUL character.

Use strnlen() to require a terminator within im_name.  Mark an
unterminated request as invalid before returning it to the kernel.

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
---
 utils/idmapd/idmapd.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
index 5231f56d..c41ae1f0 100644
--- a/utils/idmapd/idmapd.c
+++ b/utils/idmapd/idmapd.c
@@ -767,8 +767,6 @@ nfsdcb(int UNUSED(fd), short which, void *data)
 static void
 imconv(struct idmap_client *ic, struct idmap_msg *im)
 {
-	u_int32_t len;
-
 	switch (im->im_conv) {
 	case IDMAP_CONV_IDTONAME:
 		idtonameres(im);
@@ -779,10 +777,11 @@ imconv(struct idmap_client *ic, struct idmap_msg *im)
 			    im->im_id, im->im_name);
 		break;
 	case IDMAP_CONV_NAMETOID:
-		len = strnlen(im->im_name, IDMAP_NAMESZ - 1);
 		/* Check for NULL termination just to be careful */
-		if (im->im_name[len+1] != '\0')
+		if (strnlen(im->im_name, IDMAP_NAMESZ) == IDMAP_NAMESZ) {
+			im->im_status |= IDMAP_STATUS_INVALIDMSG;
 			return;
+		}
 		nametoidres(im);
 		if (verbose > 1)
 			xlog_warn("%s %s: (%s) name \"%s\" -> id \"%d\"",
-- 
2.55.0


  parent reply	other threads:[~2026-08-31 10:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 10:42 [PATCH 0/3] gssd, idmapd: validate names before using them Prabhakar Pujeri
2026-08-31 10:42 ` [PATCH 1/3] gssd: fix use of uninitialized memory in error message Prabhakar Pujeri
2026-08-31 10:42 ` Prabhakar Pujeri [this message]
2026-08-31 10:42 ` [PATCH 3/3] gssd: reject server hostnames that do not fit Prabhakar Pujeri

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=20260831104211.2297-3-prabhakar.pujeri@dell.com \
    --to=prabhakar.pujeri@dell.com \
    --cc=linux-nfs@vger.kernel.org \
    /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