isc-dhcp-client denied by apparmor

Bug #1918410 reported by Anisse Astier
26
This bug affects 4 people
Affects Status Importance Assigned to Milestone
isc-dhcp (Ubuntu)
Status tracked in Kinetic
Focal
Fix Released
Undecided
Unassigned
Impish
Fix Released
Undecided
Unassigned
Jammy
Fix Released
Undecided
Unassigned
Kinetic
Fix Released
Medium
Lukas Märdian

Bug Description

[Impact]

 * dmesg is flooded with apparmor="DENIED" messages for dhclient
 * can lead to situations where dhclient is blocked to assign an IP address
 * also impacts NetworkManager, when dhclient is being used as DHCP client

Examples:
[ 7.339430] audit: type=1400 audit(1655804569.920:30): apparmor="DENIED" operation="open" profile="/{,usr/}sbin/dhclient" name="/proc/451/task/452/comm" pid=451 comm="dhclient" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
[ 7.402768] audit: type=1400 audit(1655804569.984:33): apparmor="DENIED" operation="mknod" profile="/{,usr/}sbin/dhclient" name="/run/NetworkManager/dhclient-enp5s0.pid" pid=451 comm="dhclient" requested_mask="c" denied_mask="c" fsuid=0 ouid=0

[Test Plan]
$ apt install network-manager
$ netplan set "network.renderer=NetworkManager"
$ netplan get
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp5s0:
      dhcp4: true
$ mkdir /etc/NetworkManager/conf.d
$ cat /etc/NetworkManager/conf.d/dhcp-client.conf
[main]
dhcp=dhclient

$ apparmor_parser -r /etc/apparmor.d/sbin.dhclient
$ netplan apply
$ dmesg | grep dhclient
$ reboot
$ netplan apply
$ dmesg | grep dhclient

=> make sure there are no (new) apparmor="DENIED" messages in there, especially not after a reboot

$ ip addr
[...]
2: enp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:16:3e:60:dd:dc brd ff:ff:ff:ff:ff:ff
    inet 10.238.94.44/24 brd 10.238.94.255 scope global dynamic noprefixroute enp5s0
       valid_lft 3576sec preferred_lft 3576sec
[...]

=> make sure a dynamic IP address got assigned via DHCP

[Where problems could occur]

 * We're touching the apparmor profile for dhclient
 * If anything goes wrong, we could potentially reduce the security confinement of dhclient
 * Or we could potentially block additional functionality of dhclient via apparmor, rendering it unusable

[Other Info]

 * Also affects salesforce case "[SFDC-LAN] Case 00332266"
 * Fixed in the upstream apparmor profile for sbin.dhclient:
   https://gitlab.com/apparmor/apparmor/-/merge_requests/730
 * The 2nd fix for "/run/NetworkManager/dhclient-enp5s0.pid" was taken from the very same profile's "connman" section and adopted for NetworkManager, as /var/run/sendsigs.omit.d/network-manager.dhclient*.pid is not used anymore.

=== original description ===

Hi, I get weird errors in the audit log, seeing dhclient is being denied reading its comm or the comm of one of its tasks:

[1383307.827378] audit: type=1400 audit(1615367094.054:162): apparmor="DENIED" operation="open" profile="/{,usr/}sbin/dhclient" name="/proc/1095210/task/1095213/comm" pid=1095210 comm="dhclient" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0

This might or might not be linked with the fact that I can't get an IPv4 on this interface. Note that it happened to other, see this comment:

https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1413232/comments/8

Or even an article recommending disabling apparmor for dhclient(!):
https://blog.anthony-jacob.com/perte-dip-v4-sous-ubuntu-20-04-apparmor-et-dhclient/

As I said, I'm not sure this is the root cause of the lack of IPv4 renewal, because running it manually *does* succeed in getting an IP. And running it in strace shows the EACCES failure:

[pid 1095210] openat(AT_FDCWD, "/proc/self/task/1095211/comm", O_RDWRstrace: Process 1095211 attached
) = -1 EACCES (Permission non accordée)

Revision history for this message
Anisse Astier (anisse) wrote :

I forgot to add that this is an up-to-date Ubuntu 20.04.2

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in isc-dhcp (Ubuntu):
status: New → Confirmed
Revision history for this message
Sean Ford (sford) wrote :

I have been doing Xenial -> Bionic -> Focal release upgrades and started running into this apparmor issue with dhclient after reaching Focal.

I don't know the root issue, and it doesn't appear to impact functionality (at least as far as I can tell on my hosts). However, I am currently dealing with this by adding the following to /etc/apparmor.d/local/sbin.dhclient:

    @{PROC}/[0-9]*/task/[0-9]*/comm rw,

Revision history for this message
John Johansen (jjohansen) wrote :

Denying
  /proc/1095210/task/1095213/comm

prevents the task from introspecting (reading), and changing (write) the command text associated with the task. In this case it would appear one thread is attempting to change the comm of another thread in the process (this is generally allowed), see man 5 proc

Reading isn't considered a problem, writing is more interesting. A process may use it to provide more info, like this is a sandbox thread, renderer etc. But a compromised task could also use it to masquerade its comm as another task. It won't hide the task but could make it harder to kill or monitor if the user is looking for the default comm value.

Denying this is not directly related to lack of IPv4 (kernel wise it has no relation), but application behavior could be such that when it fails to access the comm field it handles the error poorly resulting in it failing to setup IPv4.

I would recommend a modification to the above rule, changing [0-9]* to @{pids}

  @{PROC}/@{pids}/task/[0-9]*/comm rw,

Does adding the above rule fix the IPv4 issue for you? From comment #3 I assume no, but maybe I am reading it wrong. Are there any other denials in your logs?

As for disabling AppArmor for dhclient? It is precisely the the type of service (network facing root service) I would not recommend disabling the apparmor profile for. Instead updating the profile is the way to go.

Revision history for this message
John Johansen (jjohansen) wrote :

Okay adding the suggested rule

works for me. So it would seem dhclient is treating denied access to comm as a fatal error.

Interestingly I also had it throw a rejection for capability sys_module

[ 1645.480546] audit: type=1400 audit(1616847221.859:73): apparmor="DENIED" operation="capable" profile="/{,usr/}sbin/dhclient" pid=3380 comm="dhclient" capability=16 capname="sys_module"

which should not generally be required anymore. See https://bugs.launchpad.net/ubuntu/+source/isc-dhcp/+bug/1759032

Revision history for this message
John Johansen (jjohansen) wrote :

To further elaborate on why dhclient is accessing the comm

$ pstree -at 3395
dhclient ens3
  ├─{isc-socket}
  ├─{isc-timer}
  └─{isc-worker0000}

where 3395 is the process. It has 3 additional threads and it is providing functional names for them.

Revision history for this message
Sean Ford (sford) wrote :

Hi John,

Thank you for your detailed response and education on command text. I was able to use pstree to see the thread command text behavior change before and after the AppArmor rule addition. I feel better now that I understand what is going on!

Revision history for this message
John Johansen (jjohansen) wrote :

Merge upstream https://gitlab.com/apparmor/apparmor/-/merge_requests/730

it will be part of the next apparmor point releases

tags: added: focal
Changed in isc-dhcp (Ubuntu):
status: Confirmed → Triaged
importance: Undecided → Medium
tags: added: hirsute
Revision history for this message
Toine Ganzeboom (tganzeboom) wrote :

#4 Does not work for me.

My /etc/apparmor.d/sbin.dhclient partly looks like this:

@{PROC}/[0-9]*/net/ r,
  @{PROC}/[0-9]*/net/** r,
# @{PROC}/[0-9]*/task/[0-9]*/comm rw,
  @{PROC}/@{pids}*/task/[0-9]*/comm rw,

Maybe I'm missing something?

Revision history for this message
Daniel Richard G. (skunk) wrote :

Note to everyone watching this bug:

The file that John modified above is in the "extra profiles" section of the upstream AppArmor source repository. It may be found on an Ubuntu system at

    /usr/share/apparmor/extra-profiles/sbin.dhclient

and in jammy, it has his fix.

However, the isc-dhcp-client package provides its own separate profile, which is installed at

    /etc/apparmor.d/sbin.dhclient

and is quite different.

Most people are likely going to be using this latter one, as it is enabled by default. So they will not receive the benefit of John's fix. I've confirmed that the original "DENIED" messages still occur on jammy.

tags: added: jammy
Lukas Märdian (slyon)
description: updated
description: updated
description: updated
Lukas Märdian (slyon)
description: updated
description: updated
Lukas Märdian (slyon)
Changed in isc-dhcp (Ubuntu Kinetic):
status: Triaged → Fix Committed
assignee: nobody → Lukas Märdian (slyon)
Changed in isc-dhcp (Ubuntu Jammy):
status: New → In Progress
Changed in isc-dhcp (Ubuntu Impish):
status: New → In Progress
Changed in isc-dhcp (Ubuntu Focal):
status: New → In Progress
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package isc-dhcp - 4.4.1-2.3ubuntu4

---------------
isc-dhcp (4.4.1-2.3ubuntu4) kinetic; urgency=medium

  * d/apparmor/sbin.dhclient: fix apparmor="DENIED" errors (LP: #1918410)

 -- Lukas Märdian <email address hidden> Tue, 21 Jun 2022 12:21:09 +0200

Changed in isc-dhcp (Ubuntu Kinetic):
status: Fix Committed → Fix Released
Revision history for this message
Robie Basak (racb) wrote : Please test proposed package

Hello Anisse, or anyone else affected,

Accepted isc-dhcp into jammy-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/isc-dhcp/4.4.1-2.3ubuntu2.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-jammy to verification-done-jammy. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-jammy. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in isc-dhcp (Ubuntu Jammy):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-jammy
Changed in isc-dhcp (Ubuntu Impish):
status: In Progress → Fix Committed
tags: added: verification-needed-impish
Revision history for this message
Robie Basak (racb) wrote :

Hello Anisse, or anyone else affected,

Accepted isc-dhcp into impish-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/isc-dhcp/4.4.1-2.3ubuntu1.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-impish to verification-done-impish. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-impish. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in isc-dhcp (Ubuntu Focal):
status: In Progress → Fix Committed
tags: added: verification-needed-focal
Revision history for this message
Robie Basak (racb) wrote :

Hello Anisse, or anyone else affected,

Accepted isc-dhcp into focal-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/isc-dhcp/4.4.1-2.1ubuntu5.20.04.3 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-focal to verification-done-focal. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-focal. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Revision history for this message
Ubuntu SRU Bot (ubuntu-sru-bot) wrote : Autopkgtest regression report (isc-dhcp/4.4.1-2.3ubuntu1.1)

All autopkgtests for the newly accepted isc-dhcp (4.4.1-2.3ubuntu1.1) for impish have finished running.
The following regressions have been reported in tests triggered by the package:

network-manager/1.32.12-0ubuntu1 (ppc64el)
initramfs-tools/0.140ubuntu6.1 (amd64)
systemd/248.3-1ubuntu8.6 (amd64)

Please visit the excuses page listed below and investigate the failures, proceeding afterwards as per the StableReleaseUpdates policy regarding autopkgtest regressions [1].

https://people.canonical.com/~ubuntu-archive/proposed-migration/impish/update_excuses.html#isc-dhcp

[1] https://wiki.ubuntu.com/StableReleaseUpdates#Autopkgtest_Regressions

Thank you!

Revision history for this message
Lukas Märdian (slyon) wrote :

Autopkgtest regressions got resolved by re-triggering.

Revision history for this message
Lukas Märdian (slyon) wrote :

I've tested isc-dhcp 4.4.1-2.3ubuntu2.1 from jammy-proposed. Works as expected.

root@jj-dhcp:~# apt list isc-dhcp-client -a
Listing... Done
isc-dhcp-client/jammy-proposed,now 4.4.1-2.3ubuntu2.1 amd64 [installed]

I can see no 'dhclient' entries in dmesg after the initial "apparmor_parser -r /etc/apparmor.d/sbin.dhclient" reload (neither after 'netplan apply', nor after reboot):

$ dmesg | grep dhclient
[...]
[325421.280166] audit: type=1400 audit(1655986215.663:4563): apparmor="STATUS" operation="profile_replace" label="lxd-jj-dhcp_</var/snap/lxd/common/lxd>//&:lxd-jj-dhcp_<var-snap-lxd-common-lxd>:unconfined" name="/{,usr/}sbin/dhclient" pid=1553222 comm="apparmor_parser"

dynamic IP address is assigned via NetworkManager:
$ ip addr show eth0
[...]
174: eth0@if175: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:2f:0b:19 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.238.94.79/24 brd 10.238.94.255 scope global dynamic noprefixroute eth0
       valid_lft 3596sec preferred_lft 3596sec

$ nmcli -o
eth0: connected to netplan-eth0
        "eth0"
        ethernet (veth), 00:16:3E:2F:0B:19, sw, mtu 1500
        ip4 default
        inet4 10.238.94.79/24
[...]

tags: added: verification-done-jammy
removed: verification-needed-jammy
Revision history for this message
Lukas Märdian (slyon) wrote :

I've tested isc-dhcp 4.4.1-2.1ubuntu5.20.04.3 from focal-proposed. Works as expected.

root@ff-dhcp:~# apt list isc-dhcp-client
Listing... Done
isc-dhcp-client/focal-proposed,now 4.4.1-2.1ubuntu5.20.04.3 amd64 [installed,automatic]

I can see no 'dhclient' entries in dmesg after the initial "apparmor_parser -r /etc/apparmor.d/sbin.dhclient" reload (neither after 'netplan apply', nor after reboot):

$ dmesg | grep dhclient
[...]
[327577.704123] audit: type=1400 audit(1655988372.103:4665): apparmor="STATUS" operation="profile_replace" label="lxd-ff-dhcp_</var/snap/lxd/common/lxd>//&:lxd-ff-dhcp_<var-snap-lxd-common-lxd>:unconfined" name="/{,usr/}sbin/dhclient" pid=1595322 comm="apparmor_parser"

dynamic IP address is assigned via NetworkManager:
$ ip addr show eth0
[...]
178: eth0@if179: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:0a:83:de brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.238.94.241/24 brd 10.238.94.255 scope global dynamic noprefixroute eth0
       valid_lft 3509sec preferred_lft 3509sec

$ nmcli -o
eth0: connected to netplan-eth0
        "eth0"
        ethernet (veth), 00:16:3E:0A:83:DE, sw, mtu 1500
        ip4 default, ip6 default
        inet4 10.238.94.241/24
[...]

tags: added: verification-done-focal
removed: verification-needed-focal
Revision history for this message
Lukas Märdian (slyon) wrote :

I've tested isc-dhcp 4.4.1-2.3ubuntu1.1 from impish-proposed. Works as expected.

root@ii-dhcp:~# apt list isc-dhcp-client
Listing... Done
isc-dhcp-client/impish-proposed,now 4.4.1-2.3ubuntu1.1 amd64 [installed]

I can see no 'dhclient' entries in dmesg after the initial "apparmor_parser -r /etc/apparmor.d/sbin.dhclient" reload (neither after 'netplan apply', nor after reboot):

$ dmesg | grep dhclient
[...]
[328094.549824] audit: type=1400 audit(1655988888.955:4760): apparmor="STATUS" operation="profile_load" label="lxd-ii-dhcp_</var/snap/lxd/common/lxd>//&:lxd-ii-dhcp_<var-snap-lxd-common-lxd>:unconfined" name="/{,usr/}sbin/dhclient" pid=1609944 comm="apparmor_parser"

dynamic IP address is assigned via NetworkManager:
$ ip addr show eth0
[...]
182: eth0@if183: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:e1:06:8a brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.238.94.149/24 brd 10.238.94.255 scope global dynamic noprefixroute eth0
       valid_lft 3589sec preferred_lft 3589sec

$ nmcli -o
eth0: connected to netplan-eth0
        "eth0"
        ethernet (veth), 00:16:3E:E1:06:8A, sw, mtu 1500
        ip4 default, ip6 default
        inet4 10.238.94.149/24
[...]

tags: added: verification-done-impish
removed: verification-needed-impish
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package isc-dhcp - 4.4.1-2.3ubuntu2.1

---------------
isc-dhcp (4.4.1-2.3ubuntu2.1) jammy; urgency=medium

  * d/apparmor/sbin.dhclient: fix apparmor="DENIED" errors (LP: #1918410)

 -- Lukas Märdian <email address hidden> Tue, 21 Jun 2022 12:39:11 +0200

Changed in isc-dhcp (Ubuntu Jammy):
status: Fix Committed → Fix Released
Revision history for this message
Łukasz Zemczak (sil2100) wrote : Update Released

The verification of the Stable Release Update for isc-dhcp has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package isc-dhcp - 4.4.1-2.3ubuntu1.1

---------------
isc-dhcp (4.4.1-2.3ubuntu1.1) impish; urgency=medium

  * d/apparmor/sbin.dhclient: fix apparmor="DENIED" errors (LP: #1918410)

 -- Lukas Märdian <email address hidden> Tue, 21 Jun 2022 12:42:51 +0200

Changed in isc-dhcp (Ubuntu Impish):
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package isc-dhcp - 4.4.1-2.1ubuntu5.20.04.3

---------------
isc-dhcp (4.4.1-2.1ubuntu5.20.04.3) focal; urgency=medium

  * d/apparmor/sbin.dhclient: fix apparmor="DENIED" errors (LP: #1918410)

 -- Lukas Märdian <email address hidden> Tue, 21 Jun 2022 12:44:45 +0200

Changed in isc-dhcp (Ubuntu Focal):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers