From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Samuel Thibault <samuel.thibault@gnu.org>, P J P <ppandit@redhat.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,
thuth@redhat.com, wjjzhang <wjjzhang@tencent.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] A use-after-free in slirp
Date: Thu, 24 Aug 2017 23:51:32 -0300 [thread overview]
Message-ID: <c56b92bd-f93b-1dfc-47d6-e43eee3922fb@amsat.org> (raw)
In-Reply-To: <20170824234241.5cfnuic3lmcea6xc@var.youpi.perso.aquilenet.fr>
Hi Samuel,
On 08/24/2017 08:42 PM, Samuel Thibault wrote:
> Hello,
>
> Thanks for the reproducer you sent me offline. Here is a fix which makes
> a lot of sense and fixes the reproducer. Could you try it with your
> whole testcase?
>
> Could somebody also review the patch?
>
Your patch looks correct.
It seems worth to add a soqfree() function for readability:
static inline void soqfree(struct quehead *ifq)
{
struct mbuf *ifm;
for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) {
ifm->ifq_so = NULL;
}
ifq->ifq_so = NULL;
}
then use:
if (ifq->ifq_so == so) {
soqfree(ifq);
}
same with slirp->if_batchq
Also can you send your patch in the proper format?
Thanks!
Regards,
Phil.
> Samuel
>
> commit 1a3a763509fad895c907e6978ea034a5c19ee370
> Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
> Date: Fri Aug 25 01:35:53 2017 +0200
>
> slirp: fix clearing ifq_so from pending packets
>
> The if_fastq and if_batchq contain not only packets, but queues of packets
> for the same socket. When sofree frees a socket, it thus has to clear ifq_so
> from all the packets from the queues, not only the first.
>
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
> diff --git a/slirp/socket.c b/slirp/socket.c
> index ecec0295a9..4203b80542 100644
> --- a/slirp/socket.c
> +++ b/slirp/socket.c
> @@ -66,21 +66,29 @@ void
> sofree(struct socket *so)
> {
> Slirp *slirp = so->slirp;
> - struct mbuf *ifm;
> -
> - for (ifm = (struct mbuf *) slirp->if_fastq.qh_link;
> - (struct quehead *) ifm != &slirp->if_fastq;
> - ifm = ifm->ifq_next) {
> - if (ifm->ifq_so == so) {
> - ifm->ifq_so = NULL;
> + struct mbuf *ifq;
> +
> + for (ifq = (struct mbuf *) slirp->if_fastq.qh_link;
> + (struct quehead *) ifq != &slirp->if_fastq;
> + ifq = ifq->ifq_next) {
> + if (ifq->ifq_so == so) {
> + struct mbuf *ifm;
> + ifq->ifq_so = NULL;
> + for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) {
> + ifm->ifq_so = NULL;
> + }
> }
> }
>
> - for (ifm = (struct mbuf *) slirp->if_batchq.qh_link;
> - (struct quehead *) ifm != &slirp->if_batchq;
> - ifm = ifm->ifq_next) {
> - if (ifm->ifq_so == so) {
> - ifm->ifq_so = NULL;
> + for (ifq = (struct mbuf *) slirp->if_batchq.qh_link;
> + (struct quehead *) ifq != &slirp->if_batchq;
> + ifq = ifq->ifq_next) {
> + if (ifq->ifq_so == so) {
> + struct mbuf *ifm;
> + ifq->ifq_so = NULL;
> + for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) {
> + ifm->ifq_so = NULL;
> + }
> }
> }
>
>
prev parent reply other threads:[~2017-08-25 2:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-03 12:15 [Qemu-devel] A use-after-free in slirp P J P
2017-08-23 20:27 ` Samuel Thibault
2017-08-24 11:18 ` P J P
2017-08-24 23:42 ` Samuel Thibault
2017-08-25 2:51 ` Philippe Mathieu-Daudé [this message]
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=c56b92bd-f93b-1dfc-47d6-e43eee3922fb@amsat.org \
--to=f4bug@amsat.org \
--cc=jan.kiszka@siemens.com \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=samuel.thibault@gnu.org \
--cc=thuth@redhat.com \
--cc=wjjzhang@tencent.com \
/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: link
Be 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 NNTP newsgroup(s).