From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932760AbdBHAof (ORCPT ); Tue, 7 Feb 2017 19:44:35 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:55521 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752480AbdBHAob (ORCPT ); Tue, 7 Feb 2017 19:44:31 -0500 Subject: Re: [PATCH v2 1/4] seccomp: Add sysctl to display available actions To: Kees Cook References: <1486100262-32391-1-git-send-email-tyhicks@canonical.com> <1486100262-32391-2-git-send-email-tyhicks@canonical.com> Cc: Paul Moore , Eric Paris , Andy Lutomirski , Will Drewry , linux-audit@redhat.com, LKML From: Tyler Hicks Message-ID: Date: Tue, 7 Feb 2017 18:25:11 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="v6dWaVham0CsiI5IIDCTGp4QMNvneGA24" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --v6dWaVham0CsiI5IIDCTGp4QMNvneGA24 Content-Type: multipart/mixed; boundary="W1uKqDt307Fx1krFGdgBF5StQNXkOTXl5"; protected-headers="v1" From: Tyler Hicks To: Kees Cook Cc: Paul Moore , Eric Paris , Andy Lutomirski , Will Drewry , linux-audit@redhat.com, LKML Message-ID: Subject: Re: [PATCH v2 1/4] seccomp: Add sysctl to display available actions References: <1486100262-32391-1-git-send-email-tyhicks@canonical.com> <1486100262-32391-2-git-send-email-tyhicks@canonical.com> In-Reply-To: --W1uKqDt307Fx1krFGdgBF5StQNXkOTXl5 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/07/2017 06:03 PM, Kees Cook wrote: > On Thu, Feb 2, 2017 at 9:37 PM, Tyler Hicks wro= te: >> This patch creates a read-only sysctl containing an ordered list of >> seccomp actions that the kernel supports. The ordering, from left to >> right, is the lowest action value (kill) to the highest action value >> (allow). Currently, a read of the sysctl file would return "kill trap >> errno trace allow". The contents of this sysctl file can be useful for= >> userspace code as well as the system administrator. >> >> The path to the sysctl is: >> >> /proc/sys/kernel/seccomp/actions_avail >> >> libseccomp and other userspace code can easily determine which actions= >> the current kernel supports. The set of actions supported by the curre= nt >> kernel may be different than the set of action macros found in kernel >> headers that were installed where the userspace code was built. >=20 > This is certainly good: having a discoverable way to detect filter > capabilities. I do wonder if it'd still be easier to just expose the > max_log sysctl as a numeric value, since the SECCOMP_RET_* values are > all part of uapi, so we can't escape their values... I was very torn on whether to use a numeric or string representation here. The reason I decided on string representation is because I think these sysctls are mostly aimed for admins and numeric representations wouldn't be easy to use. I considered added a utility to libseccomp but, since the kernel code to do a string representation was so simple, I went with doing it in the kernel. Another possibility is exposing the SECCOMP_RET_*_NAME macros as part of the uapi. >=20 >=20 >=20 >> >> In addition, this sysctl will allow system administrators to know whic= h >> actions are supported by the kernel and make it easier to configure >> exactly what seccomp logs through the audit subsystem. Support for thi= s >> level of logging configuration will come in a future patch. >> >> Signed-off-by: Tyler Hicks >> --- >> kernel/seccomp.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++= +++ >> 1 file changed, 50 insertions(+) >> >> diff --git a/kernel/seccomp.c b/kernel/seccomp.c >> index f7ce79a..919ad9f 100644 >> --- a/kernel/seccomp.c >> +++ b/kernel/seccomp.c >> @@ -16,10 +16,12 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> #include >> +#include >> >> #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER >> #include >> @@ -905,3 +907,51 @@ long seccomp_get_filter(struct task_struct *task,= unsigned long filter_off, >> return ret; >> } >> #endif >> + >> +#ifdef CONFIG_SYSCTL >> + >> +#define SECCOMP_RET_KILL_NAME "kill" >> +#define SECCOMP_RET_TRAP_NAME "trap" >> +#define SECCOMP_RET_ERRNO_NAME "errno" >> +#define SECCOMP_RET_TRACE_NAME "trace" >> +#define SECCOMP_RET_ALLOW_NAME "allow" >> + >> +static char seccomp_actions_avail[] =3D SECCOMP_RET_KILL_NAME " " >> + SECCOMP_RET_TRAP_NAME " " >> + SECCOMP_RET_ERRNO_NAME " " >> + SECCOMP_RET_TRACE_NAME " " >> + SECCOMP_RET_ALLOW_NAME; >> + >> +static struct ctl_path seccomp_sysctl_path[] =3D { >> + { .procname =3D "kernel", }, >> + { .procname =3D "seccomp", }, >> + { } >> +}; >> + >> +static struct ctl_table seccomp_sysctl_table[] =3D { >> + { >> + .procname =3D "actions_avail", >> + .data =3D &seccomp_actions_avail, >> + .maxlen =3D sizeof(seccomp_actions_avail), >> + .mode =3D 0444, >> + .proc_handler =3D proc_dostring, >> + }, >> + { } >> +}; >> + >> +static int __init seccomp_sysctl_init(void) >> +{ >> + struct ctl_table_header *hdr; >> + >> + hdr =3D register_sysctl_paths(seccomp_sysctl_path, seccomp_sys= ctl_table); >> + kmemleak_not_leak(hdr); >=20 > Will kmemleak complain about this if hdr is saved to a global (or not > saved at all)? Also, something should be reported in the failure > case... I have to admit to blindly following the example set by sysctl_init() in kernel/sysctl.c. I can test what kmemleak will/won't complain about and report back (tomorrow at the earliest). Tyler >=20 >> + return 0; >> +} >> + >> +#else /* CONFIG_SYSCTL */ >> + >> +static __init int seccomp_sysctl_init(void) { return 0; } >> + >> +#endif /* CONFIG_SYSCTL */ >> + >> +device_initcall(seccomp_sysctl_init) >> -- >> 2.7.4 >> >=20 > -Kees >=20 --W1uKqDt307Fx1krFGdgBF5StQNXkOTXl5-- --v6dWaVham0CsiI5IIDCTGp4QMNvneGA24 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCgAGBQJYmmVnAAoJENaSAD2qAscKJx4QAJTdTQ4VwSE86XRRdEe1KzFl k6rUc0ZHZAUJBeYVrQtsC0/2naroSxKf+4onWdZAaNANgVpSP1S4l2W0i8TI0N2g 8r6TUPaOfexJsrF7ZCXx4VFG9LnwHndM7aEpGzjMX2DsyDcuzmPjIkjvClUAhmGe RK/d6bFohWrZkrgj1bFzlJrjAk1J/TGHX8QwPN5xJvFSjsnrZaAEOiJe9glE8WWF tw0rVMdhRdFnauusrov55k2SwA7z0hlc4sPclqEqzt9zuenI78oIq5Mmd8nYcvqt dCls/FRwLHYwfhEFzTwOnFfwYlou+8CO7IheWoCb2V9aFA0dgRMRoBJ3JkuEnfFx 83FkmKcgszVtaOLTFDmw+W+hkbD7Y1PR9xEDAvBrUXnzb0Z4fS/hRmVE4F4LitM+ GQ0B1j/h4oMoxCYr1JXA18uRhFYo8FRnjIxOCqBUGCq4IEhADM2hc5WfXflRS0lQ sXgAt2AeKUE39Dfh3sNwaNllHdo2HBpHw647Lh2VXRZT3TXFVhaqNw1yV6XZF0HO dv5ZjnYND6quuKup0v9ZtTxek4K3iP0LP+6BQjdlmF/AuSnMO6Oh4WAiNfbns9v7 IdSNbAmjRELvF5qMpR5HYT3Uym951oJZ2NMpOoO5vBNm9hzAP34vC8cZVeakoVSy Dvyzrx3axrtALmPgAKFv =k2zD -----END PGP SIGNATURE----- --v6dWaVham0CsiI5IIDCTGp4QMNvneGA24--