[PATCH 23/23] scsi: remove unnecessary unlikely()

2018-08-30 Thread Igor Stoppa
BUG_ON() already contains an unlikely(), there is no need for another one. Signed-off-by: Igor Stoppa Cc: "Martin K. Petersen" Cc: "James E.J. Bottomley" --- drivers/scsi/scsi_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_

[PATCH 16/23] lvm: device mapper: remove unnecessary unlikely()

2018-08-30 Thread Igor Stoppa
WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another. Signed-off-by: Igor Stoppa Cc: Joe Thornber Cc: Alasdair Kergon --- drivers/md/dm-cache-policy-smq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-cache-policy-smq.c b

[PATCH 09/23] cpufreq: remove unnecessary unlikely()

2018-08-30 Thread Igor Stoppa
WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another. Signed-off-by: Igor Stoppa Cc: "Rafael J. Wysocki" Cc: Srivatsa S. Bhat --- drivers/cpufreq/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpufreq/c

[PATCH] infiniband: nes: add unlikely() to assert()

2018-08-31 Thread Igor Stoppa
Typically the assert is expected to not fail. Signed-off-by: Igor Stoppa Acked-by: Doug Ledford Cc: Faisal Latif Cc: Chien Tung Cc: Roland Dreier Cc: Faisal Latif Cc: Jason Gunthorpe Cc: linux-r...@vger.kernel.org CC: linux-kernel@vger.kernel.org --- drivers/infiniband/hw/nes/nes.h | 2

[PATCH] mm: percpu: remove unnecessary unlikely()

2018-08-31 Thread Igor Stoppa
WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another. Signed-off-by: Igor Stoppa Acked-by: Dennis Zhou Cc: Tejun Heo Cc: zijun_hu Cc: Christoph Lameter Cc: linux...@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/percpu.c | 2 +- 1 file changed, 1

[PATCH] infiniband: scsi: remove unnecessary unlikely()

2018-08-31 Thread Igor Stoppa
WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another. Signed-off-by: Igor Stoppa Reviewed-by: Bart Van Assche Cc: linux-r...@vger.kernel.org (open list:SCSI RDMA PROTOCOL (SRP) TARGET) Cc: linux-kernel@vger.kernel.org (open list) --- drivers/infiniband/ulp

Re: [PATCH 00/23] Make use of unlikely() more consistently.

2018-08-31 Thread Igor Stoppa
On 31/08/18 17:09, Arnd Bergmann wrote: [...] #define assert(condition) ... if (unlikely(!(condition))) error_action() ... There is a potential that this introduces false-postive -Wmaybe-uninitialized warnings when CONFIG_PROFILE_ANNOTATED_BRANCHES is set, since

[PATCH] selftest: vm: add unlikely() to BUG_ON()

2018-08-31 Thread Igor Stoppa
BUG_ON() is unlikely() to BUG() For unlikely(), borrow the definition from tools/include/linux/compiler.h Signed-off-by: Igor Stoppa Cc: Dmitry Safonov Cc: Shuah Khan Cc: linux-kselft...@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- tools/testing/selftests/vm/map_populate.c | 6

Re: [PATCH 05/23] selftest: vm: add unlikely() to BUG_ON()

2018-08-31 Thread Igor Stoppa
Hi Dmitry, On 31/08/18 02:04, Dmitry Safonov wrote: Probably, the one from "tools/include/linux/compiler.h" can be used in tools directory. Thank you for the advice. It seems to work now. -- igor

[RFC PATCH v4 00/12] hardening: statically allocated protected memory

2019-02-11 Thread Igor Stoppa
() to WARN() * turn verification of written data into debugging option * wr_rcu_assign_pointer() as special case of wr_assign() * example with protection of ima_policy_flags * documentation Igor Stoppa (12): __wr_after_init: Core and default arch __wr_after_init: x86_64: memset_user() __wr

[RFC PATCH v4 10/12] __wr_after_init: rodata_test: test __wr_after_init

2019-02-11 Thread Igor Stoppa
The write protection of the __wr_after_init data can be verified with the same methodology used for const data. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC

[RFC PATCH v4 05/12] __wr_after_init: arm64: memset_user()

2019-02-11 Thread Igor Stoppa
code to privide a memset_user() function, which is currently missing. clear_user() is the base for memset_user() Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC

[RFC PATCH v4 02/12] __wr_after_init: x86_64: memset_user()

2019-02-11 Thread Igor Stoppa
code to privide a memset_user() function, which is currently missing. clear_user() is the base for memset_user() Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC

[RFC PATCH v4 06/12] __wr_after_init: arm64: enable

2019-02-11 Thread Igor Stoppa
Set ARCH_HAS_PRMEM to Y for arm64 Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC: linux-integr...@vger.kernel.org CC: kernel-harden

[RFC PATCH v4 01/12] __wr_after_init: Core and default arch

2019-02-11 Thread Igor Stoppa
. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC: linux-integr...@vger.kernel.org CC: kernel-harden...@lists.openwall.com CC: linux

[RFC PATCH v4 04/12] __wr_after_init: x86_64: enable

2019-02-11 Thread Igor Stoppa
Set ARCH_HAS_PRMEM to Y for x86_64 Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC: linux-integr...@vger.kernel.org CC: kernel-harden

[RFC PATCH v4 07/12] __wr_after_init: Documentation: self-protection

2019-02-11 Thread Igor Stoppa
Update the self-protection documentation, to mention also the use of the __wr_after_init attribute. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed

[RFC PATCH v4 09/12] __wr_after_init: rodata_test: refactor tests

2019-02-11 Thread Igor Stoppa
Refactor the test cases, in preparation for using them also for testing __wr_after_init memory, when available. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC

[RFC PATCH v4 12/12] IMA: turn ima_policy_flags into __wr_after_init

2019-02-11 Thread Igor Stoppa
. __wr_after_init can still provide some protection, at least against simple memory overwrite attacks Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman

[RFC PATCH v4 11/12] __wr_after_init: test write rare functionality

2019-02-11 Thread Igor Stoppa
Set of test cases meant to confirm that the write rare functionality works as expected. It can be optionally compiled as module. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago

[RFC PATCH v4 03/12] __wr_after_init: x86_64: randomize mapping offset

2019-02-11 Thread Igor Stoppa
. This is accomplished by providing arch-specific version of the function __init_wr_base() Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC: linux

[RFC PATCH v4 08/12] __wr_after_init: lkdtm test

2019-02-11 Thread Igor Stoppa
Verify that trying to modify a variable with the __wr_after_init attribute will cause a crash. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC

Re: [RFC PATCH v4 00/12] hardening: statically allocated protected memory

2019-02-11 Thread Igor Stoppa
On 12/02/2019 02:09, Kees Cook wrote: On Mon, Feb 11, 2019 at 3:28 PM Igor Stoppa wrote: [...] Patch-set implementing write-rare memory protection for statically allocated data. It seems like this could be expanded in the future to cover dynamic memory too (i.e. just a separate base

Re: [RFC PATCH v4 00/12] hardening: statically allocated protected memory

2019-02-11 Thread Igor Stoppa
On 12/02/2019 03:26, Kees Cook wrote: On Mon, Feb 11, 2019 at 5:08 PM igor.sto...@gmail.com wrote: On Tue, 12 Feb 2019, 4.47 Kees Cook On Mon, Feb 11, 2019 at 4:37 PM Igor Stoppa wrote: On 12/02/2019 02:09, Kees Cook wrote: On Mon, Feb 11, 2019 at 3:28 PM Igor Stoppa wrote

Re: [RFC PATCH v4 01/12] __wr_after_init: Core and default arch

2019-02-11 Thread Igor Stoppa
On 12/02/2019 04:39, Matthew Wilcox wrote: On Tue, Feb 12, 2019 at 01:27:38AM +0200, Igor Stoppa wrote: +#ifndef CONFIG_PRMEM [...] +#else + +#include It's a mistake to do conditional includes like this. That way you see include loops with some configs and not others. Our headers

Re: [RFC PATCH v5 03/12] __wr_after_init: Core and default arch

2019-02-16 Thread Igor Stoppa
On 15/02/2019 10:57, Peter Zijlstra wrote: Where are the comments and Changelog notes ? How is an arch maintainer to be aware of this requirement when adding support for his/her arch? Yes, it will be fixed in the next revision. I've added comment to the core wr_assign function and also to

[PATCH 3/6] rodata_test: refactor tests

2018-12-04 Thread Igor Stoppa
Refactor the test cases, in preparation for using them also for testing __wr_after_init memory. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: linux-integr...@vger.kernel.org CC: kernel-harden

[RFC v1 PATCH 0/6] hardening: statically allocated protected memory

2018-12-04 Thread Igor Stoppa
://www.openwall.com/lists/kernel-hardening/2018/11/22/8 [2] https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1793199.html [3] https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1810245.html Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra

[PATCH 1/6] __wr_after_init: linker section and label

2018-12-04 Thread Igor Stoppa
Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: linux-integr...@vger.kernel.org CC: kernel-harden...@lists.openwall.com CC: linux...@kvack.org CC: linux-kernel@vger.kernel.org --- include/asm-generic/vml

[PATCH 2/6] __wr_after_init: write rare for static allocation

2018-12-04 Thread Igor Stoppa
, in a preemptible system, however the amount of data to be altered is likely to be far smaller than a page. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: linux-integr...@vger.kernel.org CC: kernel-harden

[PATCH 4/6] rodata_test: add verification for __wr_after_init

2018-12-04 Thread Igor Stoppa
The write protection of the __wr_after_init data can be verified with the same methodology used for const data. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: linux-integr...@vger.kernel.org CC: kernel

[PATCH 5/6] __wr_after_init: test write rare functionality

2018-12-04 Thread Igor Stoppa
Set of test cases meant to confirm that the write rare functionality works as expected. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: linux-integr...@vger.kernel.org CC: kernel-harden

[PATCH 6/6] __wr_after_init: lkdtm test

2018-12-04 Thread Igor Stoppa
Verify that trying to modify a variable with the __wr_after_init modifier wil lcause a crash. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: linux-integr...@vger.kernel.org CC: kernel-harden

Re: [PATCH 04/12] __wr_after_init: x86_64: __wr_op

2018-12-20 Thread Igor Stoppa
On 19/12/2018 23:33, Igor Stoppa wrote: + if (WARN_ONCE(op >= WR_OPS_NUMBER, "Invalid WR operation.") || + WARN_ONCE(!is_wr_after_init(dst, len), "Invalid WR range.")) + return (void *)dst; + + offset = dst - (unsigned long)&__star

Re: [PATCH 04/12] __wr_after_init: x86_64: __wr_op

2018-12-20 Thread Igor Stoppa
Hi, On 20/12/2018 19:20, Thiago Jung Bauermann wrote: Hello Igor, +/* + * The following two variables are statically allocated by the linker + * script at the the boundaries of the memory region (rounded up to + * multiples of PAGE_SIZE) reserved for __wr_after_init. + */ +extern long

Re: [PATCH 11/12] IMA: turn ima_policy_flags into __wr_after_init

2018-12-20 Thread Igor Stoppa
Hi, On 20/12/2018 19:30, Thiago Jung Bauermann wrote: Hello Igor, Igor Stoppa writes: diff --git a/security/integrity/ima/ima_init.c b/security/integrity/ima/ima_init.c index 59d834219cd6..5f4e13e671bf 100644 --- a/security/integrity/ima/ima_init.c +++ b/security/integrity/ima/ima_init.c

Re: [PATCH 04/12] __wr_after_init: x86_64: __wr_op

2018-12-20 Thread Igor Stoppa
On 20/12/2018 20:49, Matthew Wilcox wrote: I think you're causing yourself more headaches by implementing this "op" function. I probably misinterpreted the initial criticism on my first patchset, about duplication. Somehow, I'm still thinking to the endgame of having higher-level

Re: [PATCH 04/12] __wr_after_init: x86_64: __wr_op

2018-12-21 Thread Igor Stoppa
On 21/12/2018 19:23, Andy Lutomirski wrote: On Thu, Dec 20, 2018 at 11:19 AM Igor Stoppa wrote: On 20/12/2018 20:49, Matthew Wilcox wrote: I think you're causing yourself more headaches by implementing this "op" function. I probably misinterpreted the initial criticism o

[PATCH 05/12] __wr_after_init: x86_64: __wr_op

2018-12-21 Thread Igor Stoppa
, in a preemptible system, however the amount of data to be altered is likely to be far smaller than a page. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed

[PATCH 01/12] x86_64: memset_user()

2018-12-21 Thread Igor Stoppa
Create x86_64 specific version of memset for user space, based on clear_user(). This will be used for implementing wr_memset() in the __wr_after_init scenario, where write-rare variables have an alternate mapping for writing. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC

[PATCH 03/12] __wr_after_init: generic functionality

2018-12-21 Thread Igor Stoppa
of memset() - wr_memcpy(): write rare counterpart of memcpy() - wr_assign(): write rare counterpart of the assignment ('=') operator - wr_rcu_assign_pointer(): write rare counterpart of rcu_assign_pointer() Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter

[PATCH 08/12] rodata_test: refactor tests

2018-12-21 Thread Igor Stoppa
Refactor the test cases, in preparation for using them also for testing __wr_after_init memory, when available. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC

[PATCH 06/12] __wr_after_init: Documentation: self-protection

2018-12-21 Thread Igor Stoppa
Update the self-protection documentation, to mention also the use of the __wr_after_init attribute. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed

[PATCH 02/12] __wr_after_init: linker section and label

2018-12-21 Thread Igor Stoppa
o activate both section and label, the arch must set CONFIG_ARCH_HAS_PRMEM Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC: linux-integr...@vger.

[PATCH 12/12] x86_64: __clear_user as case of __memset_user

2018-12-21 Thread Igor Stoppa
To avoid code duplication, re-use __memset_user(), when clearing user-space memory. The overhead should be minimal (2 extra register assignments) and outside of the writing loop. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees

[PATCH 09/12] rodata_test: add verification for __wr_after_init

2018-12-21 Thread Igor Stoppa
The write protection of the __wr_after_init data can be verified with the same methodology used for const data. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC

[PATCH 07/12] __wr_after_init: lkdtm test

2018-12-21 Thread Igor Stoppa
Verify that trying to modify a variable with the __wr_after_init attribute will cause a crash. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC

[PATCH 10/12] __wr_after_init: test write rare functionality

2018-12-21 Thread Igor Stoppa
Set of test cases meant to confirm that the write rare functionality works as expected. It can be optionally compiled as module. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago

[PATCH 11/12] IMA: turn ima_policy_flags into __wr_after_init

2018-12-21 Thread Igor Stoppa
. __wr_after_init can still provide some protection, at least against simple memory overwrite attacks Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman

[PATCH 04/12] __wr_after_init: debug writes

2018-12-21 Thread Igor Stoppa
After each write operation, confirm that it was successful, otherwise generate a warning. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC

Re: [PATCH 01/12] x86_64: memset_user()

2018-12-21 Thread Igor Stoppa
On 21/12/2018 20:25, Matthew Wilcox wrote: On Fri, Dec 21, 2018 at 08:14:12PM +0200, Igor Stoppa wrote: +unsigned long __memset_user(void __user *addr, int c, unsigned long size) +{ + long __d0; + unsigned long pattern = 0; + int i; + + for (i = 0; i < 8

Re: [PATCH 03/12] __wr_after_init: generic functionality

2018-12-21 Thread Igor Stoppa
On 21/12/2018 20:41, Matthew Wilcox wrote: On Fri, Dec 21, 2018 at 08:14:14PM +0200, Igor Stoppa wrote: +static inline int memtst(void *p, int c, __kernel_size_t len) I don't understand why you're verifying that writes actually happen in production code. Sure, write lib/test_wrmem.c

Re: [PATCH 03/12] __wr_after_init: generic functionality

2018-12-21 Thread Igor Stoppa
On 21/12/2018 21:43, Matthew Wilcox wrote: On Fri, Dec 21, 2018 at 09:07:54PM +0200, Igor Stoppa wrote: On 21/12/2018 20:41, Matthew Wilcox wrote: On Fri, Dec 21, 2018 at 08:14:14PM +0200, Igor Stoppa wrote: +static inline int memtst(void *p, int c, __kernel_size_t len) I don't

Re: [PATCH 03/12] __wr_after_init: generic header

2018-12-22 Thread Igor Stoppa
On 21/12/2018 21:45, Matthew Wilcox wrote: On Fri, Dec 21, 2018 at 11:38:16AM -0800, Nadav Amit wrote: On Dec 19, 2018, at 1:33 PM, Igor Stoppa wrote: +static inline void *wr_memset(void *p, int c, __kernel_size_t len) +{ + return __wr_op((unsigned long)p, (unsigned long)c, len

Re: [PATCH 2/6] __wr_after_init: write rare for static allocation

2018-12-09 Thread Igor Stoppa
On 06/12/2018 01:13, Andy Lutomirski wrote: + kasan_disable_current(); + if (op == WR_MEMCPY) + memcpy((void *)wr_poking_addr, (void *)src, len); + else if (op == WR_MEMSET) + memset((u8 *)wr_poking_addr, (u8)src, len); + else if (op ==

Re: [PATCH 2/6] __wr_after_init: write rare for static allocation

2018-12-09 Thread Igor Stoppa
On 06/12/2018 06:44, Matthew Wilcox wrote: On Tue, Dec 04, 2018 at 02:18:01PM +0200, Igor Stoppa wrote: +void *__wr_op(unsigned long dst, unsigned long src, __kernel_size_t len, + enum wr_op_type op) +{ + temporary_mm_state_t prev; + unsigned long flags

Re: [PATCH 2/6] __wr_after_init: write rare for static allocation

2018-12-09 Thread Igor Stoppa
On 06/12/2018 11:44, Peter Zijlstra wrote: On Wed, Dec 05, 2018 at 03:13:56PM -0800, Andy Lutomirski wrote: + if (op == WR_MEMCPY) + memcpy((void *)wr_poking_addr, (void *)src, len); + else if (op == WR_MEMSET) + memset((u8 *)wr_poking_addr, (u8)src,

Re: [PATCH] seccomp: remove unnecessary unlikely()

2018-09-05 Thread Igor Stoppa
On 06/09/18 01:23, Kees Cook wrote: Should I take this, or is it part of your series going somewhere else? It turned out it doesn't really work to have a generic series against 20 trees :-/ I'm submitting them individually to each subsystem. So this one is just for security. -- thanks,

Re: [PATCH] infiniband: nes: add unlikely() to assert()

2018-09-07 Thread Igor Stoppa
On 07/09/18 18:13, Doug Ledford wrote: This patch was part of a larger series on lkml. In that context, I acked it so that the series could be applied by whomever took it (it didn't belong on rdma-list as a series since only one patch out of some large number touched rdma files). Now it is

[PATCH] cpufreq: remove unnecessary unlikely()

2018-09-07 Thread Igor Stoppa
WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another. Signed-off-by: Igor Stoppa Cc: Srivatsa S. Bhat Cc: "Rafael J. Wysocki" Cc: linux...@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/cpufreq/cpufreq.c | 2 +- 1 file changed, 1

[PATCH] filesystems: remove unnecessary unlikely()

2018-09-07 Thread Igor Stoppa
WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another. Signed-off-by: Igor Stoppa Cc: Alexander Viro Cc: linux-fsde...@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- fs/open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/open.c

[PATCH] usb: octeon-hcd: remove unnecessary unlikely()

2018-09-07 Thread Igor Stoppa
WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another. Signed-off-by: Igor Stoppa Cc: Aaro Koskinen Cc: Greg Kroah-Hartman Cc: de...@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org --- drivers/staging/octeon-usb/octeon-hcd.c | 2 +- 1 file changed, 1

[PATCH] mips: bug: add unlikely() to BUG_ON()

2018-09-07 Thread Igor Stoppa
Add a hint to the compiler that probably it won't be necessary to BUG() Signed-off-by: Igor Stoppa Cc: David Daney Cc: Ralf Baechle Cc: Paul Burton Cc: James Hogan Cc: linux-m...@linux-mips.org Cc: linux-kernel@vger.kernel.org --- arch/mips/include/asm/bug.h | 2 +- 1 file changed, 1

[RESEND PATCH] mm: percpu: remove unnecessary unlikely()

2018-09-07 Thread Igor Stoppa
WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another. Signed-off-by: Igor Stoppa Acked-by: Dennis Zhou Cc: Tejun Heo Cc: zijun_hu Cc: Christoph Lameter Cc: linux...@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/percpu.c | 2 +- 1 file changed, 1

[PATCH] asm-generic: bug: add unlikely() to BUG_ON()

2018-09-07 Thread Igor Stoppa
Add a hint to the compiler. If BUG_ON() is used instead of BUG(), it means that probably the preferred outcome is to not BUG(). The optimization is disabled, in case CONFIG_PROFILE_ANNOTATED_BRANCHES is turned on. Signed-off-by: Igor Stoppa Cc: Arnd Bergmann Cc: linux-a...@vger.kernel.org Cc

Re: [RESEND PATCH] mm: percpu: remove unnecessary unlikely()

2018-09-07 Thread Igor Stoppa
On 07/09/18 21:39, Dennis Zhou wrote: Sorry for the delay. I'll be taking over the percpu tree and am in the process of getting a tree. I'm still keeping track of this and will take it for the next release. ok, np! -- thank you, igor

Re: [PATCH] asm-generic: bug: add unlikely() to BUG_ON()

2018-09-07 Thread Igor Stoppa
On 07/09/18 23:41, Arnd Bergmann wrote: Could you add a comment about -Wmaybe-uninitialized next to the definition? Otherwise that is easily lost. Also, I see that the file has two separate definitions of BUG_ON(), and the other one does have an unlikely() in it already. Can you change both

[PATCH v2] asm-generic: bug: unify hints for BUG_ON()

2018-09-07 Thread Igor Stoppa
-uninitialized. Signed-off-by: Igor Stoppa Cc: Arnd Bergmann Cc: linux-a...@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- include/asm-generic/bug.h | 8 1 file changed, 8 insertions(+) diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index 20561a60db9c

Re: [PATCH] mips: bug: add unlikely() to BUG_ON()

2018-09-10 Thread Igor Stoppa
Hi Paul, On 08/09/18 01:02, Paul Burton wrote: I'm not sure this will actually do anything. __BUG_ON() doesn't use the value of its condition argument for regular control flow unless it's compile-time constant anyway, in which case unlikely() should be redundant because the compiler knows the

Re: [PATCH] infiniband: nes: add unlikely() to assert()

2018-09-05 Thread Igor Stoppa
On 05/09/18 09:01, Leon Romanovsky wrote: On Fri, Aug 31, 2018 at 10:24:18PM +0300, Igor Stoppa wrote: Typically the assert is expected to not fail. This whole assert can be removed. ok Signed-off-by: Igor Stoppa Acked-by: Doug Ledford Most probably that I missed discussion

[PATCH] seccomp: remove unnecessary unlikely()

2018-09-05 Thread Igor Stoppa
WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another. Signed-off-by: Igor Stoppa Acked-by: Kees Cook Cc: linux-security-mod...@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- kernel/seccomp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions

Re: [PATCH v2] asm-generic: bug: unify hints for BUG_ON()

2018-09-10 Thread Igor Stoppa
On 10/09/18 15:16, Arnd Bergmann wrote: Acked-by: Arnd Bergmann I assume this will be included in a longer patch series rather than going through my asm-generic tree, right? sadly, no: this patch is just for the asm-generic tree I tried with the longer patch series, but it didn't work

[PATCH v2] asm-generic: bug: unify hints for BUG_ON()

2018-09-11 Thread Igor Stoppa
-uninitialized. Signed-off-by: Igor Stoppa Acked-by: Arnd Bergmann Cc: linux-a...@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- include/asm-generic/bug.h | 8 1 file changed, 8 insertions(+) diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index 20561a60db9c

Re: [PATCH 10/17] prmem: documentation

2018-10-31 Thread Igor Stoppa
On 01/11/2018 01:19, Andy Lutomirski wrote: ISTM you don't need that atomic operation -- you could take a spinlock and then just add one directly to the variable. It was my intention to provide a 1:1 conversion of existing code, as it should be easier to verify the correctness of the

[PATCH 02/17] prmem: write rare for static allocation

2018-10-23 Thread Igor Stoppa
started, and there is not alternate, writable mapping to exploit. Signed-off-by: Igor Stoppa CC: Michal Hocko CC: Vlastimil Babka CC: "Kirill A. Shutemov" CC: Andrew Morton CC: Pavel Tatashin CC: linux...@kvack.org CC: linux-kernel@vger.kernel.org --- MAINTAINERS | 7 +

[PATCH 03/17] prmem: vmalloc support for dynamic allocation

2018-10-23 Thread Igor Stoppa
doubly linked list for tracking the chain of vmap_areas, only one pointer is spent for this purpose, in a single linked list, while the other is used to provide a direct connection to the parent pool. Signed-off-by: Igor Stoppa CC: Michal Hocko CC: Andrew Morton CC: Chintan Pandya CC: Joe Perches

[PATCH 05/17] prmem: shorthands for write rare on common types

2018-10-23 Thread Igor Stoppa
Wrappers around the basic write rare functionality, addressing several common data types found in the kernel, allowing to specify the new values through immediates, like constants and defines. Note: The list is not complete and could be expanded. Signed-off-by: Igor Stoppa CC: Michal Hocko CC

[PATCH 07/17] prmem: lkdtm tests for memory protection

2018-10-23 Thread Igor Stoppa
-off-by: Igor Stoppa CC: Kees Cook CC: Greg Kroah-Hartman CC: Arnd Bergmann CC: linux...@kvack.org CC: linux-kernel@vger.kernel.org --- drivers/misc/lkdtm/core.c | 13 ++ drivers/misc/lkdtm/lkdtm.h | 13 ++ drivers/misc/lkdtm/perms.c | 248 + 3 files changed

[PATCH 13/17] prmem: linked list: disable layout randomization

2018-10-23 Thread Igor Stoppa
. It shouldn't be anyway a big loss, in terms of security: with only two fields, there is a 50% chance of guessing correctly the layout. The randomization is disabled only when write rare is enabled. Signed-off-by: Igor Stoppa CC: Kees Cook CC: Greg Kroah-Hartman CC: Andrew Morton CC: Masahiro

[PATCH 17/17] prmem: ima: turn the measurements list write rare

2018-10-23 Thread Igor Stoppa
The measurement list is moved to write rare memory, including related data structures. Various boilerplate linux data structures and related functions are replaced by their write-rare counterpart. Signed-off-by: Igor Stoppa CC: Mimi Zohar CC: Dmitry Kasatkin CC: James Morris CC: "Se

[PATCH 16/17] prmem: pratomic-long

2018-10-23 Thread Igor Stoppa
Minimalistic functionality for having the write rare version of atomic_long_t data. Signed-off-by: Igor Stoppa CC: Will Deacon CC: Peter Zijlstra CC: Boqun Feng CC: Arnd Bergmann CC: linux-a...@vger.kernel.org CC: linux-kernel@vger.kernel.org --- MAINTAINERS | 1

[PATCH 15/17] prmem: test cases for prlist and prhlist

2018-10-23 Thread Igor Stoppa
These test cases focus on the basic operations required to operate both prlist and prhlist data, in particular creating, growing, shrinking, destroying. They can also be useful as reference for practical use of write-rare lists. Signed-off-by: Igor Stoppa CC: Kate Stewart CC: Philippe

[PATCH 08/17] prmem: struct page: track vmap_area

2018-10-23 Thread Igor Stoppa
the direct reference from struct page. Signed-off-by: Igor Stoppa CC: Michal Hocko CC: Vlastimil Babka CC: "Kirill A. Shutemov" CC: Andrew Morton CC: Pavel Tatashin CC: linux...@kvack.org CC: linux-kernel@vger.kernel.org --- include/linux/mm_types.h | 25 ++--

[PATCH 12/17] prmem: linked list: set alignment

2018-10-23 Thread Igor Stoppa
-off-by: Igor Stoppa CC: Greg Kroah-Hartman CC: Andrew Morton CC: Masahiro Yamada CC: Alexey Dobriyan CC: Pekka Enberg CC: "Paul E. McKenney" CC: Lihao Liang CC: linux-kernel@vger.kernel.org --- include/linux/types.h | 20 1 file changed, 16 insertions(+), 4

[PATCH 14/17] prmem: llist, hlist, both plain and rcu

2018-10-23 Thread Igor Stoppa
to functions that can perform write rare. Since lists are one of the most commonly used data structures in kernel, they are a the first candidate for receiving write rare extensions. This patch implements basic functionality for altering said lists. Signed-off-by: Igor Stoppa CC: Thomas Gleixner CC

[PATCH 09/17] prmem: hardened usercopy

2018-10-23 Thread Igor Stoppa
Prevent leaks of protected memory to userspace. The protection from overwrited from userspace is already available, once the memory is write protected. Signed-off-by: Igor Stoppa CC: Kees Cook CC: Chris von Recklinghausen CC: linux...@kvack.org CC: linux-kernel@vger.kernel.org --- include

[PATCH 11/17] prmem: llist: use designated initializer

2018-10-23 Thread Igor Stoppa
Using a list_head in an unnamed union poses a problem with the current implementation of the initializer, since it doesn't specify the names of the fields it is initializing. This patch makes it use designated initializers. Signed-off-by: Igor Stoppa CC: Kate Stewart CC: "David S. Miller

[PATCH 06/17] prmem: test cases for memory protection

2018-10-23 Thread Igor Stoppa
The test cases verify the various interfaces offered by both prmem.h and prmemextra.h The tests avoid triggering crashes, by not performing actions that would be treated as illegal. That part is handled in the lkdtm patch. Signed-off-by: Igor Stoppa CC: Michal Hocko CC: Vlastimil Babka CC

[PATCH 01/17] prmem: linker section for static write rare

2018-10-23 Thread Igor Stoppa
he current write-rare mechanism works only on x86_64 and not arm64, due to arm64 mappings. Signed-off-by: Igor Stoppa CC: Arnd Bergmann CC: Thomas Gleixner CC: Kate Stewart CC: Greg Kroah-Hartman CC: Philippe Ombredanne CC: linux-a...@vger.kernel.org CC: linux-kernel@vger.kernel.org --- include/a

[PATCH 04/17] prmem: dynamic allocation

2018-10-23 Thread Igor Stoppa
the memory that was obtained from it is automatically freed. This is the only way to release protected memory. Signed-off-by: Igor Stoppa CC: Michal Hocko CC: Vlastimil Babka CC: "Kirill A. Shutemov" CC: Andrew Morton CC: Pavel Tatashin CC: linux...@kvack.org CC: linux-kernel@vger.kernel.or

Re: [PATCH 14/17] prmem: llist, hlist, both plain and rcu

2018-10-24 Thread Igor Stoppa
On 24/10/18 14:37, Mathieu Desnoyers wrote: I could not find a description of the overall context of this patch (e.g. a patch 00/17 ?) that would explain the attack vectors this aims to protect against. Apologies, I have to admit I was a bit baffled about what to do: the patchset spans

Re: [PATCH 06/17] prmem: test cases for memory protection

2018-10-24 Thread Igor Stoppa
Hi, On 24/10/18 06:27, Randy Dunlap wrote: a. It seems backwards (or upside down) to have a test case select a feature (PRMEM) instead of depending on that feature. b. Since PRMEM depends on MMU (in patch 04/17), the "select" here could try to enabled PRMEM even when MMU is not enabled.

Re: [PATCH 14/17] prmem: llist, hlist, both plain and rcu

2018-10-24 Thread Igor Stoppa
On 24/10/2018 17:56, Tycho Andersen wrote: On Wed, Oct 24, 2018 at 05:03:01PM +0300, Igor Stoppa wrote: On 24/10/18 14:37, Mathieu Desnoyers wrote: Also, is it the right approach to duplicate existing APIs, or should we rather hook into page fault handlers and let the kernel do those "s

Re: [PATCH 08/17] prmem: struct page: track vmap_area

2018-10-24 Thread Igor Stoppa
On 24/10/2018 06:12, Matthew Wilcox wrote: On Wed, Oct 24, 2018 at 12:34:55AM +0300, Igor Stoppa wrote: The connection between each page and its vmap_area avoids more expensive searches through the btree of vmap_areas. Typo -- it's an rbtree. ack +++ b/include/linux/mm_types.h

CHECKPATCH: strange warning on alignment modifier

2018-10-08 Thread Igor Stoppa
Hi, I have the following fragment of code: +struct my_struct { + atomic_long_t l __aligned(sizeof(atomic_long_t)); +} __aligned(sizeof(atomic_long_t)); triggering this warning, when fed to checkpatch.pl: WARNING: function definition argument 'atomic_long_t' should also have an

Re: [PATCH v2] LSM: Convert security_hook_heads into explicit array of struct list_head

2017-05-31 Thread Igor Stoppa
On 30/05/17 13:32, James Morris wrote: > This seems like pointless churn in security-critical code in anticipation > of features which are still in development and may not be adopted. > > Is there a compelling reason to merge this now? (And I don't mean worrying > about non-existent

Re: [PATCH 1/1] Sealable memory support

2017-05-31 Thread Igor Stoppa
On 28/05/17 21:23, Kees Cook wrote: > On Wed, May 24, 2017 at 10:45 AM, Igor Stoppa wrote: [...] >> If the CPU1 were to forcibly halt anything that can race with it, then >> it would be sure that there was no interference. > > Correct. This is actually what ARM does fo

Re: RFC v2: post-init-read-only protection for data allocated dynamically

2017-05-04 Thread Igor Stoppa
On 04/05/17 14:21, Michal Hocko wrote: > On Wed 03-05-17 15:06:36, Igor Stoppa wrote: [...] >> * In most, if not all, the cases that could be enhanced, the code will >> be calling kmalloc/vmalloc, indicating GFP_KERNEL as the desired type of >> memory. > > Ho

Re: RFC v2: post-init-read-only protection for data allocated dynamically

2017-05-04 Thread Igor Stoppa
On 04/05/17 16:11, Michal Hocko wrote: > On Thu 04-05-17 15:14:10, Igor Stoppa wrote: > I believe that this is a fundamental question. Sealing sounds useful > for after-boot usecases as well and it would change the approach > considerably. Coming up with an ad-hoc solution for the b

Re: RFC v2: post-init-read-only protection for data allocated dynamically

2017-05-05 Thread Igor Stoppa
On 04/05/17 17:30, Dave Hansen wrote: > On 05/04/2017 01:17 AM, Igor Stoppa wrote: >> Or, let me put it differently: my goal is to not fracture more pages >> than needed. >> It will probably require some profiling to figure out what is the >> ballpark of the memory f

<    3   4   5   6   7   8   9   >