Skip to content

rgw: Fix segfault due to concurrent socket use at timeout - #50131

Merged
ivancich merged 1 commit into
ceph:mainfrom
yima77:rgw_fix_segfault_due_to_concurrent_socket_use_at_timeout
Feb 17, 2023
Merged

ivancich merged 1 commit into
ceph:mainfrom
yima77:rgw_fix_segfault_due_to_concurrent_socket_use_at_timeout

Conversation

@yima77

@yima77 yima77 commented Feb 15, 2023

Copy link
Copy Markdown
Contributor

This commit fixes a potential segfault risk when rgw timeout handler works on the socket in one thread while it is concurrently used by another. The details of the fix are:

  1. Instead of calling socket close(), which resets descriptor_data in boost::asio socket and risks segfault due to concurrent use of the socket, the timeout handler now calls cancel() to abort all pending ops followed by shutdown() to disable the underlying transport. The eventual closure of the socket will be done in the socket destructor.

  2. Expose the actual boost::asio socket via get_socket() from Connection so that the timeout handler can call cancel() and shutdown() on it, although the socket data member is already accessible. It allows future expansion that wants to hide the socket even though it renders the existing close() less useful.

Fixes: https://tracker.ceph.com/issues/58670
Signed-off-by: Yixin Jin [email protected]

Contribution Guidelines

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

This commit fixes a potential segfault risk when
rgw timeout handler works on the socket in one
thread while it is concurrently used by another.
The details of the fix are:

1. Instead of calling socket close(), which resets
descriptor_data in boost::asio socket and risks
segfault due to concurrent use of the socket,
the timeout handler now calls cancel() to abort
all pending ops followed by shutdown() to disable
the underlying transport. The eventual closure of
the socket will be done in the socket destructor.

2. Expose the actual boost::asio socket via get_socket()
from Connection so that the timeout handler can call
cancel() and shutdown() on it, although the socket data
member is already accessible. It allows future expansion
that wants to hide the socket even though it renders the
existing close() less useful.

Fixes: https://tracker.ceph.com/issues/58670
Signed-off-by: Yixin Jin <[email protected]>
@yima77
yima77 requested a review from a team as a code owner February 15, 2023 17:35
@github-actions github-actions Bot added the rgw label Feb 15, 2023
@cbodley

cbodley commented Feb 15, 2023

Copy link
Copy Markdown
Contributor

Expose the actual boost::asio socket via get_socket() from Connection so that the timeout handler can call cancel() and shutdown() on it, although the socket data member is already accessible. It allows future expansion that wants to hide the socket even though it renders the existing close() less useful.

maybe a timeout() member function that calls cancel/shutdown?

regardless, i'm happy to take the fix asap and follow up on this later

@ivancich ivancich added the wip-eric-testing-1 for ivancich testing label Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants