Bug 1211196 (CVE-2023-32182) - VUL-0: CVE-2023-32182: postfix: config_postfix SUSE specific script potentially bad /tmp file usage
Summary: VUL-0: CVE-2023-32182: postfix: config_postfix SUSE specific script potential...
Status: RESOLVED FIXED
Alias: CVE-2023-32182
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Security (show other bugs)
Version: Current
Hardware: Other Other
: P3 - Medium : Normal (vote)
Target Milestone: ---
Assignee: Peter Varkoly
QA Contact: E-mail List
URL: https://smash.suse.de/issue/365316/
Whiteboard: CVSSv3.1:SUSE:CVE-2023-32182:5.5:(AV:...
Keywords:
Depends on:
Blocks:
 
Reported: 2023-05-08 11:36 UTC by Matthias Gerstner
Modified: 2024-07-01 10:01 UTC (History)
5 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Gerstner 2023-05-08 11:36:55 UTC
Noticed via systemd service monitoring. From
/usr/lib/systemd/system/postfix.service, among others:

> ExecStartPre=/usr/lib/postfix/systemd/config_postfix

This runs /usr/sbin/config.postfix, a ~1.500 lines bash script.

In some locations safe temporary file / directions created via mktemp are
used. The function `update_cf()` sticks out though:

```
update_cf() {
    while test "x$1" != "x" ; do
        B=$( find /etc/postfix/${1} -printf %CY%Cm%Cd%CI%CM )
        cp /etc/postfix/${1} "/var/adm/backup/postfix/${1}$B"
        cp /etc/postfix/${1} "/var/adm/backup/postfix/${1}"
        eval gen_${1/\./_} > /tmp/${1}.config
        mv -Z /tmp/${1}.config /etc/postfix/${1};
        shift
    done
}
```

This is e.g. invoked here:

```
if test "$MAIL_CREATE_CONFIG" = "yes"; then
        test -z "$r" && update_cf master.cf main.cf
fi
```

But also via `restore_cf()` for main.cf and master.cf.

It looks like another local user can pre-create these files in e.g.
/tmp/master.cf, wait for the script to overwrite it and then just in time
replace the content again with something malicious so that the `mv -Z`
actually moves a compromised script into place.

This requires a closer investigation still though.
Comment 1 Matthias Gerstner 2023-05-22 11:20:11 UTC
I will look into this more closely.
Comment 2 Matthias Gerstner 2023-05-22 12:30:26 UTC
The problematic code seems exploitable:

- symlink attack if protected_symlinks is off
- otherwise allows to control the content of the postfix configuration

The code only runs the first time, though, or if
var/adm/postfix.configured is not existing.

I will involved our package maintainers soon.
Comment 3 Matthias Gerstner 2023-05-22 12:52:55 UTC
Assigning to you, Peter. Please see comment 0 and comment 2. There is a fixed
/tmp file usage in `config.postfix` that can cause security issues.

Please check whether you can confirm it and prepare updates. We need updates
for SLE first, don't publish the issue outside the company (or in OBS) until
we have updates for SLE ready.

We will likely also assign one of our SUSE CNA CVEs, since this is a SUSE
specific script.
Comment 5 Johannes Segitz 2023-05-22 13:03:13 UTC
I agree with Matthias' assessment. Please use CVE-2023-32182
Comment 6 Johannes Segitz 2023-07-05 12:22:00 UTC
ping. Can you please have a look at this? Thanks
Comment 7 Peter Varkoly 2023-07-06 11:45:23 UTC
What about this solution?
update_cf() {
    while test "x$1" != "x" ; do
        TMPFILE=$(mktemp /tmp/postfix.${1}.XXXXXX) || exit 1
        B=$( find /etc/postfix/${1} -printf %CY%Cm%Cd%CI%CM )
        cp /etc/postfix/${1} "@conf_backup_dir@/${1}$B"
        cp /etc/postfix/${1} "@conf_backup_dir@/${1}"
        eval gen_${1/\./_} > $TMPFILE
        mv -Z $TMPFILE /etc/postfix/${1};
        shift
    done
}
Comment 8 Matthias Gerstner 2023-07-11 10:35:09 UTC
(In reply to Peter Varkoly from comment #7)
> What about this solution?
> update_cf() {
>     while test "x$1" != "x" ; do
>         TMPFILE=$(mktemp /tmp/postfix.${1}.XXXXXX) || exit 1
>         B=$( find /etc/postfix/${1} -printf %CY%Cm%Cd%CI%CM )
>         cp /etc/postfix/${1} "@conf_backup_dir@/${1}$B"
>         cp /etc/postfix/${1} "@conf_backup_dir@/${1}"
>         eval gen_${1/\./_} > $TMPFILE
>         mv -Z $TMPFILE /etc/postfix/${1};
>         shift
>     done
> }

Yes, this should do, thank you.
Comment 13 Maintenance Automation 2023-08-23 20:30:39 UTC
SUSE-SU-2023:3394-1: An update that solves one vulnerability and has one fix can now be installed.

Category: security (important)
Bug References: 1211196, 1213515
CVE References: CVE-2023-32182
Sources used:
openSUSE Leap 15.5 (src): postfix-bdb-3.7.3-150500.3.5.1, postfix-3.7.3-150500.3.5.1
Basesystem Module 15-SP5 (src): postfix-3.7.3-150500.3.5.1
Legacy Module 15-SP5 (src): postfix-bdb-3.7.3-150500.3.5.1
Server Applications Module 15-SP5 (src): postfix-3.7.3-150500.3.5.1

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 15 Marcus Meissner 2023-09-12 13:37:15 UTC
make bug public as we released updates.
Comment 17 Marcus Meissner 2023-09-18 13:53:15 UTC
Petr, can you resubmit for 15-SP3 at least where it was declined due to a build failure?
Comment 18 Peter Varkoly 2023-09-18 14:03:33 UTC
(In reply to Marcus Meissner from comment #17)
> Petr, 
Peter
> can you resubmit for 15-SP3 at least where it was declined due to a build failure?
I'm just working on the build failure.
Comment 20 Maintenance Automation 2023-09-22 12:30:02 UTC
SUSE-SU-2023:3732-1: An update that solves one vulnerability and has one security fix can now be installed.

Category: security (moderate)
Bug References: 1211196, 1215372
CVE References: CVE-2023-32182
Sources used:
SUSE Linux Enterprise Software Development Kit 12 SP5 (src): postfix-3.2.10-3.27.2
SUSE Linux Enterprise High Performance Computing 12 SP5 (src): postfix-3.2.10-3.27.2
SUSE Linux Enterprise Server 12 SP5 (src): postfix-3.2.10-3.27.2
SUSE Linux Enterprise Server for SAP Applications 12 SP5 (src): postfix-3.2.10-3.27.2

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 21 Maintenance Automation 2023-09-26 16:30:04 UTC
SUSE-SU-2023:3791-1: An update that solves one vulnerability and has one security fix can now be installed.

Category: security (moderate)
Bug References: 1211196, 1215372
CVE References: CVE-2023-32182
Sources used:
openSUSE Leap 15.4 (src): postfix-3.4.7-150200.3.12.2

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 22 Maintenance Automation 2023-10-03 20:30:40 UTC
SUSE-SU-2023:3945-1: An update that solves one vulnerability and has one security fix can now be installed.

Category: security (moderate)
Bug References: 1211196, 1215372
CVE References: CVE-2023-32182
Sources used:
openSUSE Leap 15.4 (src): postfix-3.5.9-150300.5.12.2, postfix-bdb-3.5.9-150300.5.12.2
Basesystem Module 15-SP4 (src): postfix-3.5.9-150300.5.12.2
Legacy Module 15-SP4 (src): postfix-bdb-3.5.9-150300.5.12.2
Server Applications Module 15-SP4 (src): postfix-3.5.9-150300.5.12.2
SUSE Manager Proxy 4.2 (src): postfix-3.5.9-150300.5.12.2
SUSE Manager Retail Branch Server 4.2 (src): postfix-3.5.9-150300.5.12.2
SUSE Manager Server 4.2 (src): postfix-3.5.9-150300.5.12.2

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 23 Peter Varkoly 2024-06-11 10:52:10 UTC
FIXED
Comment 24 Peter Varkoly 2024-06-11 10:52:11 UTC
FIXED