Skip to contentSkip to conversation

liveupdate: fix GET_NAME ioctl argument validation

PATCH Superseded Jackie Liu 2 participants 4 messages Jul 15

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jackie Liu

author
#0 lore raw

PATCH 1/2 liveupdate: fix GET_NAME ioctl argument validation

From: Jackie Liu <[email protected]>

LIVEUPDATE_SESSION_GET_NAME was developed in the liveupdate/next branch while the session type validation change was carried in liveupdate-fixes. When the conflict between the two branches was resolved, the GET_NAME operation descriptor picked up the structure and last member from RETRIEVE_FD.

This makes both its known size and minimum size 16 bytes rather than 72. Consequently, copy_struct_from_user() treats most of a normal GET_NAME argument as unknown trailing data and rejects it with -E2BIG when any of those bytes are nonzero. It also accepts a 16-byte argument and returns success after copying only a truncated session name.

Use the GET_NAME structure and its name field in the descriptor.

---
 kernel/liveupdate/luo_session.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/liveupdate/luo_session.c +1 -1
index b79b2a488974..f38b5b18f3f8 100644
@@ -378,7 +378,7 @@ static const struct luo_ioctl_op luo_session_ioctl_ops[] = {
 	IOCTL_OP(LIVEUPDATE_SESSION_RETRIEVE_FD, luo_session_retrieve_fd,
 		 struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),
 	IOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,
-		 struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_ALL),
+		 struct liveupdate_session_get_name, name, LUO_IOCTL_ALL),
 };
 
 static bool luo_ioctl_type_valid(struct luo_session *session,
Signature · 1 line
2.54.0
author
#1 lore raw

PATCH 2/2 liveupdate: reject nonzero reserved value for SESSION_FINISH

From: Jackie Liu <[email protected]>

The UAPI documents liveupdate_session_finish::reserved as requiring zero, but luo_session_finish() currently ignores it and finishes the session. Accepting nonzero values prevents the field from being safely repurposed by a future extension.

Reject nonzero reserved values before changing session state, matching LIVEUPDATE_SESSION_GET_NAME.

Fixes 16cec0d26521 ("liveupdate: luo_session: add ioctls for file preservation")
Assisted-by Codex:gpt-5.6-sol
---
 kernel/liveupdate/luo_session.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/liveupdate/luo_session.c +6 -1
index f38b5b18f3f8..15342c0783b5 100644
@@ -316,7 +316,12 @@ static int luo_session_finish(struct luo_session *session,
 			      struct luo_ucmd *ucmd)
 {
 	struct liveupdate_session_finish *argp = ucmd->cmd;
-	int err = luo_session_finish_one(session);
+	int err;
+
+	if (argp->reserved)
+		return -EINVAL;
+
+	err = luo_session_finish_one(session);
 
 	if (err)
 		return err;
Signature · 1 line
2.54.0
maintainer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] liveupdate: reject nonzero reserved value for SESSION_FINISH

Quoted 7 lines · Jackie Liu

From: Jackie Liu <[email protected]>

The UAPI documents liveupdate_session_finish::reserved as requiring zero, but luo_session_finish() currently ignores it and finishes the session. Accepting nonzero values prevents the field from being safely repurposed by a future extension.

Quoted 6 lines

Reject nonzero reserved values before changing session state, matching LIVEUPDATE_SESSION_GET_NAME.

Fixes 16cec0d26521 ("liveupdate: luo_session: add ioctls for file preservation")
Assisted-by Codex:gpt-5.6-sol

[...]

Signature · 2 lines
Regards,
Pratyush Yadav
maintainer Reviewed-by on v1 1/2
#3 lore raw
In reply to Jackie Liu

Hi,

Quoted 1 line

Please run ./scripts/get_maintainer.pl *.patch to get the full list of people to Cc on the patch. You missed me and linux-kernel@.

Quoted 8 lines · Jackie Liu

From: Jackie Liu <[email protected]>

LIVEUPDATE_SESSION_GET_NAME was developed in the liveupdate/next branch while the session type validation change was carried in liveupdate-fixes. When the conflict between the two branches was resolved, the GET_NAME operation descriptor picked up the structure and last member from RETRIEVE_FD.

Quoted 5 lines

This makes both its known size and minimum size 16 bytes rather than 72. Consequently, copy_struct_from_user() treats most of a normal GET_NAME argument as unknown trailing data and rejects it with -E2BIG when any of those bytes are nonzero. It also accepts a 16-byte argument and returns success after copying only a truncated session name.

Nit: The second line doesn't seem to be true. The get_session_name selftest tries to create a session with 21 byte name and it passes. I think it works because luo_session_get_name assumes ucmd->cmd is struct liveupdate_session_get_name and so it tries to copy the whole thing via luo_ucmd_respond(), and if the user buffer it large enough, it will work.

But yeah, the -E2BIG seems like a real problem.

And anyway, that's a tricky bug and I missed it completely when I reviewed the final rebased version. So thanks for fixing it.

Quoted 23 lines

Use the GET_NAME structure and its name field in the descriptor.

---
 kernel/liveupdate/luo_session.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/liveupdate/luo_session.c +1 -1
index b79b2a488974..f38b5b18f3f8 100644
@@ -378,7 +378,7 @@ static const struct luo_ioctl_op luo_session_ioctl_ops[] = {
 	IOCTL_OP(LIVEUPDATE_SESSION_RETRIEVE_FD, luo_session_retrieve_fd,
 		 struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),
 	IOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,
-		 struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_ALL),
+		 struct liveupdate_session_get_name, name, LUO_IOCTL_ALL),
 };
 
 static bool luo_ioctl_type_valid(struct luo_session *session,
Signature · 2 lines
Regards,
Pratyush Yadav