mirror of
https://github.com/linux-can/can-utils.git
synced 2026-11-04 15:31:10 +01:00
isobusfs: srv: check handle state and owner for read and seek requests
Read File and Seek File requests only checked the handle index to be within the handles array. Unused or closed handle slots are zeroed (fd = 0, dir = NULL), so a read request on such a handle read from the server's stdin and sent the content to the client. Additionally every client was able to read and seek handles opened by other clients. Add isobusfs_srv_get_client_handle() which only returns handles that are in use and have been opened by the requesting client. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
@@ -108,6 +108,28 @@ isobusfs_srv_get_handle(struct isobusfs_srv_priv *priv, int handle)
|
|||||||
return &priv->handles[handle];
|
return &priv->handles[handle];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the handle only when it is in use and has been opened by the
|
||||||
|
* requesting client. Otherwise return NULL.
|
||||||
|
*/
|
||||||
|
static struct isobusfs_srv_handles *
|
||||||
|
isobusfs_srv_get_client_handle(struct isobusfs_srv_priv *priv,
|
||||||
|
struct isobusfs_srv_client *client, int handle)
|
||||||
|
{
|
||||||
|
struct isobusfs_srv_handles *hdl = isobusfs_srv_get_handle(priv, handle);
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (!hdl || !hdl->path)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(hdl->clients); i++) {
|
||||||
|
if (hdl->clients[i] == client)
|
||||||
|
return hdl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int isobusfs_srv_release_handle(struct isobusfs_srv_priv *priv,
|
static int isobusfs_srv_release_handle(struct isobusfs_srv_priv *priv,
|
||||||
struct isobusfs_srv_client *client,
|
struct isobusfs_srv_client *client,
|
||||||
int handle)
|
int handle)
|
||||||
@@ -743,7 +765,7 @@ static int isobusfs_srv_fa_rf_req(struct isobusfs_srv_priv *priv,
|
|||||||
goto send_response;
|
goto send_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle = isobusfs_srv_get_handle(priv, req->handle);
|
handle = isobusfs_srv_get_client_handle(priv, client, req->handle);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
pr_warn("failed to find file with handle: %x", req->handle);
|
pr_warn("failed to find file with handle: %x", req->handle);
|
||||||
error_code = ISOBUSFS_ERR_FILE_ORPATH_NOT_FOUND;
|
error_code = ISOBUSFS_ERR_FILE_ORPATH_NOT_FOUND;
|
||||||
@@ -959,7 +981,7 @@ static int isobusfs_srv_fa_sf_req(struct isobusfs_srv_priv *priv,
|
|||||||
goto send_response;
|
goto send_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle = isobusfs_srv_get_handle(priv, req->handle);
|
handle = isobusfs_srv_get_client_handle(priv, client, req->handle);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
pr_warn("failed to find handle: %x", req->handle);
|
pr_warn("failed to find handle: %x", req->handle);
|
||||||
error_code = ISOBUSFS_ERR_INVALID_HANDLE;
|
error_code = ISOBUSFS_ERR_INVALID_HANDLE;
|
||||||
|
|||||||
Reference in New Issue
Block a user