public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Samuel Thibault <sthibaul@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] _hurd_intr_rpc_mach_msg: handle message iteration correctly. Date: Sat, 18 Nov 2023 23:37:34 +0000 (GMT) [thread overview] Message-ID: <20231118233734.7B24F3858D20@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f11a92993c45a91c3237733486ce2b8735af2ba0 commit f11a92993c45a91c3237733486ce2b8735af2ba0 Author: Flavio Cruz <flaviocruz@gmail.com> Date: Sat Nov 18 18:18:44 2023 -0500 _hurd_intr_rpc_mach_msg: handle message iteration correctly. The `ty` pointer is only set at the end of the loop so that `msgtl_header.msgt_inline` and `msgtl_header.msgt_deallocate` remain valid. Also, when deallocating memory, we use the length from the message directly rather than hard coding mach_port_t since we want to deallocate any kind of OOL data. Message-ID: <ZVlGVD6eEN-dXsOr@jupiter.tail36e24.ts.net> Diff: --- hurd/intr-msg.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/hurd/intr-msg.c b/hurd/intr-msg.c index 98f588f206..737bfe0ffb 100644 --- a/hurd/intr-msg.c +++ b/hurd/intr-msg.c @@ -186,12 +186,14 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg, mach_msg_type_size_t size; mach_msg_type_number_t number; - inline void clean_ports (mach_port_t *ports, int dealloc) + inline void clean_ports_and_memory (char *data, const vm_size_t length, + int dealloc) { mach_msg_type_number_t i; switch (name) { case MACH_MSG_TYPE_MOVE_SEND: + mach_port_t *ports = (mach_port_t *) data; for (i = 0; i < number; i++) __mach_port_deallocate (__mach_task_self (), *ports++); if (ty->msgtl_header.msgt_longform) @@ -207,40 +209,38 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg, assert (! "unexpected port type in interruptible RPC"); } if (dealloc) - __vm_deallocate (__mach_task_self (), - (vm_address_t) ports, - number * sizeof (mach_port_t)); + __vm_deallocate (__mach_task_self (), (vm_address_t) data, length); } + char *data; if (ty->msgtl_header.msgt_longform) { name = ty->msgtl_name; size = ty->msgtl_size; number = ty->msgtl_number; - ty = (void *) ty + sizeof (mach_msg_type_long_t); + data = (char *) ty + sizeof (mach_msg_type_long_t); } else { name = ty->msgtl_header.msgt_name; size = ty->msgtl_header.msgt_size; number = ty->msgtl_header.msgt_number; - ty = (void *) ty + sizeof (mach_msg_type_t); + data = (char *) ty + sizeof (mach_msg_type_t); } + const vm_size_t length = ((number * size) + 7) >> 3; if (ty->msgtl_header.msgt_inline) { /* Calculate length of data in bytes. */ - const vm_size_t length = ((number * size) + 7) >> 3; - clean_ports ((void *) ty, 0); + clean_ports_and_memory (data, length, 0); /* Move to the next argument. */ - ty = (void *) PTR_ALIGN_UP ((char *) ty + length, - __alignof__ (uintptr_t)); + ty = (void *) PTR_ALIGN_UP (data + length, __alignof__ (uintptr_t)); } else { - clean_ports (*(void **) ty, + clean_ports_and_memory (*(void **) data, length, ty->msgtl_header.msgt_deallocate); - ty = (void *) ty + sizeof (void *); + ty = (void *) data + sizeof (void *); } } #else /* Untyped Mach IPC flavor. */
reply other threads:[~2023-11-18 23:37 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231118233734.7B24F3858D20@sourceware.org \ --to=sthibaul@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).