From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964811AbdDSWTY (ORCPT ); Wed, 19 Apr 2017 18:19:24 -0400 Received: from smtp-sh2.infomaniak.ch ([128.65.195.6]:42347 "EHLO smtp-sh2.infomaniak.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1765393AbdDSWTV (ORCPT ); Wed, 19 Apr 2017 18:19:21 -0400 Subject: Re: [PATCH net-next v6 05/11] seccomp: Split put_seccomp_filter() with put_seccomp() To: Kees Cook References: <20170328234650.19695-1-mic@digikod.net> <20170328234650.19695-6-mic@digikod.net> <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> Cc: LKML , Alexei Starovoitov , Andy Lutomirski , Arnaldo Carvalho de Melo , Casey Schaufler , Daniel Borkmann , David Drysdale , "David S . Miller" , "Eric W . Biederman" , James Morris , Jann Horn , Jonathan Corbet , Matthew Garrett , Michael Kerrisk , Paul Moore , Sargun Dhillon , "Serge E . Hallyn" , Shuah Khan , Tejun Heo , Thomas Graf , Will Drewry , "kernel-hardening@lists.openwall.com" , Linux API , linux-security-module , Network Development From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Message-ID: <96024881-1bcc-33af-6285-d9a904de963e@digikod.net> Date: Thu, 20 Apr 2017 00:18:04 +0200 User-Agent: MIME-Version: 1.0 In-Reply-To: <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE" X-Antivirus: Dr.Web (R) for Unix mail servers drweb plugin ver.6.0.2.8 X-Antivirus-Code: 0x100000 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) --PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE Content-Type: multipart/mixed; boundary="2kpFJb6D2qvUV0dV2W5akJuaRugWD6OBW"; protected-headers="v1" From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= To: Kees Cook Cc: LKML , Alexei Starovoitov , Andy Lutomirski , Arnaldo Carvalho de Melo , Casey Schaufler , Daniel Borkmann , David Drysdale , "David S . Miller" , "Eric W . Biederman" , James Morris , Jann Horn , Jonathan Corbet , Matthew Garrett , Michael Kerrisk , Paul Moore , Sargun Dhillon , "Serge E . Hallyn" , Shuah Khan , Tejun Heo , Thomas Graf , Will Drewry , "kernel-hardening@lists.openwall.com" , Linux API , linux-security-module , Network Development Message-ID: <96024881-1bcc-33af-6285-d9a904de963e@digikod.net> Subject: Re: [PATCH net-next v6 05/11] seccomp: Split put_seccomp_filter() with put_seccomp() References: <20170328234650.19695-1-mic@digikod.net> <20170328234650.19695-6-mic@digikod.net> <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> In-Reply-To: <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> --2kpFJb6D2qvUV0dV2W5akJuaRugWD6OBW Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 19/04/2017 00:47, Micka=C3=ABl Sala=C3=BCn wrote: >=20 > On 19/04/2017 00:23, Kees Cook wrote: >> On Tue, Mar 28, 2017 at 4:46 PM, Micka=C3=ABl Sala=C3=BCn wrote: >>> The semantic is unchanged. This will be useful for the Landlock >>> integration with seccomp (next commit). >>> >>> Signed-off-by: Micka=C3=ABl Sala=C3=BCn >>> Cc: Kees Cook >>> Cc: Andy Lutomirski >>> Cc: Will Drewry >>> --- >>> include/linux/seccomp.h | 4 ++-- >>> kernel/fork.c | 2 +- >>> kernel/seccomp.c | 18 +++++++++++++----- >>> 3 files changed, 16 insertions(+), 8 deletions(-) >>> >>> diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h >>> index ecc296c137cd..e25aee2cdfc0 100644 >>> --- a/include/linux/seccomp.h >>> +++ b/include/linux/seccomp.h >>> @@ -77,10 +77,10 @@ static inline int seccomp_mode(struct seccomp *s)= >>> #endif /* CONFIG_SECCOMP */ >>> >>> #ifdef CONFIG_SECCOMP_FILTER >>> -extern void put_seccomp_filter(struct task_struct *tsk); >>> +extern void put_seccomp(struct task_struct *tsk); >>> extern void get_seccomp_filter(struct task_struct *tsk); >>> #else /* CONFIG_SECCOMP_FILTER */ >>> -static inline void put_seccomp_filter(struct task_struct *tsk) >>> +static inline void put_seccomp(struct task_struct *tsk) >>> { >>> return; >>> } >>> diff --git a/kernel/fork.c b/kernel/fork.c >>> index 6c463c80e93d..a27d8e67ce33 100644 >>> --- a/kernel/fork.c >>> +++ b/kernel/fork.c >>> @@ -363,7 +363,7 @@ void free_task(struct task_struct *tsk) >>> #endif >>> rt_mutex_debug_task_free(tsk); >>> ftrace_graph_exit_task(tsk); >>> - put_seccomp_filter(tsk); >>> + put_seccomp(tsk); >>> arch_release_task_struct(tsk); >>> if (tsk->flags & PF_KTHREAD) >>> free_kthread_struct(tsk); >>> diff --git a/kernel/seccomp.c b/kernel/seccomp.c >>> index 65f61077ad50..326f79e32127 100644 >>> --- a/kernel/seccomp.c >>> +++ b/kernel/seccomp.c >>> @@ -64,6 +64,8 @@ struct seccomp_filter { >>> /* Limit any path through the tree to 256KB worth of instructions. *= / >>> #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter)) >>> >>> +static void put_seccomp_filter(struct seccomp_filter *filter); >> >> Can this be reorganized easily to avoid a forward-declaration? >=20 > I didn't want to move too much code but I will. >=20 >> >>> + >>> /* >>> * Endianness is explicitly ignored and left for BPF program authors= to manage >>> * as per the specific architecture. >>> @@ -314,7 +316,7 @@ static inline void seccomp_sync_threads(void) >>> * current's path will hold a reference. (This also >>> * allows a put before the assignment.) >>> */ >>> - put_seccomp_filter(thread); >>> + put_seccomp_filter(thread->seccomp.filter); >>> smp_store_release(&thread->seccomp.filter, >>> caller->seccomp.filter); >>> >>> @@ -476,10 +478,11 @@ static inline void seccomp_filter_free(struct s= eccomp_filter *filter) >>> } >>> } >>> >>> -/* put_seccomp_filter - decrements the ref count of tsk->seccomp.fil= ter */ >>> -void put_seccomp_filter(struct task_struct *tsk) >>> +/* put_seccomp_filter - decrements the ref count of a filter */ >>> +static void put_seccomp_filter(struct seccomp_filter *filter) >>> { >>> - struct seccomp_filter *orig =3D tsk->seccomp.filter; >>> + struct seccomp_filter *orig =3D filter; >>> + >>> /* Clean up single-reference branches iteratively. */ >>> while (orig && atomic_dec_and_test(&orig->usage)) { >>> struct seccomp_filter *freeme =3D orig; >>> @@ -488,6 +491,11 @@ void put_seccomp_filter(struct task_struct *tsk)= >>> } >>> } >>> >>> +void put_seccomp(struct task_struct *tsk) >>> +{ >>> + put_seccomp_filter(tsk->seccomp.filter); >>> +} >>> + >>> static void seccomp_init_siginfo(siginfo_t *info, int syscall, int r= eason) >>> { >>> memset(info, 0, sizeof(*info)); >>> @@ -914,7 +922,7 @@ long seccomp_get_filter(struct task_struct *task,= unsigned long filter_off, >>> if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fpr= og))) >>> ret =3D -EFAULT; >>> >>> - put_seccomp_filter(task); >>> + put_seccomp_filter(task->seccomp.filter); >>> return ret; >> >> I don't like that the arguments to get_seccomp_filter() and >> put_seccomp_filter() are now different. I think they should match for >> readability. >=20 > OK, I can do that. >=20 Kees, can I send this as a separate patch? --2kpFJb6D2qvUV0dV2W5akJuaRugWD6OBW-- --PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEUysCyY8er9Axt7hqIt7+33O9apUFAlj34hwACgkQIt7+33O9 apUqiAf/W6XDRtopGxrSLPUSvfwzYK1ZxJ+POYZ170a5F8MW8I6jQ7XSYi1Ssezu d+8nbA01nGXh7uEx19bErJZcksIXVSLqTQbmzdgQ9xJir8XMydB38PEQ1R0GHHfB S/5hOKEeyHQtJMGdPfZ1kwSuzt428vO04G0OUaKDNZxBkNzOO9FIS9Cj5soF8CU/ N4dYq+fZRtDYIhb9ybFkvEn5n/IewOHC2UX6Ox7qu8Xi2+tKGzwEDngvUrlDAHY3 B2vAlUr3byi4keNFLgxb1paHDferHAjvjJTAMHTXNZYjapioqMUDm2QGb9QAWYJ8 yKMerLmmLoqzZ1hi+RxXKug28tziOw== =heH2 -----END PGP SIGNATURE----- --PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Subject: Re: [PATCH net-next v6 05/11] seccomp: Split put_seccomp_filter() with put_seccomp() Date: Thu, 20 Apr 2017 00:18:04 +0200 Message-ID: <96024881-1bcc-33af-6285-d9a904de963e@digikod.net> References: <20170328234650.19695-1-mic@digikod.net> <20170328234650.19695-6-mic@digikod.net> <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE" Cc: LKML , Alexei Starovoitov , Andy Lutomirski , Arnaldo Carvalho de Melo , Casey Schaufler , Daniel Borkmann , David Drysdale , "David S . Miller" , "Eric W . Biederman" , James Morris , Jann Horn , Jonathan Corbet , Matthew Garrett , Michael Kerrisk , Paul Moore , Sargun Dhillon , "Serge E . Hallyn" , Shuah Khan , Tejun Heo , Thomas Graf , Will Drewry To: Kees Cook Return-path: List-Post: List-Help: List-Unsubscribe: List-Subscribe: In-Reply-To: <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> List-Id: netdev.vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE Content-Type: multipart/mixed; boundary="2kpFJb6D2qvUV0dV2W5akJuaRugWD6OBW"; protected-headers="v1" From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= To: Kees Cook Cc: LKML , Alexei Starovoitov , Andy Lutomirski , Arnaldo Carvalho de Melo , Casey Schaufler , Daniel Borkmann , David Drysdale , "David S . Miller" , "Eric W . Biederman" , James Morris , Jann Horn , Jonathan Corbet , Matthew Garrett , Michael Kerrisk , Paul Moore , Sargun Dhillon , "Serge E . Hallyn" , Shuah Khan , Tejun Heo , Thomas Graf , Will Drewry , "kernel-hardening@lists.openwall.com" , Linux API , linux-security-module , Network Development Message-ID: <96024881-1bcc-33af-6285-d9a904de963e@digikod.net> Subject: Re: [PATCH net-next v6 05/11] seccomp: Split put_seccomp_filter() with put_seccomp() References: <20170328234650.19695-1-mic@digikod.net> <20170328234650.19695-6-mic@digikod.net> <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> In-Reply-To: <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> --2kpFJb6D2qvUV0dV2W5akJuaRugWD6OBW Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 19/04/2017 00:47, Micka=C3=ABl Sala=C3=BCn wrote: >=20 > On 19/04/2017 00:23, Kees Cook wrote: >> On Tue, Mar 28, 2017 at 4:46 PM, Micka=C3=ABl Sala=C3=BCn wrote: >>> The semantic is unchanged. This will be useful for the Landlock >>> integration with seccomp (next commit). >>> >>> Signed-off-by: Micka=C3=ABl Sala=C3=BCn >>> Cc: Kees Cook >>> Cc: Andy Lutomirski >>> Cc: Will Drewry >>> --- >>> include/linux/seccomp.h | 4 ++-- >>> kernel/fork.c | 2 +- >>> kernel/seccomp.c | 18 +++++++++++++----- >>> 3 files changed, 16 insertions(+), 8 deletions(-) >>> >>> diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h >>> index ecc296c137cd..e25aee2cdfc0 100644 >>> --- a/include/linux/seccomp.h >>> +++ b/include/linux/seccomp.h >>> @@ -77,10 +77,10 @@ static inline int seccomp_mode(struct seccomp *s)= >>> #endif /* CONFIG_SECCOMP */ >>> >>> #ifdef CONFIG_SECCOMP_FILTER >>> -extern void put_seccomp_filter(struct task_struct *tsk); >>> +extern void put_seccomp(struct task_struct *tsk); >>> extern void get_seccomp_filter(struct task_struct *tsk); >>> #else /* CONFIG_SECCOMP_FILTER */ >>> -static inline void put_seccomp_filter(struct task_struct *tsk) >>> +static inline void put_seccomp(struct task_struct *tsk) >>> { >>> return; >>> } >>> diff --git a/kernel/fork.c b/kernel/fork.c >>> index 6c463c80e93d..a27d8e67ce33 100644 >>> --- a/kernel/fork.c >>> +++ b/kernel/fork.c >>> @@ -363,7 +363,7 @@ void free_task(struct task_struct *tsk) >>> #endif >>> rt_mutex_debug_task_free(tsk); >>> ftrace_graph_exit_task(tsk); >>> - put_seccomp_filter(tsk); >>> + put_seccomp(tsk); >>> arch_release_task_struct(tsk); >>> if (tsk->flags & PF_KTHREAD) >>> free_kthread_struct(tsk); >>> diff --git a/kernel/seccomp.c b/kernel/seccomp.c >>> index 65f61077ad50..326f79e32127 100644 >>> --- a/kernel/seccomp.c >>> +++ b/kernel/seccomp.c >>> @@ -64,6 +64,8 @@ struct seccomp_filter { >>> /* Limit any path through the tree to 256KB worth of instructions. *= / >>> #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter)) >>> >>> +static void put_seccomp_filter(struct seccomp_filter *filter); >> >> Can this be reorganized easily to avoid a forward-declaration? >=20 > I didn't want to move too much code but I will. >=20 >> >>> + >>> /* >>> * Endianness is explicitly ignored and left for BPF program authors= to manage >>> * as per the specific architecture. >>> @@ -314,7 +316,7 @@ static inline void seccomp_sync_threads(void) >>> * current's path will hold a reference. (This also >>> * allows a put before the assignment.) >>> */ >>> - put_seccomp_filter(thread); >>> + put_seccomp_filter(thread->seccomp.filter); >>> smp_store_release(&thread->seccomp.filter, >>> caller->seccomp.filter); >>> >>> @@ -476,10 +478,11 @@ static inline void seccomp_filter_free(struct s= eccomp_filter *filter) >>> } >>> } >>> >>> -/* put_seccomp_filter - decrements the ref count of tsk->seccomp.fil= ter */ >>> -void put_seccomp_filter(struct task_struct *tsk) >>> +/* put_seccomp_filter - decrements the ref count of a filter */ >>> +static void put_seccomp_filter(struct seccomp_filter *filter) >>> { >>> - struct seccomp_filter *orig =3D tsk->seccomp.filter; >>> + struct seccomp_filter *orig =3D filter; >>> + >>> /* Clean up single-reference branches iteratively. */ >>> while (orig && atomic_dec_and_test(&orig->usage)) { >>> struct seccomp_filter *freeme =3D orig; >>> @@ -488,6 +491,11 @@ void put_seccomp_filter(struct task_struct *tsk)= >>> } >>> } >>> >>> +void put_seccomp(struct task_struct *tsk) >>> +{ >>> + put_seccomp_filter(tsk->seccomp.filter); >>> +} >>> + >>> static void seccomp_init_siginfo(siginfo_t *info, int syscall, int r= eason) >>> { >>> memset(info, 0, sizeof(*info)); >>> @@ -914,7 +922,7 @@ long seccomp_get_filter(struct task_struct *task,= unsigned long filter_off, >>> if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fpr= og))) >>> ret =3D -EFAULT; >>> >>> - put_seccomp_filter(task); >>> + put_seccomp_filter(task->seccomp.filter); >>> return ret; >> >> I don't like that the arguments to get_seccomp_filter() and >> put_seccomp_filter() are now different. I think they should match for >> readability. >=20 > OK, I can do that. >=20 Kees, can I send this as a separate patch? --2kpFJb6D2qvUV0dV2W5akJuaRugWD6OBW-- --PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEUysCyY8er9Axt7hqIt7+33O9apUFAlj34hwACgkQIt7+33O9 apUqiAf/W6XDRtopGxrSLPUSvfwzYK1ZxJ+POYZ170a5F8MW8I6jQ7XSYi1Ssezu d+8nbA01nGXh7uEx19bErJZcksIXVSLqTQbmzdgQ9xJir8XMydB38PEQ1R0GHHfB S/5hOKEeyHQtJMGdPfZ1kwSuzt428vO04G0OUaKDNZxBkNzOO9FIS9Cj5soF8CU/ N4dYq+fZRtDYIhb9ybFkvEn5n/IewOHC2UX6Ox7qu8Xi2+tKGzwEDngvUrlDAHY3 B2vAlUr3byi4keNFLgxb1paHDferHAjvjJTAMHTXNZYjapioqMUDm2QGb9QAWYJ8 yKMerLmmLoqzZ1hi+RxXKug28tziOw== =heH2 -----END PGP SIGNATURE----- --PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: mic@digikod.net (=?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?=) Date: Thu, 20 Apr 2017 00:18:04 +0200 Subject: [PATCH net-next v6 05/11] seccomp: Split put_seccomp_filter() with put_seccomp() In-Reply-To: <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> References: <20170328234650.19695-1-mic@digikod.net> <20170328234650.19695-6-mic@digikod.net> <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> Message-ID: <96024881-1bcc-33af-6285-d9a904de963e@digikod.net> To: linux-security-module@vger.kernel.org List-Id: linux-security-module.vger.kernel.org On 19/04/2017 00:47, Micka?l Sala?n wrote: > > On 19/04/2017 00:23, Kees Cook wrote: >> On Tue, Mar 28, 2017 at 4:46 PM, Micka?l Sala?n wrote: >>> The semantic is unchanged. This will be useful for the Landlock >>> integration with seccomp (next commit). >>> >>> Signed-off-by: Micka?l Sala?n >>> Cc: Kees Cook >>> Cc: Andy Lutomirski >>> Cc: Will Drewry >>> --- >>> include/linux/seccomp.h | 4 ++-- >>> kernel/fork.c | 2 +- >>> kernel/seccomp.c | 18 +++++++++++++----- >>> 3 files changed, 16 insertions(+), 8 deletions(-) >>> >>> diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h >>> index ecc296c137cd..e25aee2cdfc0 100644 >>> --- a/include/linux/seccomp.h >>> +++ b/include/linux/seccomp.h >>> @@ -77,10 +77,10 @@ static inline int seccomp_mode(struct seccomp *s) >>> #endif /* CONFIG_SECCOMP */ >>> >>> #ifdef CONFIG_SECCOMP_FILTER >>> -extern void put_seccomp_filter(struct task_struct *tsk); >>> +extern void put_seccomp(struct task_struct *tsk); >>> extern void get_seccomp_filter(struct task_struct *tsk); >>> #else /* CONFIG_SECCOMP_FILTER */ >>> -static inline void put_seccomp_filter(struct task_struct *tsk) >>> +static inline void put_seccomp(struct task_struct *tsk) >>> { >>> return; >>> } >>> diff --git a/kernel/fork.c b/kernel/fork.c >>> index 6c463c80e93d..a27d8e67ce33 100644 >>> --- a/kernel/fork.c >>> +++ b/kernel/fork.c >>> @@ -363,7 +363,7 @@ void free_task(struct task_struct *tsk) >>> #endif >>> rt_mutex_debug_task_free(tsk); >>> ftrace_graph_exit_task(tsk); >>> - put_seccomp_filter(tsk); >>> + put_seccomp(tsk); >>> arch_release_task_struct(tsk); >>> if (tsk->flags & PF_KTHREAD) >>> free_kthread_struct(tsk); >>> diff --git a/kernel/seccomp.c b/kernel/seccomp.c >>> index 65f61077ad50..326f79e32127 100644 >>> --- a/kernel/seccomp.c >>> +++ b/kernel/seccomp.c >>> @@ -64,6 +64,8 @@ struct seccomp_filter { >>> /* Limit any path through the tree to 256KB worth of instructions. */ >>> #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter)) >>> >>> +static void put_seccomp_filter(struct seccomp_filter *filter); >> >> Can this be reorganized easily to avoid a forward-declaration? > > I didn't want to move too much code but I will. > >> >>> + >>> /* >>> * Endianness is explicitly ignored and left for BPF program authors to manage >>> * as per the specific architecture. >>> @@ -314,7 +316,7 @@ static inline void seccomp_sync_threads(void) >>> * current's path will hold a reference. (This also >>> * allows a put before the assignment.) >>> */ >>> - put_seccomp_filter(thread); >>> + put_seccomp_filter(thread->seccomp.filter); >>> smp_store_release(&thread->seccomp.filter, >>> caller->seccomp.filter); >>> >>> @@ -476,10 +478,11 @@ static inline void seccomp_filter_free(struct seccomp_filter *filter) >>> } >>> } >>> >>> -/* put_seccomp_filter - decrements the ref count of tsk->seccomp.filter */ >>> -void put_seccomp_filter(struct task_struct *tsk) >>> +/* put_seccomp_filter - decrements the ref count of a filter */ >>> +static void put_seccomp_filter(struct seccomp_filter *filter) >>> { >>> - struct seccomp_filter *orig = tsk->seccomp.filter; >>> + struct seccomp_filter *orig = filter; >>> + >>> /* Clean up single-reference branches iteratively. */ >>> while (orig && atomic_dec_and_test(&orig->usage)) { >>> struct seccomp_filter *freeme = orig; >>> @@ -488,6 +491,11 @@ void put_seccomp_filter(struct task_struct *tsk) >>> } >>> } >>> >>> +void put_seccomp(struct task_struct *tsk) >>> +{ >>> + put_seccomp_filter(tsk->seccomp.filter); >>> +} >>> + >>> static void seccomp_init_siginfo(siginfo_t *info, int syscall, int reason) >>> { >>> memset(info, 0, sizeof(*info)); >>> @@ -914,7 +922,7 @@ long seccomp_get_filter(struct task_struct *task, unsigned long filter_off, >>> if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fprog))) >>> ret = -EFAULT; >>> >>> - put_seccomp_filter(task); >>> + put_seccomp_filter(task->seccomp.filter); >>> return ret; >> >> I don't like that the arguments to get_seccomp_filter() and >> put_seccomp_filter() are now different. I think they should match for >> readability. > > OK, I can do that. > Kees, can I send this as a separate patch? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From mboxrd@z Thu Jan 1 00:00:00 1970 References: <20170328234650.19695-1-mic@digikod.net> <20170328234650.19695-6-mic@digikod.net> <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Message-ID: <96024881-1bcc-33af-6285-d9a904de963e@digikod.net> Date: Thu, 20 Apr 2017 00:18:04 +0200 MIME-Version: 1.0 In-Reply-To: <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE" Subject: [kernel-hardening] Re: [PATCH net-next v6 05/11] seccomp: Split put_seccomp_filter() with put_seccomp() To: Kees Cook Cc: LKML , Alexei Starovoitov , Andy Lutomirski , Arnaldo Carvalho de Melo , Casey Schaufler , Daniel Borkmann , David Drysdale , "David S . Miller" , "Eric W . Biederman" , James Morris , Jann Horn , Jonathan Corbet , Matthew Garrett , Michael Kerrisk , Paul Moore , Sargun Dhillon , "Serge E . Hallyn" , Shuah Khan , Tejun Heo , Thomas Graf , Will Drewry , "kernel-hardening@lists.openwall.com" , Linux API , linux-security-module , Network Development List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE Content-Type: multipart/mixed; boundary="2kpFJb6D2qvUV0dV2W5akJuaRugWD6OBW"; protected-headers="v1" From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= To: Kees Cook Cc: LKML , Alexei Starovoitov , Andy Lutomirski , Arnaldo Carvalho de Melo , Casey Schaufler , Daniel Borkmann , David Drysdale , "David S . Miller" , "Eric W . Biederman" , James Morris , Jann Horn , Jonathan Corbet , Matthew Garrett , Michael Kerrisk , Paul Moore , Sargun Dhillon , "Serge E . Hallyn" , Shuah Khan , Tejun Heo , Thomas Graf , Will Drewry , "kernel-hardening@lists.openwall.com" , Linux API , linux-security-module , Network Development Message-ID: <96024881-1bcc-33af-6285-d9a904de963e@digikod.net> Subject: Re: [PATCH net-next v6 05/11] seccomp: Split put_seccomp_filter() with put_seccomp() References: <20170328234650.19695-1-mic@digikod.net> <20170328234650.19695-6-mic@digikod.net> <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> In-Reply-To: <9b420ecc-f062-8ab3-0b18-e09c60a00c6a@digikod.net> --2kpFJb6D2qvUV0dV2W5akJuaRugWD6OBW Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 19/04/2017 00:47, Micka=C3=ABl Sala=C3=BCn wrote: >=20 > On 19/04/2017 00:23, Kees Cook wrote: >> On Tue, Mar 28, 2017 at 4:46 PM, Micka=C3=ABl Sala=C3=BCn wrote: >>> The semantic is unchanged. This will be useful for the Landlock >>> integration with seccomp (next commit). >>> >>> Signed-off-by: Micka=C3=ABl Sala=C3=BCn >>> Cc: Kees Cook >>> Cc: Andy Lutomirski >>> Cc: Will Drewry >>> --- >>> include/linux/seccomp.h | 4 ++-- >>> kernel/fork.c | 2 +- >>> kernel/seccomp.c | 18 +++++++++++++----- >>> 3 files changed, 16 insertions(+), 8 deletions(-) >>> >>> diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h >>> index ecc296c137cd..e25aee2cdfc0 100644 >>> --- a/include/linux/seccomp.h >>> +++ b/include/linux/seccomp.h >>> @@ -77,10 +77,10 @@ static inline int seccomp_mode(struct seccomp *s)= >>> #endif /* CONFIG_SECCOMP */ >>> >>> #ifdef CONFIG_SECCOMP_FILTER >>> -extern void put_seccomp_filter(struct task_struct *tsk); >>> +extern void put_seccomp(struct task_struct *tsk); >>> extern void get_seccomp_filter(struct task_struct *tsk); >>> #else /* CONFIG_SECCOMP_FILTER */ >>> -static inline void put_seccomp_filter(struct task_struct *tsk) >>> +static inline void put_seccomp(struct task_struct *tsk) >>> { >>> return; >>> } >>> diff --git a/kernel/fork.c b/kernel/fork.c >>> index 6c463c80e93d..a27d8e67ce33 100644 >>> --- a/kernel/fork.c >>> +++ b/kernel/fork.c >>> @@ -363,7 +363,7 @@ void free_task(struct task_struct *tsk) >>> #endif >>> rt_mutex_debug_task_free(tsk); >>> ftrace_graph_exit_task(tsk); >>> - put_seccomp_filter(tsk); >>> + put_seccomp(tsk); >>> arch_release_task_struct(tsk); >>> if (tsk->flags & PF_KTHREAD) >>> free_kthread_struct(tsk); >>> diff --git a/kernel/seccomp.c b/kernel/seccomp.c >>> index 65f61077ad50..326f79e32127 100644 >>> --- a/kernel/seccomp.c >>> +++ b/kernel/seccomp.c >>> @@ -64,6 +64,8 @@ struct seccomp_filter { >>> /* Limit any path through the tree to 256KB worth of instructions. *= / >>> #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter)) >>> >>> +static void put_seccomp_filter(struct seccomp_filter *filter); >> >> Can this be reorganized easily to avoid a forward-declaration? >=20 > I didn't want to move too much code but I will. >=20 >> >>> + >>> /* >>> * Endianness is explicitly ignored and left for BPF program authors= to manage >>> * as per the specific architecture. >>> @@ -314,7 +316,7 @@ static inline void seccomp_sync_threads(void) >>> * current's path will hold a reference. (This also >>> * allows a put before the assignment.) >>> */ >>> - put_seccomp_filter(thread); >>> + put_seccomp_filter(thread->seccomp.filter); >>> smp_store_release(&thread->seccomp.filter, >>> caller->seccomp.filter); >>> >>> @@ -476,10 +478,11 @@ static inline void seccomp_filter_free(struct s= eccomp_filter *filter) >>> } >>> } >>> >>> -/* put_seccomp_filter - decrements the ref count of tsk->seccomp.fil= ter */ >>> -void put_seccomp_filter(struct task_struct *tsk) >>> +/* put_seccomp_filter - decrements the ref count of a filter */ >>> +static void put_seccomp_filter(struct seccomp_filter *filter) >>> { >>> - struct seccomp_filter *orig =3D tsk->seccomp.filter; >>> + struct seccomp_filter *orig =3D filter; >>> + >>> /* Clean up single-reference branches iteratively. */ >>> while (orig && atomic_dec_and_test(&orig->usage)) { >>> struct seccomp_filter *freeme =3D orig; >>> @@ -488,6 +491,11 @@ void put_seccomp_filter(struct task_struct *tsk)= >>> } >>> } >>> >>> +void put_seccomp(struct task_struct *tsk) >>> +{ >>> + put_seccomp_filter(tsk->seccomp.filter); >>> +} >>> + >>> static void seccomp_init_siginfo(siginfo_t *info, int syscall, int r= eason) >>> { >>> memset(info, 0, sizeof(*info)); >>> @@ -914,7 +922,7 @@ long seccomp_get_filter(struct task_struct *task,= unsigned long filter_off, >>> if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fpr= og))) >>> ret =3D -EFAULT; >>> >>> - put_seccomp_filter(task); >>> + put_seccomp_filter(task->seccomp.filter); >>> return ret; >> >> I don't like that the arguments to get_seccomp_filter() and >> put_seccomp_filter() are now different. I think they should match for >> readability. >=20 > OK, I can do that. >=20 Kees, can I send this as a separate patch? --2kpFJb6D2qvUV0dV2W5akJuaRugWD6OBW-- --PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEUysCyY8er9Axt7hqIt7+33O9apUFAlj34hwACgkQIt7+33O9 apUqiAf/W6XDRtopGxrSLPUSvfwzYK1ZxJ+POYZ170a5F8MW8I6jQ7XSYi1Ssezu d+8nbA01nGXh7uEx19bErJZcksIXVSLqTQbmzdgQ9xJir8XMydB38PEQ1R0GHHfB S/5hOKEeyHQtJMGdPfZ1kwSuzt428vO04G0OUaKDNZxBkNzOO9FIS9Cj5soF8CU/ N4dYq+fZRtDYIhb9ybFkvEn5n/IewOHC2UX6Ox7qu8Xi2+tKGzwEDngvUrlDAHY3 B2vAlUr3byi4keNFLgxb1paHDferHAjvjJTAMHTXNZYjapioqMUDm2QGb9QAWYJ8 yKMerLmmLoqzZ1hi+RxXKug28tziOw== =heH2 -----END PGP SIGNATURE----- --PWs0Q1J0K2Ec48sLjhlCcfWTpdQ6uAHjE--