net_admin apparmor denial when using Go
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| | Snappy |
High
|
Tyler Hicks | ||
| | linux (Ubuntu) |
Undecided
|
Unassigned | ||
| | Xenial |
Undecided
|
Unassigned | ||
Bug Description
SRU Justification:
Impact: A noisy AppArmor denial is reported to the system logs when a go program is run as a privileged user. The denial is non-fatal and is simply the result of the proc net systctl code determining what permissions a new inode should have. This noisy denial has a high potential to confuse snap packagers because they may think that their application is not working under Snappy confinement. It has a high potential to confuse Snappy users because they may think that the snaps running on their system are malicious.
Fix: The fix was authored by Tyler Hicks and acked by Serge Hallyn. It creates a new ns_capable() function that calls into the LSM hooks with the noaudit flag set so that the LSM doesn't generate a denial if the application under confinement is missing the CAP_NET_ADMIN capability
Testcase:
# Load a test AppArmor profile
$ echo "profile test { file, }" | sudo apparmor_parser -rq
# Read a proc net sysctl file as root under confinement:
$ sudo aa-exec -p test -- cat /proc/sys/
128
# Manually inspect /var/log/syslog (or, if auditd is running, /var/log/
# audit: type=1400 audit(146257567
Original report:
Somewhere in the following code, this denial gets thrown. It's difficult to tell where because the report of the denial seems to be asynchronous, as it comes interspersed with all the other debug information being printed to stdout.
http://
Jun 16 14:21:51 localhost kernel: [ 7488.856306] audit: type=1400 audit(143446451
I can fix it by adding capability net_admin to /var/lib/
| Jamie Strandboge (jdstrand) wrote : | #1 |
| Jamie Strandboge (jdstrand) wrote : | #2 |
FYI,
`go-example-
audit: type=1400 audit(143447661
http://
| Jamie Strandboge (jdstrand) wrote : | #3 |
I was wrong about net/http. This is the simplest reproducer:
$ cat /tmp/profile
profile "foo" {
network,
ptrace,
signal,
file,
}
$ cat /tmp/main.go
package main
func main() {
}
$ sudo apparmor_parser -r /tmp/profile && sudo aa-exec -p foo go run /tmp/main.go
then see this denial:
audit: type=1400 audit(143447905
Running it as non-root does not show the denial. Eg,
$ sudo apparmor_parser -r /tmp/profile && aa-exec -p foo go run /tmp/main.go
| Jamie Strandboge (jdstrand) wrote : | #4 |
FYI, this issue exists all the way back to 12.04 (/tmp/profile should omit ptrace and signal when reproducing).
| Tyler Hicks (tyhicks) wrote : | #5 |
Even these two commands trigger the CAP_NET_ADMIN denial:
$ sudo apparmor_parser -r /tmp/profile && sudo aa-exec -p foo go --version
$ sudo apparmor_parser -r /tmp/profile && sudo aa-exec -p foo go --help
| Tyler Hicks (tyhicks) wrote : | #6 |
The capable(
2223 open("/
You can reproduce it by running the following command with and without sudo:
$ aa-exec -p foo -- cat /proc/sys/
$ sudo aa-exec -p foo -- cat /proc/sys/
| Tyler Hicks (tyhicks) wrote : | #7 |
If we want to track down the kernel code that is triggering this capable() check when running as root, here's a stack trace called from AppArmor's audit_caps() function. Note that I generated this on a vanilla kernel (4.1-rc8).
CPU: 1 PID: 2199 Comm: go Not tainted 4.1.0-rc8+ #120
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
00000000ffffffff ffff880079ff3a88 ffffffffb0634f04 0000000080000001
0000000000001000 ffff880079ff3b48 ffffffffb0348bf1 ffff88007f9d75d0
00000000001d2480 0000000c00000007 00000000001d2480 ffff880079ff3a03
Call Trace:
[<ffffffffb063
[<ffffffffb034
[<ffffffffb035
[<ffffffffb030
[<ffffffffb007
[<ffffffffb062
[<ffffffffb027
[<ffffffffb01f
[<ffffffffb01f
[<ffffffffb01f
[<ffffffffb03c
[<ffffffffb00b
[<ffffffffb00b
[<ffffffffb01f
[<ffffffffb01f
[<ffffffffb01f
[<ffffffffb000
[<ffffffffb00a
[<ffffffffb021
[<ffffffffb03c
[<ffffffffb00b
[<ffffffffb020
[<ffffffffb021
[<ffffffffb012
[<ffffffffb01e
[<ffffffffb001
[<ffffffffb01e
[<ffffffffb063
| Tyler Hicks (tyhicks) wrote : | #8 |
One potential fix, although I don't know if it is technically correct, is to switch the ordering of the calls to ns_capable() and uid_eq() here:
http://
| Tyler Hicks (tyhicks) wrote : | #9 |
I've verified that the proposed fix in comment #8 does work. I'll need to look at other ns_capable() call sites and get upstream's opinion before I can be confident in its correctness. Here's the raw patch:
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index e7000be..77e6bbf 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -46,8 +46,8 @@ static int net_ctl_
kgid_t root_gid = make_kgid(
/* Allow network administrator to have same access as root. */
- if (ns_capable(
- uid_eq(root_uid, current_euid())) {
+ if (uid_eq(root_uid, current_euid()) ||
+ ns_capable(
int mode = (table->mode >> 6) & 7;
return (mode << 6) | (mode << 3) | mode;
}
| Rick Spencer (rick-rickspencer3) wrote : | #10 |
For what it is worth, if any cares, here is a smaller code listing that produces the error
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"time"
)
import "gopkg.in/yaml.v2"
var config Config
type Config struct {
Duration string
}
func appDataPath() string {
//use the full path to the app when in a snap package, but
//for local development, assume that the app is run from bin/arch
dir := os.Getenv(
fmt.Println("app path ENV is " + dir)
if dir == "" {
fmt.Println("no snap app data path, guessing ../../")
dir = "../../"
}
return dir
}
func initConfig() {
//create a Config instance and fill it from the yaml file
dir := appDataPath()
yamlfilename := filepath.Join(dir, "cnf", "config.yaml")
fmt.Println(
yamlFile, err := ioutil.
err = yaml.Unmarshal(
if err != nil {
fmt.Println(
log.Fatal(err)
} else {
fmt.Println(
}
}
func main() {
fmt.Println(
initConfig()
s, err := time.ParseDurat
if err != nil {
fmt.Println(
log.Fatal(err)
}
ticker := time.NewTicker(s)
for _ = range ticker.C {
fmt.Println(
}
| Tyler Hicks (tyhicks) wrote : | #11 |
It is worth noting that this particular AppArmor denial is harmless. It does not affect go in any way because go is still able to read the /proc/sys/
| Rick Spencer (rick-rickspencer3) wrote : | #12 |
For clarity, this bug causes my service to fail, and I have to work around it by adding the net_admin cap.
| Michael Vogt (mvo) wrote : | #13 |
@Tyler did you get a chance to look at this again (as indicated in #11)?
| Changed in snappy: | |
| status: | New → Incomplete |
| Tyler Hicks (tyhicks) wrote : | #14 |
I have not yet had a chance to look at this issue again. However, Jamie helped Rick manually add 'capability net_admin,' to his service's AppArmor profile so that the denial wouldn't occur. After that change, Rick was able to verify that the AppArmor denial was not the cause of failure for his service.
We still plan to work with upstream to fix this issue soon but now feel confident that it is a harmless denial for root-runnign go apps.
| Changed in snappy: | |
| status: | Incomplete → Confirmed |
| importance: | Undecided → High |
| Jamie Strandboge (jdstrand) wrote : | #15 |
I think this may also affect java:
Sep 23 22:46:07 localhost kernel: [ 8184.860885] audit: type=1400 audit(144304836
but the server otherwise runs fine.
| Changed in snappy: | |
| assignee: | nobody → Tyler Hicks (tyhicks) |
| status: | Confirmed → In Progress |
| Tyler Hicks (tyhicks) wrote : | #16 |
Fixes sent to the upstream kernel lists:
| description: | updated |
| description: | updated |
| Changed in linux (Ubuntu Xenial): | |
| status: | New → Fix Committed |
This bug is missing log files that will aid in diagnosing the problem. From a terminal window please run:
apport-collect 1465724
and then change the status of the bug to 'Confirmed'.
If, due to the nature of the issue you have encountered, you are unable to run this command, please add a comment stating that fact and change the bug status to 'Confirmed'.
This change has been made by an automated script, maintained by the Ubuntu Kernel Team.
| Changed in linux (Ubuntu): | |
| status: | New → Incomplete |
| Kamal Mostafa (kamalmostafa) wrote : | #18 |
This bug is awaiting verification that the kernel in -proposed solves the problem. Please test the kernel and update this bug with the results. If the problem is solved, change the tag 'verification-
If verification is not done by 5 working days from today, this fix will be dropped from the source code, and this bug will be closed.
See https:/
| tags: | added: verification-needed-xenial |
| tags: |
added: verification-done-xenial removed: verification-needed-xenial |
| Launchpad Janitor (janitor) wrote : | #19 |
This bug was fixed in the package linux - 4.4.0-25.44
---------------
linux (4.4.0-25.44) xenial; urgency=low
[ Kamal Mostafa ]
* Release Tracking Bug
- LP: #1591289
* Xenial update to v4.4.13 stable release (LP: #1590455)
- MIPS64: R6: R2 emulation bugfix
- MIPS: math-emu: Fix jalr emulation when rd == $0
- MIPS: MSA: Fix a link error on `_init_msa_upper' with older GCC
- MIPS: Don't unwind to user mode with EVA
- MIPS: Avoid using unwind_stack() with usermode
- MIPS: Fix siginfo.h to use strict posix types
- MIPS: Fix uapi include in exported asm/siginfo.h
- MIPS: Fix watchpoint restoration
- MIPS: Flush highmem pages in __flush_dcache_page
- MIPS: Handle highmem pages in __update_cache
- MIPS: Sync icache & dcache in set_pte_at
- MIPS: ath79: make bootconsole wait for both THRE and TEMT
- MIPS: Reserve nosave data for hibernation
- MIPS: Loongson-3: Reserve 32MB for RS780E integrated GPU
- MIPS: Use copy_s.fmt rather than copy_u.fmt
- MIPS: Fix MSA ld_*/st_* asm macros to use PTR_ADDU
- MIPS: Prevent "restoration" of MSA context in non-MSA kernels
- MIPS: Disable preemption during prctl(PR_
- MIPS: ptrace: Fix FP context restoration FCSR regression
- MIPS: ptrace: Prevent writes to read-only FCSR bits
- MIPS: Fix sigreturn via VDSO on microMIPS kernel
- MIPS: Build microMIPS VDSO for microMIPS kernels
- MIPS: lib: Mark intrinsics notrace
- MIPS: VDSO: Build with `-fno-strict-
- affs: fix remount failure when there are no options changed
- ASoC: ak4642: Enable cache usage to fix crashes on resume
- Input: uinput - handle compat ioctl for UI_SET_PHYS
- ARM: mvebu: fix GPIO config on the Linksys boards
- ARM: dts: at91: fix typo in sama5d2 PIN_PD24 description
- ARM: dts: exynos: Add interrupt line to MAX8997 PMIC on exynos4210-trats
- ARM: dts: imx35: restore existing used clock enumeration
- ath9k: Add a module parameter to invert LED polarity.
- ath9k: Fix LED polarity for some Mini PCI AR9220 MB92 cards.
- ath10k: fix debugfs pktlog_filter write
- ath10k: fix firmware assert in monitor mode
- ath10k: fix rx_channel during hw reconfigure
- ath10k: fix kernel panic, move arvifs list head init before htt init
- ath5k: Change led pin configuration for compaq c700 laptop
- hwrng: exynos - Fix unbalanced PM runtime put on timeout error path
- rtlwifi: rtl8723be: Add antenna select module parameter
- rtlwifi: btcoexist: Implement antenna selection
- rtlwifi: Fix logic error in enter/exit power-save mode
- rtlwifi: pci: use dev_kfree_skb_irq instead of kfree_skb in
rtl_
- aacraid: Relinquish CPU during timeout wait
- aacraid: Fix for aac_command_thread hang
- aacraid: Fix for KDUMP driver hang
- hwmon: (ads7828) Enable internal reference
- mfd: intel-lpss: Save register context on suspend
- mfd: intel_soc_
correctly
- PM / Runtime: Fix error path in pm_runtime_
- cpuidle: Indicate when a device has been unregiste...
| Changed in linux (Ubuntu): | |
| status: | Incomplete → Fix Released |
| Launchpad Janitor (janitor) wrote : | #20 |
This bug was fixed in the package linux - 4.4.0-28.47
---------------
linux (4.4.0-28.47) xenial; urgency=low
[ Luis Henriques ]
* Release Tracking Bug
- LP: #1595874
* Linux netfilter local privilege escalation issues (LP: #1595350)
- netfilter: x_tables: don't move to non-existent next rule
- netfilter: x_tables: validate targets of jumps
- netfilter: x_tables: add and use xt_check_
- netfilter: x_tables: kill check_entry helper
- netfilter: x_tables: assert minimum target size
- netfilter: x_tables: add compat version of xt_check_
- netfilter: x_tables: check standard target size too
- netfilter: x_tables: check for bogus target offset
- netfilter: x_tables: validate all offsets and sizes in a rule
- netfilter: x_tables: don't reject valid target size on some architectures
- netfilter: arp_tables: simplify translate_
- netfilter: ip_tables: simplify translate_
- netfilter: ip6_tables: simplify translate_
- netfilter: x_tables: xt_compat_
- netfilter: x_tables: do compat validation via translate_table
- netfilter: x_tables: introduce and use xt_copy_
* Linux netfilter IPT_SO_SET_REPLACE memory corruption (LP: #1555338)
- netfilter: x_tables: validate e->target_offset early
- netfilter: x_tables: make sure e->next_offset covers remaining blob size
- netfilter: x_tables: fix unconditional helper
linux (4.4.0-27.46) xenial; urgency=low
[ Kamal Mostafa ]
* Release Tracking Bug
- LP: #1594906
* Support Edge Gateway's Bluetooth LED (LP: #1512999)
- Revert "UBUNTU: SAUCE: Bluetooth: Support for LED on Marvell modules"
linux (4.4.0-26.45) xenial; urgency=low
[ Kamal Mostafa ]
* Release Tracking Bug
- LP: #1594442
* linux: Implement secure boot state variables (LP: #1593075)
- SAUCE: UEFI: Add secure boot and MOK SB State disabled sysctl
* failures building userspace packages that include ethtool.h (LP: #1592930)
- ethtool.h: define INT_MAX for userland
linux (4.4.0-25.44) xenial; urgency=low
[ Kamal Mostafa ]
* Release Tracking Bug
- LP: #1591289
* Xenial update to v4.4.13 stable release (LP: #1590455)
- MIPS64: R6: R2 emulation bugfix
- MIPS: math-emu: Fix jalr emulation when rd == $0
- MIPS: MSA: Fix a link error on `_init_msa_upper' with older GCC
- MIPS: Don't unwind to user mode with EVA
- MIPS: Avoid using unwind_stack() with usermode
- MIPS: Fix siginfo.h to use strict posix types
- MIPS: Fix uapi include in exported asm/siginfo.h
- MIPS: Fix watchpoint restoration
- MIPS: Flush highmem pages in __flush_dcache_page
- MIPS: Handle highmem pages in __update_cache
- MIPS: Sync icache & dcache in set_pte_at
- MIPS: ath79: make bootconsole wait for both THRE and TEMT
- MIPS: Reserve nosave data for hibernation
- MIPS: Loongson-3: Reserve 32MB for RS780E integrated GPU
- MIPS: Use copy_s.fmt rather than copy_u.fmt
- MIPS: Fix MSA ld_*/st_* asm macros to use PTR_ADDU
- MIPS: Prevent "restoration" of MSA c...
| Changed in linux (Ubuntu Xenial): | |
| status: | Fix Committed → Fix Released |
| Changed in snappy: | |
| status: | In Progress → Fix Released |


For those reading this bug report, "net_admin" is used for the following (from man capabilities):
* interface configuration;
* administration of IP firewall, masquerading, and accounting;
* modify routing tables;
* bind to any address for transparent proxying;
* set type-of-service (TOS)
* clear driver statistics;
* set promiscuous mode;
* enabling multicasting;
* use setsockopt(2) to set the following socket options: SO_DEBUG, SO_MARK, SO_PRIORITY (for a priority outside the range 0 to 6), SO_RCVBUFFORCE, and SO_SNDBUFFORCE.
This is quite a set of privileges and our AppArmor policy is correctly denying the access.
I have a feeling this is a harmless denial related to setsockopt() by the "net/http" import and that go tries to do something with setsockopt and happily proceeds if it cannot.