Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a use-after-free in EmitterEmail::notify() #1604

Merged

Conversation

ppisar
Copy link
Contributor

@ppisar ppisar commented Aug 1, 2024

When "dnf5 automatic" was configured to send e-mails via SMTP ("emit_via = email" in automatic.conf), it sometimes crashed:

#0  0x00007ff7fb955184 __memcpy_avx_unaligned_erms (libc.so.6 + 0x147184)
#1  0x00007ff7fb873bd4 fmemopen_read (libc.so.6 + 0x65bd4)
#2  0x00007ff7fb875813 _IO_file_underflow@@GLIBC_2.2.5 (libc.so.6 + 0x67813)
#3  0x00007ff7fb877e45 _IO_default_xsgetn (libc.so.6 + 0x69e45)
#4  0x00007ff7fb869a40 _IO_fread (libc.so.6 + 0x5ba40)
#5  0x00007ff7faceb1f7 cr_in_read (libcurl.so.4 + 0x541f7)
#6  0x00007ff7facf8608 cr_eob_read (libcurl.so.4 + 0x61608)
#7  0x00007ff7facf0f20 Curl_client_read (libcurl.so.4 + 0x59f20)
#8  0x00007ff7facf103d Curl_req_send_more (libcurl.so.4 + 0x5a03d)
#9  0x00007ff7fad068da Curl_readwrite (libcurl.so.4 + 0x6f8da)
#10 0x00007ff7face6258 multi_runsingle.lto_priv.0 (libcurl.so.4 + 0x4f258)
#11 0x00007ff7face8c64 curl_multi_perform (libcurl.so.4 + 0x51c64)
#12 0x00007ff7facbb8a3 curl_easy_perform (libcurl.so.4 + 0x248a3)
#13 0x00007ff7f9ee30ad _ZN4dnf512EmitterEmail6notifyEv (automatic_cmd_plugin.so + 0x170ad)
#14 0x00007ff7f9ed61f5 _ZN4dnf516AutomaticCommand3runEv (automatic_cmd_plugin.so + 0xa1f5)
#15 0x0000557b633d5f78 main (dnf5 + 0x39f78)
#16 0x00007ff7fb811248 __libc_start_call_main (libc.so.6 + 0x3248)
#17 0x00007ff7fb81130b __libc_start_main@@GLIBC_2.34 (libc.so.6 + 0x330b)
#18 0x0000557b633d88e5 _start (dnf5 + 0x3c8e5)

or sent an e-mail without a body and some headers (e.g. Subject):

From root@fedora-41.localdomain  Thu Aug  1 14:49:36 2024
Return-Path: <root@fedora-41.localdomain>
X-Original-To: test
Delivered-To: test@fedora-41.localdomain
Received: from fedora-41 (localhost [IPv6:::1])
    by fedora-41.localdomain (Postfix) with ESMTP id E5A1E51
    for <test>; Thu, 01 Aug 2024 14:49:36 +0200 (CEST)
Message-Id: <20240801124936.E5A1E51@fedora-41.localdomain>
Date: Thu, 01 Aug 2024 14:49:36 +0200 (CEST)
From: root@fedora-41.localdomain

The cause was that a FILE * structure registered to curl as CURLOPT_READDATA and freed before curl_easy_perform() processed it.

This patch fixes it.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2298385

When "dnf5 automatic" was configured to send e-mails via SMTP
("emit_via = email" in automatic.conf), it sometimes crashed:

    #0  0x00007ff7fb955184 __memcpy_avx_unaligned_erms (libc.so.6 + 0x147184)
    rpm-software-management#1  0x00007ff7fb873bd4 fmemopen_read (libc.so.6 + 0x65bd4)
    rpm-software-management#2  0x00007ff7fb875813 _IO_file_underflow@@GLIBC_2.2.5 (libc.so.6 + 0x67813)
    rpm-software-management#3  0x00007ff7fb877e45 _IO_default_xsgetn (libc.so.6 + 0x69e45)
    rpm-software-management#4  0x00007ff7fb869a40 _IO_fread (libc.so.6 + 0x5ba40)
    rpm-software-management#5  0x00007ff7faceb1f7 cr_in_read (libcurl.so.4 + 0x541f7)
    rpm-software-management#6  0x00007ff7facf8608 cr_eob_read (libcurl.so.4 + 0x61608)
    rpm-software-management#7  0x00007ff7facf0f20 Curl_client_read (libcurl.so.4 + 0x59f20)
    rpm-software-management#8  0x00007ff7facf103d Curl_req_send_more (libcurl.so.4 + 0x5a03d)
    rpm-software-management#9  0x00007ff7fad068da Curl_readwrite (libcurl.so.4 + 0x6f8da)
    rpm-software-management#10 0x00007ff7face6258 multi_runsingle.lto_priv.0 (libcurl.so.4 + 0x4f258)
    rpm-software-management#11 0x00007ff7face8c64 curl_multi_perform (libcurl.so.4 + 0x51c64)
    rpm-software-management#12 0x00007ff7facbb8a3 curl_easy_perform (libcurl.so.4 + 0x248a3)
    rpm-software-management#13 0x00007ff7f9ee30ad _ZN4dnf512EmitterEmail6notifyEv (automatic_cmd_plugin.so + 0x170ad)
    rpm-software-management#14 0x00007ff7f9ed61f5 _ZN4dnf516AutomaticCommand3runEv (automatic_cmd_plugin.so + 0xa1f5)
    rpm-software-management#15 0x0000557b633d5f78 main (dnf5 + 0x39f78)
    rpm-software-management#16 0x00007ff7fb811248 __libc_start_call_main (libc.so.6 + 0x3248)
    rpm-software-management#17 0x00007ff7fb81130b __libc_start_main@@GLIBC_2.34 (libc.so.6 + 0x330b)
    rpm-software-management#18 0x0000557b633d88e5 _start (dnf5 + 0x3c8e5)

or sent an e-mail without a body and some headers (e.g. Subject):

    From root@fedora-41.localdomain  Thu Aug  1 14:49:36 2024
    Return-Path: <root@fedora-41.localdomain>
    X-Original-To: test
    Delivered-To: test@fedora-41.localdomain
    Received: from fedora-41 (localhost [IPv6:::1])
	    by fedora-41.localdomain (Postfix) with ESMTP id E5A1E51
	    for <test>; Thu, 01 Aug 2024 14:49:36 +0200 (CEST)
    Message-Id: <20240801124936.E5A1E51@fedora-41.localdomain>
    Date: Thu, 01 Aug 2024 14:49:36 +0200 (CEST)
    From: root@fedora-41.localdomain

The cause was that a FILE * structure registered to curl as CURLOPT_READDATA
and freed before curl_easy_perform() processed it.

This patch fixes it.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2298385
Copy link
Member

@m-blaha m-blaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ppisar ppisar added this pull request to the merge queue Aug 2, 2024
Merged via the queue into rpm-software-management:main with commit 97ed37c Aug 2, 2024
16 checks passed
@ppisar ppisar deleted the automatic_no_email_body branch August 2, 2024 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants