Skip to contentSkip to conversation

fwctl: pds: Validate RPC input size before parsing

PATCH Applied Heechan Kang 4 participants 4 messages May 17 – May 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fwctl: pds: Validate RPC input size before parsing

The fwctl core allocates the device-specific RPC input buffer with fwctl_rpc.in_len and passes that buffer to the driver callback.

pdsfc_fw_rpc() casts the buffer to struct fwctl_rpc_pds and then calls pdsfc_validate_rpc(), which reads fields from that structure before checking that the input buffer is large enough to contain it. A short in_len can make pds_fwctl read beyond the allocation.

Reject pds RPC buffers that are smaller than struct fwctl_rpc_pds before parsing any pds-specific fields.

Fixes 92c66ee829b9 ("pds_fwctl: add rpc and query support")
Cc [email protected] # v6.15+
---
 drivers/fwctl/pds/main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/fwctl/pds/main.c +3 -0
index 08872ee8422f..68fe254dd10a 100644
@@ -362,6 +362,9 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
 	void *out = NULL;
 	int err;
 
+	if (in_len < sizeof(*rpc))
+		return ERR_PTR(-EINVAL);
+
 	err = pdsfc_validate_rpc(pdsfc, rpc, scope);
 	if (err)
 		return ERR_PTR(err);
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Heechan Kang

The fwctl core allocates the device-specific RPC input buffer with fwctl_rpc.in_len and passes that buffer to the driver callback.

pdsfc_fw_rpc() casts the buffer to struct fwctl_rpc_pds and then calls pdsfc_validate_rpc(), which reads fields from that structure before checking that the input buffer is large enough to contain it. A short in_len can make pds_fwctl read beyond the allocation.

Quoted 6 lines

Reject pds RPC buffers that are smaller than struct fwctl_rpc_pds before parsing any pds-specific fields.

Fixes 92c66ee829b9 ("pds_fwctl: add rpc and query support")
Cc [email protected] # v6.15+
Quoted 18 lines
---
 drivers/fwctl/pds/main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/fwctl/pds/main.c +3 -0
index 08872ee8422f..68fe254dd10a 100644
@@ -362,6 +362,9 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
 	void *out = NULL;
 	int err;
 
+	if (in_len < sizeof(*rpc))
+		return ERR_PTR(-EINVAL);
+
 	err = pdsfc_validate_rpc(pdsfc, rpc, scope);
 	if (err)
 		return ERR_PTR(err);
#2 lore raw
In reply to Heechan Kang
Quoted 28 lines · Heechan Kang

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

The fwctl core allocates the device-specific RPC input buffer with fwctl_rpc.in_len and passes that buffer to the driver callback.

pdsfc_fw_rpc() casts the buffer to struct fwctl_rpc_pds and then calls pdsfc_validate_rpc(), which reads fields from that structure before checking that the input buffer is large enough to contain it. A short in_len can make pds_fwctl read beyond the allocation.

Reject pds RPC buffers that are smaller than struct fwctl_rpc_pds before parsing any pds-specific fields.

Fixes 92c66ee829b9 ("pds_fwctl: add rpc and query support")
Cc [email protected] # v6.15+
---
  drivers/fwctl/pds/main.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/fwctl/pds/main.c +0 -0
index 08872ee8422f..68fe254dd10a 100644

drivers/fwctl/pds/main.c static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope, · line 367

Quoted 6 lines
drivers/fwctl/pds/main.c +3 -0
@@ -362,6 +362,9 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
         void *out = NULL;
         int err;
 
+       if (in_len < sizeof(*rpc))
+               return ERR_PTR(-EINVAL);
+

LGTM. Thanks for the fix.

Brett

Quoted 6 lines
drivers/fwctl/pds/main.c +0 -1
         err = pdsfc_validate_rpc(pdsfc, rpc, scope);
         if (err)
                 return ERR_PTR(err);
--

2.34.1

#3 lore raw
In reply to Heechan Kang
Quoted 11 lines · Heechan Kang

The fwctl core allocates the device-specific RPC input buffer with fwctl_rpc.in_len and passes that buffer to the driver callback.

pdsfc_fw_rpc() casts the buffer to struct fwctl_rpc_pds and then calls pdsfc_validate_rpc(), which reads fields from that structure before checking that the input buffer is large enough to contain it. A short in_len can make pds_fwctl read beyond the allocation.

Reject pds RPC buffers that are smaller than struct fwctl_rpc_pds before parsing any pds-specific fields.

Quoted 6 lines
Fixes 92c66ee829b9 ("pds_fwctl: add rpc and query support")
Cc [email protected] # v6.15+
---
 drivers/fwctl/pds/main.c | 3 +++
 1 file changed, 3 insertions(+)

Applied to for-rc, thanks

Jason