Commit ef62adae authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: operation: fix broken activation logic

An operation should only be added to the connection active list if the
connection is in the enabled state, or if it is in the enabled_tx state
and the operation is not incoming.

This fixes a race where an early or late incoming request could be added
to the active list while the connection is being enabled or disabled,
something which could lead to use-after-free issues or worse.

Note that the early connection-state checks in the receive path
limited the impact of this bug.

Fixes: e903a2ce7379 ("connection: add unidirectional enabled state")
Reported-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent b0e97bce
...@@ -48,8 +48,8 @@ static int gb_operation_get_active(struct gb_operation *operation) ...@@ -48,8 +48,8 @@ static int gb_operation_get_active(struct gb_operation *operation)
spin_lock_irqsave(&connection->lock, flags); spin_lock_irqsave(&connection->lock, flags);
if (connection->state != GB_CONNECTION_STATE_ENABLED && if (connection->state != GB_CONNECTION_STATE_ENABLED &&
connection->state != GB_CONNECTION_STATE_ENABLED_TX && (connection->state != GB_CONNECTION_STATE_ENABLED_TX ||
!gb_operation_is_incoming(operation)) { gb_operation_is_incoming(operation))) {
spin_unlock_irqrestore(&connection->lock, flags); spin_unlock_irqrestore(&connection->lock, flags);
return -ENOTCONN; return -ENOTCONN;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment