incoming
Subsystems (68)
Andrew Morton
maintainerPATCH 96/127 exec: simplify the copy_strings_kernel calling convention
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: exec: simplify the copy_strings_kernel calling convention
copy_strings_kernel is always used with a single argument, adjust the calling convention to that.
---
fs/binfmt_em86.c | 6 +++--- fs/binfmt_misc.c | 4 ++-- fs/binfmt_script.c | 6 +++--- fs/exec.c | 13 ++++++------- include/linux/binfmts.h | 3 +-- 5 files changed, 15 insertions(+), 17 deletions(-)
fs/binfmt_em86.c renamed from fs/binfmt_em86.c~exec-simplify-the-copy_strings_kernel-calling-convention +3 -3
@@ -68,15 +68,15 @@ static int load_em86(struct linux_binprm* user environment and arguments are stored. */ remove_arg_zero (bprm); - retval =copy_strings_kernel (1 , &bprm->filename, bprm); + retval =copy_string_kernel (bprm->filename, bprm);if (retval <0 )return retval; bprm->argc++;if (i_arg) { - retval =copy_strings_kernel (1 , &i_arg, bprm); + retval =copy_string_kernel (i_arg, bprm);if (retval <0 )return retval; bprm->argc++; } - retval =copy_strings_kernel (1 , &i_name, bprm); + retval =copy_string_kernel (i_name, bprm);if (retval <0 )return retval; bprm->argc++;
fs/binfmt_misc.c renamed from fs/binfmt_misc.c~exec-simplify-the-copy_strings_kernel-calling-convention +2 -2
@@ -190,13 +190,13 @@ static int load_misc_binary(struct linux bprm->file =NULL ; }/* make argv[1] be the path to the binary */ - retval =copy_strings_kernel (1 , &bprm->interp, bprm); + retval =copy_string_kernel (bprm->interp, bprm);if (retval <0 ) goto error; bprm->argc++;/* add the interp as argv[0] */ - retval =copy_strings_kernel (1 , &fmt->interpreter, bprm); + retval =copy_string_kernel (fmt->interpreter, bprm);if (retval <0 ) goto error; bprm->argc++;
fs/binfmt_script.c renamed from fs/binfmt_script.c~exec-simplify-the-copy_strings_kernel-calling-convention +3 -3
@@ -117,17 +117,17 @@ static int load_script(struct linux_binp retval =remove_arg_zero (bprm);if (retval)return retval; - retval =copy_strings_kernel (1 , &bprm->interp, bprm); + retval =copy_string_kernel (bprm->interp, bprm);if (retval <0 )return retval; bprm->argc++;if (i_arg) { - retval =copy_strings_kernel (1 , &i_arg, bprm); + retval =copy_string_kernel (i_arg, bprm);if (retval <0 )return retval; bprm->argc++; } - retval =copy_strings_kernel (1 , &i_name, bprm); + retval =copy_string_kernel (i_name, bprm);if (retval)return retval; bprm->argc++;
fs/exec.c renamed from fs/exec.c~exec-simplify-the-copy_strings_kernel-calling-convention +6 -7
@@ -588,24 +588,23 @@ out: }/* -* Like copy_strings, but get argv and its values from kernel memory. +* Copy and argument/environment string from the kernel to the processes stack. */ -int copy_strings_kernel (int argc,const char *const *__argv, -struct linux_binprm *bprm) +int copy_string_kernel (const char *arg,struct linux_binprm *bprm) {int r;mm_segment_t oldfs =get_fs ();struct user_arg_ptr argv = { - .ptr.native = (const char __user *const __user *)__argv, + .ptr.native = (const char __user *const __user *)&arg, };set_fs (KERNEL_DS ); - r =copy_strings (argc, argv, bprm); + r =copy_strings (1 , argv, bprm);set_fs (oldfs);return r; } -EXPORT_SYMBOL (copy_strings_kernel); +EXPORT_SYMBOL (copy_string_kernel);#ifdef CONFIG_MMU
@@ -1865,7 +1864,7 @@ static int __do_execve_file(int fd, struif (retval <0 ) goto out; - retval =copy_strings_kernel (1 , &bprm->filename, bprm); + retval =copy_string_kernel (bprm->filename, bprm);if (retval <0 ) goto out;
include/linux/binfmts.h renamed from include/linux/binfmts.h~exec-simplify-the-copy_strings_kernel-calling-convention +1 -2
@@ -144,8 +144,7 @@ extern int setup_arg_pages(struct linux_extern int transfer_args_to_stack (struct linux_binprm *bprm,unsigned long *sp_location);extern int bprm_change_interp (const char *interp,struct linux_binprm *bprm); -extern int copy_strings_kernel (int argc,const char *const *argv, -struct linux_binprm *bprm); +int copy_string_kernel (const char *arg,struct linux_binprm *bprm);extern void install_exec_creds (struct linux_binprm *bprm);extern void set_binfmt (struct linux_binfmt *new);extern ssize_t read_code (struct file *,unsigned long ,loff_t ,size_t );
_
Andrew Morton
maintainerPATCH 97/127 exec: open code copy_string_kernel
In reply to Andrew MortonFrom: Christoph Hellwig <[email protected]>
Subject: exec: open code copy_string_kernel
Currently copy_string_kernel is just a wrapper around copy_strings that simplifies the calling conventions and uses set_fs to allow passing a kernel pointer. But due to the fact the we only need to handle a single kernel argument pointer, the logic can be sigificantly simplified while getting rid of the set_fs.
---
fs/exec.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-)
fs/exec.c renamed from fs/exec.c~exec-open-code-copy_string_kernel +35 -10
@@ -592,17 +592,42 @@ out:*/ int copy_string_kernel (const char *arg,struct linux_binprm *bprm) { -int r; -mm_segment_t oldfs =get_fs (); -struct user_arg_ptr argv = { - .ptr.native = (const char __user *const __user *)&arg, - }; - -set_fs (KERNEL_DS ); - r =copy_strings (1 , argv, bprm); -set_fs (oldfs); +int len =strnlen (arg,MAX_ARG_STRLEN ) +1 /* terminating NUL */ ; +unsigned long pos = bprm->p; -return r; +if (len ==0 ) +return -EFAULT ; +if (!valid_arg_len (bprm, len)) +return -E2BIG ; + +/* We're going to work our way backwards. */ + arg += len; + bprm->p -= len; +if (IS_ENABLED (CONFIG_MMU ) && bprm->p < bprm->argmin) +return -E2BIG ; + +while (len >0 ) { + unsigned int bytes_to_copy = min_t(unsigned int, len, +min_not_zero (offset_in_page (pos),PAGE_SIZE )); +struct page *page; +char *kaddr; + + pos -= bytes_to_copy; + arg -= bytes_to_copy; + len -= bytes_to_copy; + + page =get_arg_page (bprm, pos,1 ); +if (!page) +return -E2BIG ; + kaddr =kmap_atomic (page); +flush_arg_page (bprm, pos &PAGE_MASK , page); +memcpy (kaddr +offset_in_page (pos), arg, bytes_to_copy); +flush_kernel_dcache_page (page); +kunmap_atomic (kaddr); +put_arg_page (page); + } + +return 0 ; }EXPORT_SYMBOL (copy_string_kernel);
_
Andrew Morton
maintainerPATCH 98/127 rapidio: avoid data race between file operation callbacks and mport_cdev_add().
In reply to Andrew MortonFrom: Madhuparna Bhowmik <[email protected]>
Subject: rapidio: avoid data race between file operation callbacks and mport_cdev_add().
Fields of md(mport_dev) are set after cdev_device_add(). However, the file operation callbacks can be called after cdev_device_add() and therefore accesses to fields of md in the callbacks can race with the rest of the mport_cdev_add() function.
One such example is INIT_LIST_HEAD(&md->portwrites) in mport_cdev_add(), the list is initialised after cdev_device_add(). This can race with list_add_tail(&pw_filter->md_node,&md->portwrites) in rio_mport_add_pw_filter() which is called by unlocked_ioctl.
To avoid such data races use cdev_device_add() after initializing md.
Found by Linux Driver Verification project (linuxtesting.org).
---
drivers/rapidio/devices/rio_mport_cdev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/rapidio/devices/rio_mport_cdev.c renamed from drivers/rapidio/devices/rio_mport_cdev.c~rapidio-avoid-data-race-between-file-operation-callbacks-and-mport_cdev_add +7 -7
@@ -2384,13 +2384,6 @@ static struct mport_dev *mport_cdev_add(cdev_init (&md->cdev, &mport_fops); md->cdev.owner =THIS_MODULE ; - ret =cdev_device_add (&md->cdev, &md->dev); -if (ret) { -rmcd_error ("Failed to register mport %d (err=%d)" , - mport->id, ret); - goto err_cdev; - } -INIT_LIST_HEAD (&md->doorbells);spin_lock_init (&md->db_lock);INIT_LIST_HEAD (&md->portwrites);
@@ -2410,6 +2403,13 @@ static struct mport_dev *mport_cdev_add(#else md->properties.transfer_mode |=RIO_TRANSFER_MODE_TRANSFER ;#endif + + ret =cdev_device_add (&md->cdev, &md->dev); +if (ret) { +rmcd_error ("Failed to register mport %d (err=%d)" , + mport->id, ret); + goto err_cdev; + } ret =rio_query_mport (mport, &attr);if (!ret) { md->properties.flags = attr.flags;
_
Andrew Morton
maintainerPATCH 99/127 rapidio: convert get_user_pages() --> pin_user_pages()
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: rapidio: convert get_user_pages() --> pin_user_pages()
This code was using get_user_pages_fast(), in a "Case 2" scenario (DMA/RDMA), using the categorization from [1]. That means that it's time to convert the get_user_pages_fast() + put_page() calls to pin_user_pages_fast() + unpin_user_pages() calls.
There is some helpful background in [2]: basically, this is a small part of fixing a long-standing disconnect between pinning pages, and file systems' use of those pages.
[1] Documentation/core-api/pin_user_pages.rst
[2] "Explicit pinning of user-space pages":
https://lwn.net/Articles/807108/
---
drivers/rapidio/devices/rio_mport_cdev.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/rapidio/devices/rio_mport_cdev.c renamed from drivers/rapidio/devices/rio_mport_cdev.c~rapidio-convert-get_user_pages-pin_user_pages +5 -8
@@ -572,14 +572,12 @@ static void dma_req_free(struct kref *re struct mport_dma_req *req = container_of(ref, struct mport_dma_req, refcount);struct mport_cdev_priv *priv = req->priv; -unsigned int i;dma_unmap_sg (req->dmach->device->dev, req->sgt.sgl, req->sgt.nents, req->dir);sg_free_table (&req->sgt);if (req->page_list) { -for (i =0 ; i < req->nr_pages; i++) -put_page (req->page_list[i]); +unpin_user_pages (req->page_list, req->nr_pages);kfree (req->page_list); }
@@ -815,7 +813,7 @@ rio_dma_transfer(struct file *filp, u32struct mport_dma_req *req;struct mport_dev *md = priv->md;struct dma_chan *chan; -int i, ret; +int ret;int nents;if (xfer->length ==0 )
@@ -862,7 +860,7 @@ rio_dma_transfer(struct file *filp, u32 goto err_req; } - pinned = get_user_pages_fast( + pinned = pin_user_pages_fast( (unsigned long)xfer->loc_addr & PAGE_MASK, nr_pages, dir == DMA_FROM_DEVICE ? FOLL_WRITE : 0,
@@ -870,7 +868,7 @@ rio_dma_transfer(struct file *filp, u32if (pinned != nr_pages) {if (pinned <0 ) { -rmcd_error ("get_user_pages_unlocked err=%ld" , +rmcd_error ("pin_user_pages_fast err=%ld" , pinned); nr_pages =0 ; }else
@@ -951,8 +949,7 @@ rio_dma_transfer(struct file *filp, u32 err_pg:if (!req->page_list) { -for (i =0 ; i < nr_pages; i++) -put_page (page_list[i]); +unpin_user_pages (page_list, nr_pages);kfree (page_list); } err_req:
_
Andrew Morton
maintainerPATCH 100/127 kernel/relay.c: handle alloc_percpu returning NULL in relay_open
In reply to Andrew MortonFrom: Daniel Axtens <[email protected]>
Subject: kernel/relay.c: handle alloc_percpu returning NULL in relay_open
alloc_percpu() may return NULL, which means chan->buf may be set to NULL. In that case, when we do *per_cpu_ptr(chan->buf, ...), we dereference an invalid pointer:
BUG: Unable to handle kernel data access at 0x7dae0000
Faulting instruction address: 0xc0000000003f3fec
...
NIP [c0000000003f3fec] relay_open+0x29c/0x600
LR [c0000000003f3fc0] relay_open+0x270/0x600
Call Trace: [c000000054353a70] [c0000000003f3fb4] relay_open+0x264/0x600 (unreliable) [c000000054353b00] [c000000000451764] __blk_trace_setup+0x254/0x600 [c000000054353bb0] [c000000000451b78] blk_trace_setup+0x68/0xa0 [c000000054353c10] [c0000000010da77c] sg_ioctl+0x7bc/0x2e80 [c000000054353cd0] [c000000000758cbc] do_vfs_ioctl+0x13c/0x1300 [c000000054353d90] [c000000000759f14] ksys_ioctl+0x94/0x130 [c000000054353de0] [c000000000759ff8] sys_ioctl+0x48/0xb0 [c000000054353e20] [c00000000000bcd0] system_call+0x5c/0x68
Check if alloc_percpu returns NULL.
This was found by syzkaller both on x86 and powerpc, and the reproducer it found on powerpc is capable of hitting the issue as an unprivileged user.
---
kernel/relay.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/relay.c renamed from kernel/relay.c~relay-handle-alloc_percpu-returning-null-in-relay_open +5 -0
@@ -581,6 +581,11 @@ struct rchan *relay_open(const char *basreturn NULL ; chan->buf = alloc_percpu(struct rchan_buf *); +if (!chan->buf) { +kfree (chan); +return NULL ; + } + chan->version =RELAYFS_CHANNEL_VERSION ; chan->n_subbufs = n_subbufs; chan->subbuf_size = subbuf_size;
_
Andrew Morton
maintainerPATCH 101/127 kernel/relay.c: fix read_pos error when multiple readers
In reply to Andrew MortonFrom: Pengcheng Yang <[email protected]>
Subject: kernel/relay.c: fix read_pos error when multiple readers
When reading, read_pos should start with bytes_consumed, not file->f_pos. Because when there is more than one reader, the read_pos corresponding to file->f_pos may have been consumed, which will cause the data that has been consumed to be read and the bytes_consumed update error.
---
kernel/relay.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
kernel/relay.c renamed from kernel/relay.c~kernel-relayc-fix-read_pos-error-when-multiple-readers +7 -10
@@ -996,14 +996,14 @@ static void relay_file_read_consume(stru/* * relay_file_read_avail - boolean, are there unconsumed bytes available? */ -static int relay_file_read_avail (struct rchan_buf *buf,size_t read_pos) +static int relay_file_read_avail (struct rchan_buf *buf) {size_t subbuf_size = buf->chan->subbuf_size;size_t n_subbufs = buf->chan->n_subbufs;size_t produced = buf->subbufs_produced;size_t consumed = buf->subbufs_consumed; -relay_file_read_consume (buf, read_pos,0 ); +relay_file_read_consume (buf,0 ,0 ); consumed = buf->subbufs_consumed;
@@ -1064,23 +1064,20 @@ static size_t relay_file_read_subbuf_ava/** * relay_file_read_start_pos - find the first available byte to read -* @read_pos: file read position * @buf: relay channel buffer * -* If the @read_pos is in the middle of padding, return the +* If the read_pos is in the middle of padding, return the * position of the first actually available byte, otherwise * return the original value. */ -static size_t relay_file_read_start_pos (size_t read_pos, -struct rchan_buf *buf) +static size_t relay_file_read_start_pos (struct rchan_buf *buf) {size_t read_subbuf, padding, padding_start, padding_end;size_t subbuf_size = buf->chan->subbuf_size;size_t n_subbufs = buf->chan->n_subbufs;size_t consumed = buf->subbufs_consumed % n_subbufs; +size_t read_pos = consumed * subbuf_size + buf->bytes_consumed; -if (!read_pos) - read_pos = consumed * subbuf_size + buf->bytes_consumed; read_subbuf = read_pos / subbuf_size; padding = buf->padding[read_subbuf]; padding_start = (read_subbuf +1 ) * subbuf_size - padding;
@@ -1136,10 +1133,10 @@ static ssize_t relay_file_read(struct fi do { void *from; - if (!relay_file_read_avail(buf, *ppos)) + if (!relay_file_read_avail(buf)) break; - read_start = relay_file_read_start_pos(*ppos, buf); + read_start = relay_file_read_start_pos(buf); avail = relay_file_read_subbuf_avail(read_start, buf); if (!avail) break;
_
Andrew Morton
maintainerPATCH 102/127 selftests/x86/pkeys: move selftests to arch-neutral directory
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/x86/pkeys: move selftests to arch-neutral directory
Patch series "selftests, powerpc, x86: Memory Protection Keys", v19.
Memory protection keys enables an application to protect its address space from inadvertent access by its own code.
This feature is now enabled on powerpc and has been available since 4.16-rc1. The patches move the selftests to arch neutral directory and enhance their test coverage.
Tested on powerpc64 and x86_64 (Skylake-SP).
This patch (of 24):
Move selftest files from tools/testing/selftests/x86/ to tools/testing/selftests/vm/.
---
tools/testing/selftests/vm/.gitignore | 1 tools/testing/selftests/vm/Makefile | 1 tools/testing/selftests/vm/pkey-helpers.h | 219 ++ tools/testing/selftests/vm/protection_keys.c | 1506 ++++++++++++++++ tools/testing/selftests/x86/.gitignore | 1 tools/testing/selftests/x86/Makefile | 2 tools/testing/selftests/x86/pkey-helpers.h | 219 -- tools/testing/selftests/x86/protection_keys.c | 1506 ---------------- 8 files changed, 1728 insertions(+), 1727 deletions(-)
tools/testing/selftests/vm/.gitignore renamed from tools/testing/selftests/vm/.gitignore~selftests-x86-pkeys-move-selftests-to-arch-neutral-directory +1 -0
@@ -10,6 +10,7 @@ mlock2-tests mremap_dontunmap on-fault-limit transhuge-stress +protection_keys userfaultfd mlock-intersect-test mlock-random-test
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-x86-pkeys-move-selftests-to-arch-neutral-directory +1 -0
@@ -15,6 +15,7 @@ TEST_GEN_FILES += map_fixed_noreplace TEST_GEN_FILES += map_populate TEST_GEN_FILES += mlock-random-test TEST_GEN_FILES += mlock2-tests +TEST_GEN_FILES += protection_keys TEST_GEN_FILES += mremap_dontunmap TEST_GEN_FILES += on-fault-limit TEST_GEN_FILES += thuge-gen
tools/testing/selftests/vm/pkey-helpers.h new file +219 -0
219 lines not on this page · raw message
tools/testing/selftests/vm/protection_keys.c new file +1506 -0
1,506 lines not on this page · raw message
tools/testing/selftests/x86/.gitignore renamed from tools/testing/selftests/x86/.gitignore~selftests-x86-pkeys-move-selftests-to-arch-neutral-directory +0 -1
@@ -12,5 +12,4 @@ ldt_gdt iopl mpx-mini-test ioperm -protection_keys test_vdso
tools/testing/selftests/x86/Makefile renamed from tools/testing/selftests/x86/Makefile~selftests-x86-pkeys-move-selftests-to-arch-neutral-directory +1 -1
@@ -12,7 +12,7 @@ CAN_BUILD_WITH_NOPIE := $(shell ./check_ TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \ check_initial_reg_state sigreturn iopl ioperm \ - protection_keys test_vdso test_vsyscall mov_ss_trap \ + test_vdso test_vsyscall mov_ss_trap \ syscall_arg_fault TARGETS_C_32BIT_ONLY := entry_from_vm86 test_syscall_vdso unwind_vdso \ test_FCMOV test_FCOMI test_FISTTP \
tools/testing/selftests/x86/pkey-helpers.h deleted +0 -219
219 lines not on this page · raw message
tools/testing/selftests/x86/protection_keys.c deleted +0 -1506
1,029 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
_
Part of the diff is not shown here. View the raw message.
Andrew Morton
maintainerPATCH 103/127 selftests/vm/pkeys: rename all references to pkru to a generic name
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: rename all references to pkru to a generic name
This renames PKRU references to "pkey_reg" or "pkey" based on the usage.
---
tools/testing/selftests/vm/pkey-helpers.h | 85 +++--- tools/testing/selftests/vm/protection_keys.c | 240 ++++++++--------- 2 files changed, 170 insertions(+), 155 deletions(-)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-rename-all-references-to-pkru-to-a-generic-name +44 -41
@@ -14,7 +14,7 @@#include <sys/mman.h> #define NR_PKEYS 16 -#define PKRU_BITS_PER_PKEY 2 +#define PKEY_BITS_PER_PKEY 2#ifndef DEBUG_LEVEL #define DEBUG_LEVEL 0
@@ -53,85 +53,88 @@ static inline void sigsafe_printf(const #define dprintf3(args...) dprintf_level(3, args) #define dprintf4(args...) dprintf_level(4, args) -extern unsigned int shadow_pkru; -static inline unsigned int __rdpkru (void ) +extern unsigned int shadow_pkey_reg; +static inline unsigned int __read_pkey_reg (void ) {unsigned int eax, edx;unsigned int ecx =0 ; -unsigned int pkru; +unsigned int pkey_reg; asmvolatile (".byte 0x0f,0x01,0xee\n\t" :"=a" (eax),"=d" (edx) :"c" (ecx)); - pkru = eax; -return pkru; + pkey_reg = eax; +return pkey_reg; } -static inline unsigned int _rdpkru (int line) +static inline unsigned int _read_pkey_reg (int line) { -unsigned int pkru =__rdpkru (); +unsigned int pkey_reg =__read_pkey_reg (); -dprintf4 ("rdpkru(line=%d) pkru: %x shadow: %x\n" , - line, pkru, shadow_pkru); -assert (pkru == shadow_pkru); +dprintf4 ("read_pkey_reg(line=%d) pkey_reg: %x shadow: %x\n" , + line, pkey_reg, shadow_pkey_reg); +assert (pkey_reg == shadow_pkey_reg); -return pkru; +return pkey_reg; } -#define rdpkru () _rdpkru(__LINE__) +#define read_pkey_reg () _read_pkey_reg(__LINE__) -static inline void __wrpkru (unsigned int pkru) +static inline void __write_pkey_reg (unsigned int pkey_reg) { -unsigned int eax = pkru; +unsigned int eax = pkey_reg;unsigned int ecx =0 ;unsigned int edx =0 ; -dprintf4 ("%s() changing %08x to %08x\n" , __func__,__rdpkru (), pkru); +dprintf4 ("%s() changing %08x to %08x\n" , __func__, +__read_pkey_reg (), pkey_reg); asmvolatile (".byte 0x0f,0x01,0xef\n\t" : :"a" (eax),"c" (ecx),"d" (edx)); -assert (pkru ==__rdpkru ()); +assert (pkey_reg ==__read_pkey_reg ()); } -static inline void wrpkru (unsigned int pkru) +static inline void write_pkey_reg (unsigned int pkey_reg) { -dprintf4 ("%s() changing %08x to %08x\n" , __func__,__rdpkru (), pkru); +dprintf4 ("%s() changing %08x to %08x\n" , __func__, +__read_pkey_reg (), pkey_reg);/* will do the shadow check for us: */ -rdpkru (); -__wrpkru (pkru); - shadow_pkru = pkru; -dprintf4 ("%s(%08x) pkru: %08x\n" , __func__, pkru,__rdpkru ()); +read_pkey_reg (); +__write_pkey_reg (pkey_reg); + shadow_pkey_reg = pkey_reg; +dprintf4 ("%s(%08x) pkey_reg: %08x\n" , __func__, + pkey_reg,__read_pkey_reg ()); }/* * These are technically racy. since something could -* change PKRU between the read and the write. +* change PKEY register between the read and the write. */ static inline void __pkey_access_allow (int pkey,int do_allow) { -unsigned int pkru =rdpkru (); +unsigned int pkey_reg =read_pkey_reg ();int bit = pkey *2 ;if (do_allow) - pkru &= (1 <<bit); + pkey_reg &= (1 <<bit);else - pkru |= (1 <<bit); + pkey_reg |= (1 <<bit); -dprintf4 ("pkru now: %08x\n" ,rdpkru ()); -wrpkru (pkru); +dprintf4 ("pkey_reg now: %08x\n" ,read_pkey_reg ()); +write_pkey_reg (pkey_reg); }static inline void __pkey_write_allow (int pkey,int do_allow_write) { -long pkru =rdpkru (); +long pkey_reg =read_pkey_reg ();int bit = pkey *2 +1 ;if (do_allow_write) - pkru &= (1 <<bit); + pkey_reg &= (1 <<bit);else - pkru |= (1 <<bit); + pkey_reg |= (1 <<bit); -wrpkru (pkru); -dprintf4 ("pkru now: %08x\n" ,rdpkru ()); +write_pkey_reg (pkey_reg); +dprintf4 ("pkey_reg now: %08x\n" ,read_pkey_reg ()); }#define PROT_PKEY0 0x10/* protection key value (bit 0) */
@@ -181,10 +184,10 @@ static inline int cpu_has_pku(void)return 1 ; } -#define XSTATE_PKRU_BIT (9) -#define XSTATE_PKRU 0x200 +#define XSTATE_PKEY_BIT (9) +#define XSTATE_PKEY 0x200 -int pkru_xstate_offset (void ) +int pkey_reg_xstate_offset (void ) {unsigned int eax;unsigned int ebx;
@@ -195,21 +198,21 @@ int pkru_xstate_offset(void)unsigned long XSTATE_CPUID =0xd ;int leaf; -/* assume that XSTATE_PKRU is set in XCR0 */ - leaf =XSTATE_PKRU_BIT ; +/* assume that XSTATE_PKEY is set in XCR0 */ + leaf =XSTATE_PKEY_BIT ; { eax =XSTATE_CPUID ; ecx = leaf;__cpuid (&eax, &ebx, &ecx, &edx); -if (leaf ==XSTATE_PKRU_BIT ) { +if (leaf ==XSTATE_PKEY_BIT ) { xstate_offset = ebx; xstate_size = eax; } }if (xstate_size ==0 ) { -printf ("could not find size/offset of PKRU in xsave state\n" ); +printf ("could not find size/offset of PKEY in xsave state\n" );return 0 ; }
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-rename-all-references-to-pkru-to-a-generic-name +126 -114
527 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 104/127 selftests/vm/pkeys: move generic definitions to header file
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: move generic definitions to header file
Moved all the generic definition and helper functions to the header file.
---
tools/testing/selftests/vm/pkey-helpers.h | 35 ++++++++++++++--- tools/testing/selftests/vm/protection_keys.c | 27 ------------- 2 files changed, 30 insertions(+), 32 deletions(-)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-move-generic-definitions-to-header-file +30 -5
@@ -13,6 +13,14 @@#include <ucontext.h> #include <sys/mman.h> +/* Define some kernel-like types */ +#define u8 uint8_t +#define u16 uint16_t +#define u32 uint32_t +#define u64 uint64_t + +#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP) +#define NR_PKEYS 16#define PKEY_BITS_PER_PKEY 2
@@ -53,6 +61,18 @@ static inline void sigsafe_printf(const #define dprintf3(args...) dprintf_level(3, args) #define dprintf4(args...) dprintf_level(4, args) +extern void abort_hooks (void ); +#define pkey_assert (condition) do { \ + if (!(condition)) { \ + dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \ + __FILE__, __LINE__, \ + test_nr, iteration_nr); \ + dprintf0("errno at assert: %d", errno); \ + abort_hooks(); \ + exit(__LINE__); \ + } \ +} while (0) +extern unsigned int shadow_pkey_reg;static inline unsigned int __read_pkey_reg (void ) {
@@ -137,11 +157,6 @@ static inline void __pkey_write_allow(indprintf4 ("pkey_reg now: %08x\n" ,read_pkey_reg ()); } -#define PROT_PKEY0 0x10/* protection key value (bit 0) */ -#define PROT_PKEY1 0x20/* protection key value (bit 1) */ -#define PROT_PKEY2 0x40/* protection key value (bit 2) */ -#define PROT_PKEY3 0x80/* protection key value (bit 3) */ -#define PAGE_SIZE 4096#define MB (1<<20)
@@ -219,4 +234,14 @@ int pkey_reg_xstate_offset(void)return xstate_offset; } +#define ARRAY_SIZE (x) (sizeof(x) / sizeof(*(x))) +#define ALIGN_UP (x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1)) +#define ALIGN_DOWN (x, align_to) ((x) & ~((align_to)-1)) +#define ALIGN_PTR_UP (p, ptr_align_to) \ + ((typeof(p))ALIGN_UP((unsigned long)(p), ptr_align_to)) +#define ALIGN_PTR_DOWN (p, ptr_align_to) \ + ((typeof(p))ALIGN_DOWN((unsigned long)(p), ptr_align_to)) +#define __stringify_1(x...) #x +#define __stringify(x...) __stringify_1(x) +#endif /* _PKEYS_HELPER_H */
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-move-generic-definitions-to-header-file +0 -26
@@ -51,31 +51,10 @@ int test_nr;unsigned int shadow_pkey_reg;#define HPAGE_SIZE (1UL<<21) -#define ARRAY_SIZE (x) (sizeof(x) / sizeof(*(x))) -#define ALIGN_UP (x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1)) -#define ALIGN_DOWN (x, align_to) ((x) & ~((align_to)-1)) -#define ALIGN_PTR_UP (p, ptr_align_to) ((typeof(p))ALIGN_UP((unsigned long)(p), ptr_align_to)) -#define ALIGN_PTR_DOWN (p, ptr_align_to) ((typeof(p))ALIGN_DOWN((unsigned long)(p), ptr_align_to)) -#define __stringify_1(x...) #x -#define __stringify(x...) __stringify_1(x) - -#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP)int dprint_in_signal;char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE ]; -extern void abort_hooks (void ); -#define pkey_assert (condition) do { \ - if (!(condition)) { \ - dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \ - __FILE__, __LINE__, \ - test_nr, iteration_nr); \ - dprintf0("errno at assert: %d", errno); \ - abort_hooks(); \ - exit(__LINE__); \ - } \ -} while (0) -void cat_into_file (char *str,char *file) {int fd =open (file,O_RDWR );
@@ -186,12 +165,6 @@ void lots_o_noops_around_write(int *writdprintf3 ("%s() done\n" , __func__); } -/* Define some kernel-like types */ -#define u8 uint8_t -#define u16 uint16_t -#define u32 uint32_t -#define u64 uint64_t
Andrew Morton
maintainerPATCH 105/127 selftests/vm/pkeys: move some definitions to arch-specific header
In reply to Andrew MortonFrom: Thiago Jung Bauermann <[email protected]>
Subject: selftests/vm/pkeys: move some definitions to arch-specific header
In preparation for multi-arch support, move definitions which have arch-specific values to x86-specific header.
---
tools/testing/selftests/vm/pkey-helpers.h | 111 ------------ tools/testing/selftests/vm/pkey-x86.h | 156 +++++++++++++++++ tools/testing/selftests/vm/protection_keys.c | 47 ----- 3 files changed, 162 insertions(+), 152 deletions(-)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-move-some-definitions-to-arch-specific-header +6 -105
@@ -21,9 +21,6 @@#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP) -#define NR_PKEYS 16 -#define PKEY_BITS_PER_PKEY 2 -#ifndef DEBUG_LEVEL #define DEBUG_LEVEL 0#endif
@@ -73,19 +70,13 @@ extern void abort_hooks(void); } \ } while (0) +#if defined(__i386__) || defined(__x86_64__)/* arch */ +#include "pkey-x86.h" +#else /* arch */ +#error Architecture not supported +#endif /* arch */ +extern unsigned int shadow_pkey_reg; -static inline unsigned int __read_pkey_reg (void ) -{ -unsigned int eax, edx; -unsigned int ecx =0 ; -unsigned int pkey_reg; - - asmvolatile (".byte 0x0f,0x01,0xee\n\t" - :"=a" (eax),"=d" (edx) - :"c" (ecx)); - pkey_reg = eax; -return pkey_reg; -}static inline unsigned int _read_pkey_reg (int line) {
@@ -100,19 +91,6 @@ static inline unsigned int _read_pkey_re#define read_pkey_reg () _read_pkey_reg(__LINE__) -static inline void __write_pkey_reg (unsigned int pkey_reg) -{ -unsigned int eax = pkey_reg; -unsigned int ecx =0 ; -unsigned int edx =0 ; - -dprintf4 ("%s() changing %08x to %08x\n" , __func__, -__read_pkey_reg (), pkey_reg); - asmvolatile (".byte 0x0f,0x01,0xef\n\t" - : :"a" (eax),"c" (ecx),"d" (edx)); -assert (pkey_reg ==__read_pkey_reg ()); -} -static inline void write_pkey_reg (unsigned int pkey_reg) { dprintf4("%s() changing %08x to %08x\n", __func__,
@@ -157,83 +135,6 @@ static inline void __pkey_write_allow(indprintf4 ("pkey_reg now: %08x\n" ,read_pkey_reg ()); } -#define PAGE_SIZE 4096 -#define MB (1<<20) - -static inline void __cpuid (unsigned int *eax,unsigned int *ebx, -unsigned int *ecx,unsigned int *edx) -{ -/* ecx is often an input as well as an output. */ - asmvolatile ( -"cpuid;" - :"=a" (*eax), -"=b" (*ebx), -"=c" (*ecx), -"=d" (*edx) - :"0" (*eax),"2" (*ecx)); -} - -/* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx) */ -#define X86_FEATURE_PKU (1<<3)/* Protection Keys for Userspace */ -#define X86_FEATURE_OSPKE (1<<4)/* OS Protection Keys Enable */ - -static inline int cpu_has_pku (void ) -{ -unsigned int eax; -unsigned int ebx; -unsigned int ecx; -unsigned int edx; - - eax =0x7 ; - ecx =0x0 ; -__cpuid (&eax, &ebx, &ecx, &edx); - -if (!(ecx &X86_FEATURE_PKU )) { -dprintf2 ("cpu does not have PKU\n" ); -return 0 ; - } -if (!(ecx &X86_FEATURE_OSPKE )) { -dprintf2 ("cpu does not have OSPKE\n" ); -return 0 ; - } -return 1 ; -} - -#define XSTATE_PKEY_BIT (9) -#define XSTATE_PKEY 0x200 - -int pkey_reg_xstate_offset (void ) -{ -unsigned int eax; -unsigned int ebx; -unsigned int ecx; -unsigned int edx; -int xstate_offset; -int xstate_size; -unsigned long XSTATE_CPUID =0xd ; -int leaf; - -/* assume that XSTATE_PKEY is set in XCR0 */ - leaf =XSTATE_PKEY_BIT ; - { - eax =XSTATE_CPUID ; - ecx = leaf; -__cpuid (&eax, &ebx, &ecx, &edx); - -if (leaf ==XSTATE_PKEY_BIT ) { - xstate_offset = ebx; - xstate_size = eax; - } - } - -if (xstate_size ==0 ) { -printf ("could not find size/offset of PKEY in xsave state\n" ); -return 0 ; - } - -return xstate_offset; -} -#define ARRAY_SIZE (x) (sizeof(x) / sizeof(*(x)))#define ALIGN_UP (x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1))#define ALIGN_DOWN (x, align_to) ((x) & ~((align_to)-1))
tools/testing/selftests/vm/pkey-x86.h new file +156 -0
156 lines not on this page · raw message
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-move-some-definitions-to-arch-specific-header +0 -47
71 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 106/127 selftests/vm/pkeys: make gcc check arguments of sigsafe_printf()
In reply to Andrew MortonFrom: Thiago Jung Bauermann <[email protected]>
Subject: selftests/vm/pkeys: make gcc check arguments of sigsafe_printf()
This will help us ensure we print pkey_reg_t values correctly in different architectures.
---
tools/testing/selftests/vm/pkey-helpers.h | 4 ++++ 1 file changed, 4 insertions(+)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-make-gcc-check-arguments-of-sigsafe_printf +4 -0
@@ -27,6 +27,10 @@#define DPRINT_IN_SIGNAL_BUF_SIZE 4096extern int dprint_in_signal;extern char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE ]; + +#ifdef __GNUC__ +__attribute__((format(printf, 1, 2))) +#endif static inline void sigsafe_printf (const char *format, ...) {va_list ap;
_
Andrew Morton
maintainerPATCH 107/127 selftests: vm: pkeys: Use sane types for pkey register
In reply to Andrew MortonFrom: Sandipan Das <[email protected]>
Subject: selftests: vm: pkeys: Use sane types for pkey register
The size of the pkey register can vary across architectures. This converts the data type of all its references to u64 in preparation for multi-arch support.
To keep the definition of the u64 type consistent and remove format specifier related warnings, __SANE_USERSPACE_TYPES__ is defined as suggested by Michael Ellerman.
---
tools/testing/selftests/vm/pkey-helpers.h | 31 +++--- tools/testing/selftests/vm/pkey-x86.h | 8 - tools/testing/selftests/vm/protection_keys.c | 86 ++++++++++------- 3 files changed, 72 insertions(+), 53 deletions(-)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-use-sane-types-for-pkey-register +16 -15
@@ -14,10 +14,10 @@#include <sys/mman.h> /* Define some kernel-like types */ -#define u8 uint8_t -#define u16 uint16_t -#define u32 uint32_t -#define u64 uint64_t +#define u8 __u8 +#define u16 __u16 +#define u32 __u32 +#define u64 __u64#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP)
@@ -80,13 +80,14 @@ extern void abort_hooks(void);#error Architecture not supported#endif /* arch */ -extern unsigned int shadow_pkey_reg; +extern u64 shadow_pkey_reg; -static inline unsigned int _read_pkey_reg (int line) +static inline u64 _read_pkey_reg (int line) { -unsigned int pkey_reg =__read_pkey_reg (); +u64 pkey_reg =__read_pkey_reg (); -dprintf4 ("read_pkey_reg(line=%d) pkey_reg: %x shadow: %x\n" , +dprintf4 ("read_pkey_reg(line=%d) pkey_reg: %016llx" +" shadow: %016llx\n" , line, pkey_reg, shadow_pkey_reg);assert (pkey_reg == shadow_pkey_reg);
@@ -95,15 +96,15 @@ static inline unsigned int _read_pkey_re#define read_pkey_reg () _read_pkey_reg(__LINE__) -static inline void write_pkey_reg (unsigned int pkey_reg) +static inline void write_pkey_reg (u64 pkey_reg) { -dprintf4 ("%s() changing %08x to %08x\n" , __func__, +dprintf4 ("%s() changing %016llx to %016llx\n" , __func__,__read_pkey_reg (), pkey_reg);/* will do the shadow check for us: */ read_pkey_reg ();__write_pkey_reg (pkey_reg); shadow_pkey_reg = pkey_reg; -dprintf4 ("%s(%08x) pkey_reg: %08x\n" , __func__, +dprintf4 ("%s(%016llx) pkey_reg: %016llx\n" , __func__, pkey_reg,__read_pkey_reg ()); }
@@ -113,7 +114,7 @@ static inline void write_pkey_reg(unsign*/ static inline void __pkey_access_allow (int pkey,int do_allow) { -unsigned int pkey_reg =read_pkey_reg (); +u64 pkey_reg =read_pkey_reg ();int bit = pkey *2 ;if (do_allow)
@@ -121,13 +122,13 @@ static inline void __pkey_access_allow(ielse pkey_reg |= (1 <<bit); -dprintf4 ("pkey_reg now: %08x\n" ,read_pkey_reg ()); +dprintf4 ("pkey_reg now: %016llx\n" ,read_pkey_reg ());write_pkey_reg (pkey_reg); }static inline void __pkey_write_allow (int pkey,int do_allow_write) { -long pkey_reg =read_pkey_reg (); +u64 pkey_reg =read_pkey_reg ();int bit = pkey *2 +1 ;if (do_allow_write)
@@ -136,7 +137,7 @@ static inline void __pkey_write_allow(in pkey_reg |= (1 <<bit);write_pkey_reg (pkey_reg); -dprintf4 ("pkey_reg now: %08x\n" ,read_pkey_reg ()); +dprintf4 ("pkey_reg now: %016llx\n" ,read_pkey_reg ()); }#define ARRAY_SIZE (x) (sizeof(x) / sizeof(*(x)))
tools/testing/selftests/vm/pkey-x86.h renamed from tools/testing/selftests/vm/pkey-x86.h~selftests-vm-pkeys-use-sane-types-for-pkey-register +4 -4
@@ -53,11 +53,11 @@ static inline void __page_o_noops(void) asm(".rept 512 ; nopl 0x7eeeeeee(%eax) ; .endr" ); } -static inline unsigned int __read_pkey_reg (void ) +static inline u64 __read_pkey_reg (void ) {unsigned int eax, edx;unsigned int ecx =0 ; -unsigned int pkey_reg; +unsigned pkey_reg; asmvolatile (".byte 0x0f,0x01,0xee\n\t" : "=a" (eax), "=d" (edx)
@@ -66,13 +66,13 @@ static inline unsigned int __read_pkey_rreturn pkey_reg; } -static inline void __write_pkey_reg (unsigned int pkey_reg) +static inline void __write_pkey_reg (u64 pkey_reg) {unsigned int eax = pkey_reg;unsigned int ecx =0 ;unsigned int edx =0 ; -dprintf4 ("%s() changing %08x to %08x\n" , __func__, +dprintf4 ("%s() changing %016llx to %016llx\n" , __func__,__read_pkey_reg (), pkey_reg); asmvolatile (".byte 0x0f,0x01,0xef\n\t" : :"a" (eax),"c" (ecx),"d" (edx));
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-use-sane-types-for-pkey-register +52 -34
260 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 108/127 selftests: vm: pkeys: add helpers for pkey bits
In reply to Andrew MortonFrom: Sandipan Das <[email protected]>
Subject: selftests: vm: pkeys: add helpers for pkey bits
This introduces some functions that help with setting or clearing bits of a particular pkey. This also adds an abstraction for getting a pkey's bit position in the pkey register as this may vary across architectures.
---
tools/testing/selftests/vm/pkey-helpers.h | 22 +++++++++++ tools/testing/selftests/vm/pkey-x86.h | 5 ++ tools/testing/selftests/vm/protection_keys.c | 32 ++++------------- 3 files changed, 36 insertions(+), 23 deletions(-)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-add-helpers-for-pkey-bits +22 -0
@@ -80,6 +80,28 @@ extern void abort_hooks(void);#error Architecture not supported#endif /* arch */ +#define PKEY_MASK (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE) + +static inline u64 set_pkey_bits (u64 reg,int pkey,u64 flags) +{ +u32 shift =pkey_bit_position (pkey); +/* mask out bits from pkey in old value */ + reg &= ~((u64 )PKEY_MASK << shift); +/* OR in new bits for pkey */ + reg |= (flags &PKEY_MASK ) << shift; +return reg; +} + +static inline u64 get_pkey_bits (u64 reg,int pkey) +{ +u32 shift =pkey_bit_position (pkey); +/* +* shift down the relevant bits to the lowest two, then +* mask off all the other higher bits +*/ +return ((reg >> shift) &PKEY_MASK ); +} +extern u64 shadow_pkey_reg;static inline u64 _read_pkey_reg (int line)
tools/testing/selftests/vm/pkey-x86.h renamed from tools/testing/selftests/vm/pkey-x86.h~selftests-vm-pkeys-add-helpers-for-pkey-bits +5 -0
@@ -118,6 +118,11 @@ static inline int cpu_has_pku(void)return 1 ; } +static inline u32 pkey_bit_position (int pkey) +{ +return pkey *PKEY_BITS_PER_PKEY ; +} +#define XSTATE_PKEY_BIT (9)#define XSTATE_PKEY 0x200
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-add-helpers-for-pkey-bits +9 -23
@@ -334,25 +334,13 @@ pid_t fork_lazy_child(void)static u32 hw_pkey_get (int pkey,unsigned long flags) { -u32 mask = (PKEY_DISABLE_ACCESS |PKEY_DISABLE_WRITE );u64 pkey_reg =__read_pkey_reg (); -u64 shifted_pkey_reg; -u32 masked_pkey_reg;dprintf1 ("%s(pkey=%d, flags=%lx) = %x / %d\n" , __func__, pkey, flags,0 ,0 );dprintf2 ("%s() raw pkey_reg: %016llx\n" , __func__, pkey_reg); - shifted_pkey_reg = (pkey_reg >> (pkey *PKEY_BITS_PER_PKEY )); -dprintf2 ("%s() shifted_pkey_reg: %016llx\n" , __func__, - shifted_pkey_reg); - masked_pkey_reg = shifted_pkey_reg & mask; -dprintf2 ("%s() masked pkey_reg: %x\n" , __func__, masked_pkey_reg); -/* -* shift down the relevant bits to the lowest two, then -* mask off all the other high bits. -*/ -return masked_pkey_reg; +return (u32 )get_pkey_bits (pkey_reg, pkey); }static int hw_pkey_set (int pkey,unsigned long rights,unsigned long flags)
@@ -364,12 +352,8 @@ static int hw_pkey_set(int pkey, unsigne/* make sure that 'rights' only contains the bits we expect: */ assert (!(rights & ~mask)); -/* copy old pkey_reg */ - new_pkey_reg = old_pkey_reg; -/* mask out bits from pkey in old value: */ - new_pkey_reg &= ~(mask << (pkey *PKEY_BITS_PER_PKEY )); -/* OR in new bits for pkey: */ - new_pkey_reg |= (rights << (pkey *PKEY_BITS_PER_PKEY )); +/* modify bits accordingly in old pkey_reg and assign it */ + new_pkey_reg =set_pkey_bits (old_pkey_reg, pkey, rights);__write_pkey_reg (new_pkey_reg);
@@ -403,7 +387,7 @@ void pkey_disable_set(int pkey, int flag ret =hw_pkey_set (pkey, pkey_rights, syscall_flags);assert (!ret);/* pkey_reg and flags have the same format */ - shadow_pkey_reg |= flags << (pkey *2 ); + shadow_pkey_reg =set_pkey_bits (shadow_pkey_reg, pkey, pkey_rights);dprintf1 ("%s(%d) shadow: 0x%016llx\n" , __func__, pkey, shadow_pkey_reg);
@@ -437,7 +421,7 @@ void pkey_disable_clear(int pkey, int fl pkey_rights |= flags; ret =hw_pkey_set (pkey, pkey_rights,0 ); - shadow_pkey_reg &= ~(flags << (pkey *2 )); + shadow_pkey_reg =set_pkey_bits (shadow_pkey_reg, pkey, pkey_rights);pkey_assert (ret >=0 ); pkey_rights =hw_pkey_get (pkey, syscall_flags);
@@ -513,7 +497,8 @@ int alloc_pkey(void) shadow_pkey_reg);if (ret) {/* clear both the bits: */ - shadow_pkey_reg &= ~(0x3 << (ret *2 )); + shadow_pkey_reg =set_pkey_bits (shadow_pkey_reg, ret, + ~PKEY_MASK ); dprintf4("%s()::%d, ret: %d pkey_reg: 0x%016llx" " shadow: 0x%016llx\n", __func__,
@@ -523,7 +508,8 @@ int alloc_pkey(void)* move the new state in from init_val * (remember, we cheated and init_val == pkey_reg format) */ - shadow_pkey_reg |= (init_val << (ret *2 )); + shadow_pkey_reg =set_pkey_bits (shadow_pkey_reg, ret, + init_val); } dprintf4("%s()::%d, ret: %d pkey_reg: 0x%016llx" " shadow: 0x%016llx\n",
_
Andrew Morton
maintainerPATCH 109/127 selftests/vm/pkeys: fix pkey_disable_clear()
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: fix pkey_disable_clear()
Currently, pkey_disable_clear() sets the specified bits instead clearing them. This has been dead code up to now because its only callers i.e. pkey_access/write_allow() are also unused.
---
tools/testing/selftests/vm/protection_keys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-fix-pkey_disable_clear +2 -2
@@ -418,7 +418,7 @@ void pkey_disable_clear(int pkey, int fl pkey, pkey, pkey_rights);pkey_assert (pkey_rights >=0 ); - pkey_rights |= flags; + pkey_rights &= ~flags; ret =hw_pkey_set (pkey, pkey_rights,0 ); shadow_pkey_reg =set_pkey_bits (shadow_pkey_reg, pkey, pkey_rights);
@@ -431,7 +431,7 @@ void pkey_disable_clear(int pkey, int fldprintf1 ("%s(%d) pkey_reg: 0x%016llx\n" , __func__, pkey,read_pkey_reg ());if (flags) -assert (read_pkey_reg () > orig_pkey_reg); +assert (read_pkey_reg () < orig_pkey_reg); }void pkey_write_allow (int pkey)
_
Andrew Morton
maintainerPATCH 110/127 selftests/vm/pkeys: fix assertion in pkey_disable_set/clear()
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: fix assertion in pkey_disable_set/clear()
In some cases, a pkey's bits need not necessarily change in a way that the value of the pkey register increases when performing a pkey_disable_set() or decreases when performing a pkey_disable_clear().
For example, on powerpc, if a pkey's current state is PKEY_DISABLE_ACCESS and we perform a pkey_write_disable() on it, the bits still remain the same. We will observe something similar when the pkey's current state is 0 and a pkey_access_enable() is performed on it.
Either case would cause some assertions to fail. This fixes the problem.
---
tools/testing/selftests/vm/protection_keys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-fix-assertion-in-pkey_disable_set-clear +2 -2
@@ -400,7 +400,7 @@ void pkey_disable_set(int pkey, int flagdprintf1 ("%s(%d) pkey_reg: 0x%016llx\n" , __func__, pkey,read_pkey_reg ());if (flags) -pkey_assert (read_pkey_reg () > orig_pkey_reg); +pkey_assert (read_pkey_reg () >= orig_pkey_reg);dprintf1 ("END<---%s(%d, 0x%x)\n" , __func__, pkey, flags); }
@@ -431,7 +431,7 @@ void pkey_disable_clear(int pkey, int fldprintf1 ("%s(%d) pkey_reg: 0x%016llx\n" , __func__, pkey,read_pkey_reg ());if (flags) -assert (read_pkey_reg () < orig_pkey_reg); +assert (read_pkey_reg () <= orig_pkey_reg); }void pkey_write_allow (int pkey)
_
Andrew Morton
maintainerPATCH 111/127 selftests/vm/pkeys: fix alloc_random_pkey() to make it really random
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: fix alloc_random_pkey() to make it really random
alloc_random_pkey() was allocating the same pkey every time. Not all pkeys were geting tested. This fixes it.
---
tools/testing/selftests/vm/protection_keys.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-fix-alloc_random_pkey-to-make-it-really-random +2 -1
@@ -25,6 +25,7 @@#define __SANE_USERSPACE_TYPES__#include <errno.h> #include <linux/futex.h> +#include <time.h> #include <sys/time.h> #include <sys/syscall.h> #include <string.h>
@@ -546,10 +547,10 @@ int alloc_random_pkey(void)int nr_alloced =0 ;int random_index;memset (alloced_pkeys,0 ,sizeof (alloced_pkeys)); +srand ((unsigned int )time (NULL ));/* allocate every possible key and make a note of which ones we got */ max_nr_pkey_allocs =NR_PKEYS ; - max_nr_pkey_allocs =1 ;for (i =0 ; i < max_nr_pkey_allocs; i++) {int new_pkey =alloc_pkey ();if (new_pkey <0 )
_
Andrew Morton
maintainerPATCH 112/127 selftests: vm: pkeys: use the correct huge page size
In reply to Andrew MortonFrom: Sandipan Das <[email protected]>
Subject: selftests: vm: pkeys: use the correct huge page size
The huge page size can vary across architectures. This will ensure that the correct huge page size is used when accessing the hugetlb controls under sysfs. Instead of using a hardcoded page size (i.e. 2MB), this now uses the HPAGE_SIZE macro which is arch-specific.
---
tools/testing/selftests/vm/protection_keys.c | 23 +++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-)
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-use-the-correct-huge-page-size +16 -7
@@ -739,12 +739,15 @@ void *malloc_pkey_anon_huge(long size, i }int hugetlb_setup_ok; +#define SYSFS_FMT_NR_HUGE_PAGES "/sys/kernel/mm/hugepages/hugepages-%ldkB/nr_hugepages"#define GET_NR_HUGE_PAGES 10void setup_hugetlbfs (void ) {int err;int fd; -char buf[] ="123" ; +char buf[256 ]; +long hpagesz_kb; +long hpagesz_mb;if (geteuid () !=0 ) {fprintf (stderr,"WARNING: not run as root, can not do hugetlb test\n" );
@@ -755,11 +758,16 @@ void setup_hugetlbfs(void)/* * Now go make sure that we got the pages and that they -* are 2M pages. Someone might have made 1G the default. +* are PMD-level pages. Someone might have made PUD-level +* pages the default. */ - fd =open ("/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" ,O_RDONLY ); + hpagesz_kb =HPAGE_SIZE /1024 ; + hpagesz_mb = hpagesz_kb /1024 ; +sprintf (buf,SYSFS_FMT_NR_HUGE_PAGES , hpagesz_kb); + fd =open (buf,O_RDONLY );if (fd <0 ) { -perror ("opening sysfs 2M hugetlb config" ); +fprintf (stderr,"opening sysfs %ldM hugetlb config: %s\n" , + hpagesz_mb,strerror (errno));return ; }
@@ -767,13 +775,14 @@ void setup_hugetlbfs(void) err =read (fd, buf,sizeof (buf)-1 );close (fd);if (err <=0 ) { -perror ("reading sysfs 2M hugetlb config" ); +fprintf (stderr,"reading sysfs %ldM hugetlb config: %s\n" , + hpagesz_mb,strerror (errno));return ; }if (atoi (buf) !=GET_NR_HUGE_PAGES ) { -fprintf (stderr,"could not confirm 2M pages, got: '%s' expected %d\n" , - buf,GET_NR_HUGE_PAGES ); +fprintf (stderr,"could not confirm %ldM pages, got: '%s' expected %d\n" , + hpagesz_mb, buf,GET_NR_HUGE_PAGES );return ; }
_
Andrew Morton
maintainerPATCH 113/127 selftests/vm/pkeys: introduce generic pkey abstractions
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: introduce generic pkey abstractions
This introduces some generic abstractions and provides the corresponding architecture-specfic implementations for these abstractions.
---
tools/testing/selftests/vm/pkey-helpers.h | 12 ++++++++++++ tools/testing/selftests/vm/pkey-x86.h | 15 +++++++++++++++ tools/testing/selftests/vm/protection_keys.c | 8 ++------ 3 files changed, 29 insertions(+), 6 deletions(-)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-introduce-generic-pkey-abstractions +12 -0
@@ -74,6 +74,9 @@ extern void abort_hooks(void); } \ }while (0 ) +__attribute__((noinline)) int read_ptr(int *ptr); +void expected_pkey_fault (int pkey); +#if defined(__i386__) || defined(__x86_64__)/* arch */ #include "pkey-x86.h" #else /* arch */
@@ -172,4 +175,13 @@ static inline void __pkey_write_allow(in #define __stringify_1(x...) #x #define __stringify(x...) __stringify_1(x) +static inline u32 *siginfo_get_pkey_ptr (siginfo_t *si) +{ +#ifdef si_pkey +return &si->si_pkey; +#else +return (u32 *)(((u8 *)si) + si_pkey_offset); +#endif +} +#endif /* _PKEYS_HELPER_H */
tools/testing/selftests/vm/pkey-x86.h renamed from tools/testing/selftests/vm/pkey-x86.h~selftests-vm-pkeys-introduce-generic-pkey-abstractions +15 -0
@@ -42,6 +42,7 @@#endif #define NR_PKEYS 16 +#define NR_RESERVED_PKEYS 2/* pkey-0 and exec-only-pkey */ #define PKEY_BITS_PER_PKEY 2#define HPAGE_SIZE (1UL<<21)#define PAGE_SIZE 4096
@@ -158,4 +159,18 @@ int pkey_reg_xstate_offset(void) return xstate_offset; } +static inline int get_arch_reserved_keys (void ) +{ +return NR_RESERVED_PKEYS ; +} + +void expect_fault_on_read_execonly_key (void *p1,int pkey) +{ +int ptr_contents; + + ptr_contents =read_ptr (p1); +dprintf2 ("ptr (%p) contents@%d: %x\n" , p1, __LINE__, ptr_contents); +expected_pkey_fault (pkey); +} +#endif /* _PKEYS_X86_H */
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-introduce-generic-pkey-abstractions +2 -6
@@ -1307,9 +1307,7 @@ void test_executing_on_unreadable_memorymadvise (p1,PAGE_SIZE ,MADV_DONTNEED );lots_o_noops_around_write (&scratch);do_not_expect_pkey_fault ("executing on PROT_EXEC memory" ); - ptr_contents =read_ptr (p1); -dprintf2 ("ptr (%p) contents@%d: %x\n" , p1, __LINE__, ptr_contents); -expected_pkey_fault (pkey); +expect_fault_on_read_execonly_key (p1, pkey); }void test_implicit_mprotect_exec_only_memory (int *ptr,u16 pkey)
@@ -1336,9 +1334,7 @@ void test_implicit_mprotect_exec_only_memadvise (p1,PAGE_SIZE ,MADV_DONTNEED );lots_o_noops_around_write (&scratch);do_not_expect_pkey_fault ("executing on PROT_EXEC memory" ); - ptr_contents =read_ptr (p1); -dprintf2 ("ptr (%p) contents@%d: %x\n" , p1, __LINE__, ptr_contents); -expected_pkey_fault (UNKNOWN_PKEY ); +expect_fault_on_read_execonly_key (p1,UNKNOWN_PKEY );/* * Put the memory back to non-PROT_EXEC. Should clear the
_
Andrew Morton
maintainerPATCH 114/127 selftests/vm/pkeys: introduce powerpc support
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: introduce powerpc support
This makes use of the abstractions added earlier and introduces support for powerpc.
For powerpc, after receiving the SIGSEGV, the signal handler must explicitly restore access permissions for the faulting pkey to allow the test to continue. As this makes use of pkey_access_allow(), all of its dependencies and other similar functions have been moved ahead of the signal handler.
---
tools/testing/selftests/vm/pkey-helpers.h | 2 tools/testing/selftests/vm/pkey-powerpc.h | 91 +++++ tools/testing/selftests/vm/protection_keys.c | 269 ++++++++--------- 3 files changed, 234 insertions(+), 128 deletions(-)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-introduce-powerpc-support +2 -0
@@ -79,6 +79,8 @@ void expected_pkey_fault(int pkey);#if defined(__i386__) || defined(__x86_64__)/* arch */ #include "pkey-x86.h" +#elif defined(__powerpc64__)/* arch */ +#include "pkey-powerpc.h" #else /* arch */ #error Architecture not supported#endif /* arch */
tools/testing/selftests/vm/pkey-powerpc.h new file +91 -0
91 lines not on this page · raw message
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-introduce-powerpc-support +137 -127
327 lines not on this page · raw message
Andrew Morton
maintainerPATCH 115/127 selftests/vm/pkeys: fix number of reserved powerpc pkeys
In reply to Andrew MortonFrom: "Desnes A. Nunes do Rosario" <[email protected]>
Subject: selftests/vm/pkeys: fix number of reserved powerpc pkeys
The number of reserved pkeys in a PowerNV environment is different from that on PowerVM or KVM.
Tested on PowerVM and PowerNV environments.
---
tools/testing/selftests/vm/pkey-powerpc.h | 22 ++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
tools/testing/selftests/vm/pkey-powerpc.h renamed from tools/testing/selftests/vm/pkey-powerpc.h~selftests-vm-pkeys-fix-number-of-reserved-powerpc-pkeys +20 -2
@@ -28,7 +28,10 @@#define NR_RESERVED_PKEYS_4K 27/* pkey-0, pkey-1, exec-only-pkey and 24 other keys that cannot be represented in the PTE */ -#define NR_RESERVED_PKEYS_64K 3/* pkey-0, pkey-1 and exec-only-pkey */ +#define NR_RESERVED_PKEYS_64K_3KEYS 3/* PowerNV and KVM: pkey-0, +pkey-1 and exec-only key */ +#define NR_RESERVED_PKEYS_64K_4KEYS 4/* PowerVM: pkey-0, pkey-1, +pkey-31 and exec-only key */ #define PKEY_BITS_PER_PKEY 2#define HPAGE_SIZE (1UL << 24)#define PAGE_SIZE (1UL << 16)
@@ -66,12 +69,27 @@ static inline int cpu_has_pku(void)return 1 ; } +static inline bool arch_is_powervm () +{ +struct stat buf; + +if ((stat ("/sys/firmware/devicetree/base/ibm,partition-name" , &buf) ==0 ) && + (stat ("/sys/firmware/devicetree/base/hmc-managed?" , &buf) ==0 ) && + (stat ("/sys/firmware/devicetree/base/chosen/qemu,graphic-width" , &buf) ==-1 ) ) +return true; + +return false; +} +static inline int get_arch_reserved_keys (void ) {if (sysconf (_SC_PAGESIZE) ==4096 )return NR_RESERVED_PKEYS_4K ;else -return NR_RESERVED_PKEYS_64K ; +if (arch_is_powervm ()) +return NR_RESERVED_PKEYS_64K_4KEYS ; +else +return NR_RESERVED_PKEYS_64K_3KEYS ; }void expect_fault_on_read_execonly_key (void *p1,int pkey)
_
Andrew Morton
maintainerPATCH 116/127 selftests/vm/pkeys: fix assertion in test_pkey_alloc_exhaust()
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: fix assertion in test_pkey_alloc_exhaust()
Some pkeys which are valid on the hardware are reserved and not available for application use. These keys cannot be allocated.
test_pkey_alloc_exhaust() tries to account for these and has an assertion which validates if all available pkeys have been exahaustively allocated. However, the expression that is currently used is only valid for x86. On powerpc, a pkey is additionally reserved as compared to x86. Hence, the assertion is made to use an arch-specific helper to get the correct count of reserved pkeys.
---
tools/testing/selftests/vm/protection_keys.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-fix-assertion-in-test_pkey_alloc_exhaust +10 -1
@@ -1153,6 +1153,7 @@ void test_pkey_alloc_exhaust(int *ptr, udprintf3 ("%s()::%d\n" , __func__, __LINE__);/* +* On x86: * There are 16 pkeys supported in hardware. Three are * allocated by the time we get here: * 1. The default key (0)
@@ -1160,8 +1161,16 @@ void test_pkey_alloc_exhaust(int *ptr, u* 3. One allocated by the test code and passed in via * 'pkey' to this function. * Ensure that we can allocate at least another 13 (16-3). +* +* On powerpc: +* There are either 5, 28, 29 or 32 pkeys supported in +* hardware depending on the page size (4K or 64K) and +* platform (powernv or powervm). Four are allocated by +* the time we get here. These include pkey-0, pkey-1, +* exec-only pkey and the one allocated by the test code. +* Ensure that we can allocate the remaining. */ -pkey_assert (i >=NR_PKEYS -3 ); +pkey_assert (i >= (NR_PKEYS -get_arch_reserved_keys () -1 ));for (i =0 ; i < nr_allocated_pkeys; i++) { err =sys_pkey_free (allocated_pkeys[i]);
_
Andrew Morton
maintainerPATCH 117/127 selftests/vm/pkeys: improve checks to determine pkey support
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: improve checks to determine pkey support
For the pkeys subsystem to work, both the CPU and the kernel need to have support. So, additionally check if the kernel supports pkeys apart from the CPU feature checks.
---
tools/testing/selftests/vm/pkey-helpers.h | 30 +++++++++++++++++ tools/testing/selftests/vm/pkey-powerpc.h | 3 + tools/testing/selftests/vm/pkey-x86.h | 2 - tools/testing/selftests/vm/protection_keys.c | 7 ++- 4 files changed, 37 insertions(+), 5 deletions(-)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-improve-checks-to-determine-pkey-support +30 -0
@@ -76,6 +76,8 @@ extern void abort_hooks(void); __attribute__((noinline))int read_ptr (int *ptr);void expected_pkey_fault (int pkey); +int sys_pkey_alloc (unsigned long flags,unsigned long init_val); +int sys_pkey_free (unsigned long pkey);#if defined(__i386__) || defined(__x86_64__)/* arch */ #include "pkey-x86.h"
@@ -186,4 +188,32 @@ static inline u32 *siginfo_get_pkey_ptr( #endif } +static inline int kernel_has_pkeys (void ) +{ +/* try allocating a key and see if it succeeds */ +int ret =sys_pkey_alloc (0 ,0 ); +if (ret <=0 ) { +return 0 ; + } +sys_pkey_free (ret); +return 1 ; +} + +static inline int is_pkeys_supported (void ) +{ +/* check if the cpu supports pkeys */ +if (!cpu_has_pkeys ()) { +dprintf1 ("SKIP: %s: no CPU support\n" , __func__); +return 0 ; + } + +/* check if the kernel supports pkeys */ +if (!kernel_has_pkeys ()) { +dprintf1 ("SKIP: %s: no kernel support\n" , __func__); +return 0 ; + } + +return 1 ; +} +#endif /* _PKEYS_HELPER_H */
tools/testing/selftests/vm/pkey-powerpc.h renamed from tools/testing/selftests/vm/pkey-powerpc.h~selftests-vm-pkeys-improve-checks-to-determine-pkey-support +2 -1
@@ -64,8 +64,9 @@ static inline void __write_pkey_reg(u64 __func__, __read_pkey_reg(), pkey_reg); } -static inline int cpu_has_pku (void ) +static inline int cpu_has_pkeys (void ) { +/* No simple way to determine this */ return 1 ; }
tools/testing/selftests/vm/pkey-x86.h renamed from tools/testing/selftests/vm/pkey-x86.h~selftests-vm-pkeys-improve-checks-to-determine-pkey-support +1 -1
@@ -97,7 +97,7 @@ static inline void __cpuid(unsigned int#define X86_FEATURE_PKU (1<<3)/* Protection Keys for Userspace */ #define X86_FEATURE_OSPKE (1<<4)/* OS Protection Keys Enable */ -static inline int cpu_has_pku (void ) +static inline int cpu_has_pkeys (void ) {unsigned int eax;unsigned int ebx;
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-improve-checks-to-determine-pkey-support +4 -3
@@ -1378,7 +1378,7 @@ void test_mprotect_pkey_on_unsupported_cint size =PAGE_SIZE ;int sret; -if (cpu_has_pku ()) { +if (cpu_has_pkeys ()) {dprintf1 ("SKIP: %s: no CPU support\n" , __func__);return ; }
@@ -1447,12 +1447,13 @@ void pkey_setup_shadow(void)int main (void ) {int nr_iterations =22 ; +int pkeys_supported =is_pkeys_supported ();setup_handlers (); -printf ("has pku: %d\n" ,cpu_has_pku ()); +printf ("has pkeys: %d\n" , pkeys_supported); -if (!cpu_has_pku ()) { +if (!pkeys_supported) {int size =PAGE_SIZE ;int *ptr;
_
Andrew Morton
maintainerPATCH 118/127 selftests/vm/pkeys: associate key on a mapped page and detect access violation
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: associate key on a mapped page and detect access violation
Detect access-violation on a page to which access-disabled key is associated much after the page is mapped.
Signed-off: Sandipan Das <[email protected]>
---
tools/testing/selftests/vm/protection_keys.c | 19 +++++++++++++++++ 1 file changed, 19 insertions(+)
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-associate-key-on-a-mapped-page-and-detect-access-violation +19 -0
@@ -984,6 +984,24 @@ void test_read_of_access_disabled_regiondprintf1 ("*ptr: %d\n" , ptr_contents);expected_pkey_fault (pkey); } + +void test_read_of_access_disabled_region_with_page_already_mapped (int *ptr, +u16 pkey) +{ +int ptr_contents; + +dprintf1 ("disabling access to PKEY[%02d], doing read @ %p\n" , + pkey, ptr); + ptr_contents =read_ptr (ptr); +dprintf1 ("reading ptr before disabling the read : %d\n" , + ptr_contents); +read_pkey_reg (); +pkey_access_deny (pkey); + ptr_contents =read_ptr (ptr); +dprintf1 ("*ptr: %d\n" , ptr_contents); +expected_pkey_fault (pkey); +} +void test_write_of_write_disabled_region (int *ptr,u16 pkey) {dprintf1 ("disabling write access to PKEY[%02d], doing write\n" , pkey);
@@ -1390,6 +1408,7 @@ void test_mprotect_pkey_on_unsupported_cvoid (*pkey_tests[])(int *ptr,u16 pkey) = { test_read_of_write_disabled_region, test_read_of_access_disabled_region, + test_read_of_access_disabled_region_with_page_already_mapped, test_write_of_write_disabled_region, test_write_of_access_disabled_region, test_kernel_write_of_access_disabled_region,
_
Andrew Morton
maintainerPATCH 119/127 selftests/vm/pkeys: associate key on a mapped page and detect write violation
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: associate key on a mapped page and detect write violation
Detect write-violation on a page to which write-disabled key is associated much after the page is mapped.
---
tools/testing/selftests/vm/protection_keys.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-associate-key-on-a-mapped-page-and-detect-write-violation +12 -0
@@ -1002,6 +1002,17 @@ void test_read_of_access_disabled_regionexpected_pkey_fault (pkey); } +void test_write_of_write_disabled_region_with_page_already_mapped (int *ptr, +u16 pkey) +{ + *ptr = __LINE__; +dprintf1 ("disabling write access; after accessing the page, " +"to PKEY[%02d], doing write\n" , pkey); +pkey_write_deny (pkey); + *ptr = __LINE__; +expected_pkey_fault (pkey); +} +void test_write_of_write_disabled_region (int *ptr,u16 pkey) {dprintf1 ("disabling write access to PKEY[%02d], doing write\n" , pkey);
@@ -1410,6 +1421,7 @@ void (*pkey_tests[])(int *ptr, u16 pkey) test_read_of_access_disabled_region, test_read_of_access_disabled_region_with_page_already_mapped, test_write_of_write_disabled_region, + test_write_of_write_disabled_region_with_page_already_mapped, test_write_of_access_disabled_region, test_kernel_write_of_access_disabled_region, test_kernel_write_of_write_disabled_region,
_
Andrew Morton
maintainerPATCH 120/127 selftests/vm/pkeys: detect write violation on a mapped access-denied-key page
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: detect write violation on a mapped access-denied-key page
Detect write-violation on a page to which access-disabled key is associated much after the page is mapped.
---
tools/testing/selftests/vm/protection_keys.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-detect-write-violation-on-a-mapped-access-denied-key-page +13 -0
@@ -1027,6 +1027,18 @@ void test_write_of_access_disabled_regio *ptr = __LINE__;expected_pkey_fault (pkey); } + +void test_write_of_access_disabled_region_with_page_already_mapped (int *ptr, +u16 pkey) +{ + *ptr = __LINE__; +dprintf1 ("disabling access; after accessing the page, " +" to PKEY[%02d], doing write\n" , pkey); +pkey_access_deny (pkey); + *ptr = __LINE__; +expected_pkey_fault (pkey); +} +void test_kernel_write_of_access_disabled_region (int *ptr,u16 pkey) {int ret;
@@ -1423,6 +1435,7 @@ void (*pkey_tests[])(int *ptr, u16 pkey) test_write_of_write_disabled_region, test_write_of_write_disabled_region_with_page_already_mapped, test_write_of_access_disabled_region, + test_write_of_access_disabled_region_with_page_already_mapped, test_kernel_write_of_access_disabled_region, test_kernel_write_of_write_disabled_region, test_kernel_gup_of_access_disabled_region,
_
Andrew Morton
maintainerPATCH 121/127 selftests/vm/pkeys: introduce a sub-page allocator
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: introduce a sub-page allocator
This introduces a new allocator that allocates 4K hardware pages to back 64K linux pages. This allocator is available only on powerpc.
---
tools/testing/selftests/vm/pkey-helpers.h | 6 ++++ tools/testing/selftests/vm/pkey-powerpc.h | 25 +++++++++++++++++ tools/testing/selftests/vm/pkey-x86.h | 5 +++ tools/testing/selftests/vm/protection_keys.c | 1 4 files changed, 37 insertions(+)
tools/testing/selftests/vm/pkey-helpers.h renamed from tools/testing/selftests/vm/pkey-helpers.h~selftests-vm-pkeys-introduce-a-sub-page-allocator +6 -0
@@ -28,6 +28,9 @@extern int dprint_in_signal;extern char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE ]; +extern int test_nr; +extern int iteration_nr; +#ifdef __GNUC__ __attribute__((format(printf, 1, 2)))#endif
@@ -78,6 +81,9 @@ __attribute__((noinline)) int read_ptr(ivoid expected_pkey_fault (int pkey);int sys_pkey_alloc (unsigned long flags,unsigned long init_val);int sys_pkey_free (unsigned long pkey); +int mprotect_pkey (void *ptr,size_t size,unsigned long orig_prot, +unsigned long pkey); +void record_pkey_malloc (void *ptr,long size,int prot);#if defined(__i386__) || defined(__x86_64__)/* arch */ #include "pkey-x86.h"
tools/testing/selftests/vm/pkey-powerpc.h renamed from tools/testing/selftests/vm/pkey-powerpc.h~selftests-vm-pkeys-introduce-a-sub-page-allocator +25 -0
@@ -107,4 +107,29 @@ void expect_fault_on_read_execonly_key(v/* 4-byte instructions * 16384 = 64K page */ #define __page_o_noops () asm(".rept 16384 ; nop; .endr") +void *malloc_pkey_with_mprotect_subpage (long size,int prot,u16 pkey) +{ +void *ptr; +int ret; + +dprintf1 ("doing %s(size=%ld, prot=0x%x, pkey=%d)\n" , __func__, + size, prot, pkey); +pkey_assert (pkey <NR_PKEYS ); + ptr =mmap (NULL , size, prot,MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); +pkey_assert (ptr != (void *)-1 ); + + ret =syscall (__NR_subpage_prot, ptr, size,NULL ); +if (ret) { +perror ("subpage_perm" ); +return PTR_ERR_ENOTSUP ; + } + + ret =mprotect_pkey ((void *)ptr,PAGE_SIZE , prot, pkey); +pkey_assert (!ret); +record_pkey_malloc (ptr, size, prot); + +dprintf1 ("%s() for pkey %d @ %p\n" , __func__, pkey, ptr); +return ptr; +} +#endif /* _PKEYS_POWERPC_H */
tools/testing/selftests/vm/pkey-x86.h renamed from tools/testing/selftests/vm/pkey-x86.h~selftests-vm-pkeys-introduce-a-sub-page-allocator +5 -0
@@ -173,4 +173,9 @@ void expect_fault_on_read_execonly_key(v expected_pkey_fault(pkey); } +void *malloc_pkey_with_mprotect_subpage (long size,int prot,u16 pkey) +{ +return PTR_ERR_ENOTSUP ; +} +#endif /* _PKEYS_X86_H */
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-introduce-a-sub-page-allocator +1 -0
@@ -845,6 +845,7 @@ void *malloc_pkey_mmap_dax(long size, invoid *(*pkey_malloc[])(long size,int prot,u16 pkey) = { malloc_pkey_with_mprotect, + malloc_pkey_with_mprotect_subpage, malloc_pkey_anon_huge, malloc_pkey_hugetlb/* can not do direct with the pkey_mprotect() API:
_
Andrew Morton
maintainerPATCH 122/127 selftests/vm/pkeys: test correct behaviour of pkey-0
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: test correct behaviour of pkey-0
Ensure that pkey-0 is allocated on start and that it can be attached dynamically in various modes, without failures.
---
tools/testing/selftests/vm/protection_keys.c | 53 +++++++++++++++++ 1 file changed, 53 insertions(+)
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-test-correct-behaviour-of-pkey-0 +53 -0
@@ -964,6 +964,58 @@ __attribute__((noinline)) int read_ptr(ireturn *ptr; } +void test_pkey_alloc_free_attach_pkey0 (int *ptr,u16 pkey) +{ +int i, err; +int max_nr_pkey_allocs; +int alloced_pkeys[NR_PKEYS ]; +int nr_alloced =0 ; +long size; + +pkey_assert (pkey_last_malloc_record); + size = pkey_last_malloc_record->size; +/* +* This is a bit of a hack. But mprotect() requires +* huge-page-aligned sizes when operating on hugetlbfs. +* So, make sure that we use something that's a multiple +* of a huge page when we can. +*/ +if (size >=HPAGE_SIZE ) + size =HPAGE_SIZE ; + +/* allocate every possible key and make sure key-0 never got allocated */ + max_nr_pkey_allocs =NR_PKEYS ; +for (i =0 ; i < max_nr_pkey_allocs; i++) { +int new_pkey =alloc_pkey (); +pkey_assert (new_pkey !=0 ); + +if (new_pkey <0 ) +break ; + alloced_pkeys[nr_alloced++] = new_pkey; + } +/* free all the allocated keys */ +for (i =0 ; i < nr_alloced; i++) { +int free_ret; + +if (!alloced_pkeys[i]) +continue ; + free_ret =sys_pkey_free (alloced_pkeys[i]); +pkey_assert (!free_ret); + } + +/* attach key-0 in various modes */ + err =sys_mprotect_pkey (ptr, size,PROT_READ ,0 ); +pkey_assert (!err); + err =sys_mprotect_pkey (ptr, size,PROT_WRITE ,0 ); +pkey_assert (!err); + err =sys_mprotect_pkey (ptr, size,PROT_EXEC ,0 ); +pkey_assert (!err); + err =sys_mprotect_pkey (ptr, size,PROT_READ |PROT_WRITE ,0 ); +pkey_assert (!err); + err =sys_mprotect_pkey (ptr, size,PROT_READ |PROT_WRITE |PROT_EXEC ,0 ); +pkey_assert (!err); +} +void test_read_of_write_disabled_region (int *ptr,u16 pkey) {int ptr_contents;
@@ -1448,6 +1500,7 @@ void (*pkey_tests[])(int *ptr, u16 pkey) test_pkey_syscalls_on_non_allocated_pkey, test_pkey_syscalls_bad_args, test_pkey_alloc_exhaust, + test_pkey_alloc_free_attach_pkey0, };void run_tests_once (void )
_
Andrew Morton
maintainerPATCH 123/127 selftests/vm/pkeys: override access right definitions on powerpc
In reply to Andrew MortonFrom: Ram Pai <[email protected]>
Subject: selftests/vm/pkeys: override access right definitions on powerpc
Some platforms hardcode the x86 values for PKEY_DISABLE_ACCESS and PKEY_DISABLE_WRITE such as those in:
/usr/include/bits/mman-shared.h.
This overrides the definitions with correct values for powerpc.
---
tools/testing/selftests/vm/pkey-powerpc.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
tools/testing/selftests/vm/pkey-powerpc.h renamed from tools/testing/selftests/vm/pkey-powerpc.h~selftests-vm-pkeys-override-access-right-definitions-on-powerpc +4 -6
@@ -16,13 +16,11 @@#define fpregs fp_regs#define si_pkey_offset 0x20 -#ifndef PKEY_DISABLE_ACCESS -# define PKEY_DISABLE_ACCESS 0x3/* disable read and write */ -#endif +#undef PKEY_DISABLE_ACCESS +#define PKEY_DISABLE_ACCESS 0x3/* disable read and write */ -#ifndef PKEY_DISABLE_WRITE -# define PKEY_DISABLE_WRITE 0x2 -#endif +#undef PKEY_DISABLE_WRITE +#define PKEY_DISABLE_WRITE 0x2#define NR_PKEYS 32#define NR_RESERVED_PKEYS_4K 27/* pkey-0, pkey-1, exec-only-pkey
_
Andrew Morton
maintainerPATCH 124/127 selftests: vm: pkeys: use the correct page size on powerpc
In reply to Andrew MortonFrom: Sandipan Das <[email protected]>
Subject: selftests: vm: pkeys: use the correct page size on powerpc
Both 4K and 64K pages are supported on powerpc. Parts of the selftest code perform alignment computations based on the PAGE_SIZE macro which is currently hardcoded to 64K for powerpc. This causes some test failures on kernels configured with 4K page size.
In some cases, we need to enforce function alignment on page size. Since this can only be done at build time, 64K is used as the alignment factor as that also ensures 4K alignment.
---
tools/testing/selftests/vm/pkey-powerpc.h | 2 +- tools/testing/selftests/vm/protection_keys.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/vm/pkey-powerpc.h renamed from tools/testing/selftests/vm/pkey-powerpc.h~selftests-vm-pkeys-use-the-correct-page-size-on-powerpc +1 -1
@@ -32,7 +32,7 @@pkey-31 and exec-only key */ #define PKEY_BITS_PER_PKEY 2#define HPAGE_SIZE (1UL << 24) -#define PAGE_SIZE (1UL << 16) +#define PAGE_SIZE sysconf(_SC_PAGESIZE)static inline u32 pkey_bit_position (int pkey) {
tools/testing/selftests/vm/protection_keys.c renamed from tools/testing/selftests/vm/protection_keys.c~selftests-vm-pkeys-use-the-correct-page-size-on-powerpc +5 -0
@@ -146,7 +146,12 @@ void abort_hooks(void)* will then fault, which makes sure that the fault code handles * execute-only memory properly. */ +#ifdef __powerpc64__ +/* This way, both 4K and 64K alignment are maintained */ +__attribute__((__aligned__ (65536 ))) +#else __attribute__((__aligned__ (PAGE_SIZE ))) +#endifvoid lots_o_noops_around_write (int *write_to_me) {dprintf3 ("running %s()\n" , __func__);
_
Andrew Morton
maintainerPATCH 125/127 selftests: vm: pkeys: fix multilib builds for x86
In reply to Andrew MortonFrom: Sandipan Das <[email protected]>
Subject: selftests: vm: pkeys: fix multilib builds for x86
This ensures that both 32-bit and 64-bit binaries are generated when this is built on a x86_64 system. Most of the changes have been borrowed from tools/testing/selftests/x86/Makefile.
---
tools/testing/selftests/vm/Makefile | 74 +++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-)
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-vm-pkeys-fix-multilib-builds-for-x86 +73 -1
@@ -15,7 +15,6 @@ TEST_GEN_FILES += map_fixed_noreplace TEST_GEN_FILES += map_populate TEST_GEN_FILES += mlock-random-test TEST_GEN_FILES += mlock2-tests -TEST_GEN_FILES += protection_keys TEST_GEN_FILES += mremap_dontunmap TEST_GEN_FILES += on-fault-limit TEST_GEN_FILES += thuge-gen
@@ -23,6 +22,30 @@ TEST_GEN_FILES += transhuge-stress TEST_GEN_FILES += userfaultfd TEST_GEN_FILES += khugepaged +ifeq ($(ARCH),x86_64) +CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh $(CC) ../x86/trivial_32bit_program.c -m32) +CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh $(CC) ../x86/trivial_64bit_program.c) +CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh $(CC) ../x86/trivial_program.c -no-pie) + +TARGETS := protection_keys +BINARIES_32 := $(TARGETS:%=%_32) +BINARIES_64 := $(TARGETS:%=%_64) + +ifeq ($(CAN_BUILD_WITH_NOPIE),1) +CFLAGS += -no-pie +endif + +ifeq ($(CAN_BUILD_I386),1) +TEST_GEN_FILES += $(BINARIES_32) +endif + +ifeq ($(CAN_BUILD_X86_64),1) +TEST_GEN_FILES += $(BINARIES_64) +endif +else +TEST_GEN_FILES += protection_keys +endif + ifneq (,$(filter $(MACHINE),arm64 ia64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sh64 sparc64 x86_64)) TEST_GEN_FILES += va_128TBswitch TEST_GEN_FILES += virtual_address_range
@@ -38,6 +61,55 @@ include ../lib.mk $(OUTPUT)/hmm-tests: LDLIBS += -lhugetlbfs -lpthread +ifeq ($(ARCH),x86_64) +BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) +BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) + +define gen-target-rule-32 +$(1) $(1)_32: $(OUTPUT)/$(1)_32 +.PHONY: $(1) $(1)_32 +endef + +define gen-target-rule-64 +$(1) $(1)_64: $(OUTPUT)/$(1)_64 +.PHONY: $(1) $(1)_64 +endef + +ifeq ($(CAN_BUILD_I386),1) +$(BINARIES_32): CFLAGS += -m32 +$(BINARIES_32): LDLIBS += -lrt -ldl -lm +$(BINARIES_32): %_32: %.c + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ +$(foreach t,$(TARGETS),$(eval $(call gen-target-rule-32,$(t)))) +endif + +ifeq ($(CAN_BUILD_X86_64),1) +$(BINARIES_64): CFLAGS += -m64 +$(BINARIES_64): LDLIBS += -lrt -ldl +$(BINARIES_64): %_64: %.c + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(notdir $^) $(LDLIBS) -o $@ +$(foreach t,$(TARGETS),$(eval $(call gen-target-rule-64,$(t)))) +endif + +# x86_64 users should be encouraged to install 32-bit libraries +ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01) +all: warn_32bit_failure + +warn_32bit_failure: + @echo "Warning: you seem to have a broken 32-bit build" 2>&1; \ + echo "environment. This will reduce test coverage of 64-bit" 2>&1; \ + echo "kernels. If you are using a Debian-like distribution," 2>&1; \ + echo "try:"; 2>&1; \ + echo ""; \ + echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ + echo ""; \ + echo "If you are using a Fedora-like distribution, try:"; \ + echo ""; \ + echo " yum install glibc-devel.*i686"; \ + exit 0; +endif +endif + $(OUTPUT)/userfaultfd: LDLIBS += -lpthread $(OUTPUT)/mlock-random-test: LDLIBS += -lcap
_
Andrew Morton
maintainerPATCH 126/127 tools/testing/selftests/vm: remove duplicate headers
In reply to Andrew MortonFrom: Jagadeesh Pagadala <[email protected]>
Subject: tools/testing/selftests/vm: remove duplicate headers
Code cleanup: Remove duplicate headers which are included twice.
---
tools/testing/selftests/vm/mremap_dontunmap.c | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/vm/mremap_dontunmap.c renamed from tools/testing/selftests/vm/mremap_dontunmap.c~tools-testing-selftests-vm-remove-duplicate-headers +0 -1
@@ -11,7 +11,6 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdlib.h> #include <unistd.h> #include "../kselftest.h"
_
Andrew Morton
maintainerPATCH 127/127 lib/ubsan.c: fix gcc-10 warnings
In reply to Andrew MortonFrom: Arnd Bergmann <[email protected]>
Subject: lib/ubsan.c: fix gcc-10 warnings
The latest compiler expects slightly different function prototypes for the ubsan helpers:
lib/ubsan.c:192:6: error: conflicting types for built-in function '__ubsan_handle_add_overflow'; expected 'void(void *, void *, void *)' [-Werror=builtin-declaration-mismatch]
192 | void __ubsan_handle_add_overflow(struct overflow_data *data,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/ubsan.c:200:6: error: conflicting types for built-in function '__ubsan_handle_sub_overflow'; expected 'void(void *, void *, void *)' [-Werror=builtin-declaration-mismatch]
200 | void __ubsan_handle_sub_overflow(struct overflow_data *data,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/ubsan.c:207:6: error: conflicting types for built-in function '__ubsan_handle_mul_overflow'; expected 'void(void *, void *, void *)' [-Werror=builtin-declaration-mismatch]
207 | void __ubsan_handle_mul_overflow(struct overflow_data *data,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/ubsan.c:214:6: error: conflicting types for built-in function '__ubsan_handle_negate_overflow'; expected 'void(void *, void *)' [-Werror=builtin-declaration-mismatch]
214 | void __ubsan_handle_negate_overflow(struct overflow_data *data,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/ubsan.c:234:6: error: conflicting types for built-in function '__ubsan_handle_divrem_overflow'; expected 'void(void *, void *, void *)' [-Werror=builtin-declaration-mismatch]
234 | void __ubsan_handle_divrem_overflow(struct overflow_data *data,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Change the Linux implementation to match these, using a local typed pointer.
---
lib/ubsan.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
lib/ubsan.c renamed from lib/ubsan.c~ubsan-fix-gcc-10-warnings +17 -16
@@ -189,7 +189,7 @@ static void handle_overflow(struct overfubsan_epilogue (); } -void __ubsan_handle_add_overflow (struct overflow_data *data, +void __ubsan_handle_add_overflow (void *data,void *lhs,void *rhs) {
@@ -197,23 +197,23 @@ void __ubsan_handle_add_overflow(struct }EXPORT_SYMBOL (__ubsan_handle_add_overflow); -void __ubsan_handle_sub_overflow (struct overflow_data *data, +void __ubsan_handle_sub_overflow (void *data,void *lhs,void *rhs) {handle_overflow (data, lhs, rhs,'-' ); }EXPORT_SYMBOL (__ubsan_handle_sub_overflow); -void __ubsan_handle_mul_overflow (struct overflow_data *data, +void __ubsan_handle_mul_overflow (void *data,void *lhs,void *rhs) {handle_overflow (data, lhs, rhs,'*' ); }EXPORT_SYMBOL (__ubsan_handle_mul_overflow); -void __ubsan_handle_negate_overflow (struct overflow_data *data, -void *old_val) +void __ubsan_handle_negate_overflow (void *_data,void *old_val) { +struct overflow_data *data = _data;char old_val_str[VALUE_LENGTH ];if (suppress_report (&data->location))
@@ -231,9 +231,9 @@ void __ubsan_handle_negate_overflow(struEXPORT_SYMBOL (__ubsan_handle_negate_overflow); -void __ubsan_handle_divrem_overflow (struct overflow_data *data, -void *lhs,void *rhs) +void __ubsan_handle_divrem_overflow (void *_data,void *lhs,void *rhs) { +struct overflow_data *data = _data;char rhs_val_str[VALUE_LENGTH ];if (suppress_report (&data->location))
@@ -326,10 +326,9 @@ void __ubsan_handle_type_mismatch(struct }EXPORT_SYMBOL (__ubsan_handle_type_mismatch); -void __ubsan_handle_type_mismatch_v1 (struct type_mismatch_data_v1 *data, -void *ptr) +void __ubsan_handle_type_mismatch_v1 (void *_data,void *ptr) { - +struct type_mismatch_data_v1 *data = _data;struct type_mismatch_data_common common_data = { .location = &data->location, .type = data->type,
@@ -341,8 +340,9 @@ void __ubsan_handle_type_mismatch_v1(str }EXPORT_SYMBOL (__ubsan_handle_type_mismatch_v1); -void __ubsan_handle_out_of_bounds (struct out_of_bounds_data *data,void *index) +void __ubsan_handle_out_of_bounds (void *_data,void *index) { +struct out_of_bounds_data *data = _data;char index_str[VALUE_LENGTH ];if (suppress_report (&data->location))
@@ -357,9 +357,9 @@ void __ubsan_handle_out_of_bounds(struct }EXPORT_SYMBOL (__ubsan_handle_out_of_bounds); -void __ubsan_handle_shift_out_of_bounds (struct shift_out_of_bounds_data *data, -void *lhs,void *rhs) +void __ubsan_handle_shift_out_of_bounds (void *_data,void *lhs,void *rhs) { +struct shift_out_of_bounds_data *data = _data;struct type_descriptor *rhs_type = data->rhs_type;struct type_descriptor *lhs_type = data->lhs_type;char rhs_str[VALUE_LENGTH ];
@@ -399,8 +399,9 @@ out:EXPORT_SYMBOL (__ubsan_handle_shift_out_of_bounds); -void __ubsan_handle_builtin_unreachable (struct unreachable_data *data) +void __ubsan_handle_builtin_unreachable (void *_data) { +struct unreachable_data *data = _data;ubsan_prologue (&data->location,"unreachable" );pr_err ("calling __builtin_unreachable()\n" );ubsan_epilogue ();
@@ -408,9 +409,9 @@ void __ubsan_handle_builtin_unreachable( }EXPORT_SYMBOL (__ubsan_handle_builtin_unreachable); -void __ubsan_handle_load_invalid_value (struct invalid_value_data *data, -void *val) +void __ubsan_handle_load_invalid_value (void *_data,void *val) { +struct invalid_value_data *data = _data;char val_str[VALUE_LENGTH ];if (suppress_report (&data->location))
_
+ lib-test-get_count_order-long-in-test_bitopsc-fix.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: lib-test-get_count_order-long-in-test_bitopsc-fix has been added to the -mm tree. Its filename is lib-test-get_count_order-long-in-test_bitopsc-fix.patch
The patch titled
Subject: lib-test-get_count_order-long-in-test_bitopsc-fix
has been added to the -mm tree. Its filename is
lib-test-get_count_order-long-in-test_bitopsc-fix.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/lib-test-get_count_order-long-in-test_bitopsc-fix.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/lib-test-get_count_order-long-in-test_bitopsc-fix.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrew Morton <[email protected]>
Subject: lib-test-get_count_order-long-in-test_bitopsc-fix
- use order_comb[] to test get_count_order_long() as well, per Geert
- avoid warnings on 32-bit, reported by Geert
- coding-style cleanups
---
lib/test_bitops.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
lib/test_bitops.c renamed from lib/test_bitops.c~lib-test-get_count_order-long-in-test_bitopsc-fix +17 -6
@@ -28,7 +28,7 @@ enum bitops_fun { static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH); -unsigned int order_comb[][2 ] = { +static unsigned int order_comb[][2 ] = { {0x00000003 ,2 }, {0x00000004 ,2 }, {0x00001fff ,13 },
@@ -38,7 +38,8 @@ unsigned int order_comb[][2] = { {0x80003000, 32}, }; -unsigned long order_comb_long[][2 ] = { +#ifdef CONFIG_64BIT +static unsigned long order_comb_long[][2 ] = { {0x0000000300000000 ,34 }, {0x0000000400000000 ,34 }, {0x00001fff00000000, 45},
@@ -47,6 +48,7 @@ unsigned long order_comb_long[][2] = { {0x8000000000000000, 63}, {0x8000300000000000, 64}, }; +#endif static int __init test_bitops_startup(void) {
@@ -62,14 +64,23 @@ static int __init test_bitops_startup(vofor (i =0 ; i <ARRAY_SIZE (order_comb); i++) {if (order_comb[i][1 ] !=get_count_order (order_comb[i][0 ]))pr_warn ("get_count_order wrong for %x\n" , - order_comb[i][0 ]); } + order_comb[i][0 ]); + } -for (i =0 ; i <ARRAY_SIZE (order_comb_long); i++) { +for (i =0 ; i <ARRAY_SIZE (order_comb); i++) { +if (order_comb[i][1 ] !=get_count_order_long (order_comb[i][0 ])) +pr_warn ("get_count_order_long wrong for %x\n" , + order_comb[i][0 ]); + } + +#ifdef CONFIG_64BIT +for (i =0 ; i <ARRAY_SIZE (order_comb); i++) {if (order_comb_long[i][1 ] !=get_count_order_long (order_comb_long[i][0 ]))pr_warn ("get_count_order_long wrong for %lx\n" , - order_comb_long[i][0 ]); } - + order_comb_long[i][0 ]); + } +#endif return 0 ; }
_
Patches currently in -mm which might be from [email protected] are
drivers-tty-serial-sh-scic-suppress-uninitialized-var-warning.patch mm.patch
lib-test-get_count_order-long-in-test_bitopsc-fix.patch ipc-convert-ipcs_idr-to-xarray-update-fix.patch linux-next-git-rejects.patch
kernel-add-panic_on_taint-fix.patch mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix.patch mmap-locking-api-convert-mmap_sem-call-sites-missed-by-coccinelle-fix.patch mmap-locking-api-convert-mmap_sem-call-sites-missed-by-coccinelle-fix-fix.patch mmap-locking-api-convert-mmap_sem-call-sites-missed-by-coccinelle-fix-fix-fix.patch mmap-locking-api-rename-mmap_sem-to-mmap_lock-fix.patch mmap-locking-api-convert-mmap_sem-comments-fix.patch mmap-locking-api-convert-mmap_sem-comments-fix-fix.patch mmap-locking-api-convert-mmap_sem-comments-fix-fix-fix.patch mm-pass-task-and-mm-to-do_madvise.patch mm-introduce-external-memory-hinting-api-fix-2-fix.patch mm-support-vector-address-ranges-for-process_madvise-fix-fix-fix-fix-fix.patch maccess-unify-the-probe-kernel-arch-hooks-fix.patch bpf-bpf_seq_printf-handle-potentially-unsafe-format-string-better.patch maccess-always-use-strict-semantics-for-probe_kernel_read-fix.patch x86-use-non-set_fs-based-maccess-routines-checkpatch-fixes.patch doc-cgroup-update-note-about-conditions-when-oom-killer-is-invoked-fix.patch kernel-forkc-export-kernel_thread-to-modules.patch
+ checkpatch-add-test-for-possible-misuse-of-is_enabled-without-config_.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: checkpatch: add test for possible misuse of IS_ENABLED() without CONFIG_ has been added to the -mm tree. Its filename is…
The patch titled
Subject: checkpatch: add test for possible misuse of IS_ENABLED() without CONFIG_
has been added to the -mm tree. Its filename is
checkpatch-add-test-for-possible-misuse-of-is_enabled-without-config_.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/checkpatch-add-test-for-possible-misuse-of-is_enabled-without-config_.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/checkpatch-add-test-for-possible-misuse-of-is_enabled-without-config_.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Joe Perches <[email protected]>
Subject: checkpatch: add test for possible misuse of IS_ENABLED() without CONFIG_
IS_ENABLED is almost always used with CONFIG_<FOO> defines.
Add a test to verify that the #define being tested starts with CONFIG_.
---
scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/checkpatch.pl renamed from scripts/checkpatch.pl~checkpatch-add-test-for-possible-misuse-of-is_enabled-without-config_ +6 -0
@@ -6472,6 +6472,12 @@ sub process { } } +# check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too) + if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^CONFIG_/) { + WARN("IS_ENABLED_CONFIG", + "IS_ENABLED($1) is normally used as IS_ENABLED(CONFIG_$1)\n" . $herecurr); + } + # check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) { my $config = $1;
_
Patches currently in -mm which might be from [email protected] are
checkpatch-test-git_dir-changes.patch checkpatch-add-test-for-possible-misuse-of-is_enabled-without-config_.patch
[to-be-updated] exec-change-uselib2-is_sreg-failure-to-eacces.patch removed from -mm tree
In reply to Andrew MortonThe patch titled Subject: exec: change uselib(2) IS_SREG() failure to EACCES has been removed from the -mm tree. Its filename was exec-change-uselib2-is_sreg-failure-to-eacces.patch
The patch titled
Subject: exec: change uselib(2) IS_SREG() failure to EACCES
has been removed from the -mm tree. Its filename was
exec-change-uselib2-is_sreg-failure-to-eacces.patch
This patch was dropped because an updated version will be merged
------------------------------------------------------
From: Kees Cook <[email protected]>
Subject: exec: change uselib(2) IS_SREG() failure to EACCES
Patch series "Relocate execve() sanity checks".
While looking at the code paths for the proposed O_MAYEXEC flag, I saw some things that looked like they should be fixed up.
exec: Change uselib(2) IS_SREG() failure to EACCES
This just regularizes the return code on uselib(2).
exec: Relocate S_ISREG() check
This moves the S_ISREG() check even earlier than it was already.
exec: Relocate path_noexec() check
This adds the path_noexec() check to the same place as the S_ISREG() check.
fs: Include FMODE_EXEC when converting flags to f_mode
This seemed like an oversight, but I suspect there is some reason I couldn't find for why FMODE_EXEC doesn't get set in f_mode and just stays in f_flags.
This patch (of 4):
Change uselib(2)' S_ISREG() error return to EACCES instead of EINVAL so the behavior matches execve(2), and the seemingly documented value. The "not a regular file" failure mode of execve(2) is explicitly documented[1], but it is not mentioned in uselib(2)[2] which does, however, say that open(2) and mmap(2) errors may apply. The documentation for open(2) does not include a "not a regular file" error[3], but mmap(2) does[4], and it is EACCES.
[1] http://man7.org/linux/man-pages/man2/execve.2.html#ERRORS
[2] http://man7.org/linux/man-pages/man2/uselib.2.html#ERRORS
[3] http://man7.org/linux/man-pages/man2/open.2.html#ERRORS
[4] http://man7.org/linux/man-pages/man2/mmap.2.html#ERRORS
---
fs/exec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/exec.c renamed from fs/exec.c~exec-change-uselib2-is_sreg-failure-to-eacces +1 -2
@@ -141,11 +141,10 @@ SYSCALL_DEFINE1(uselib, const char __useif (IS_ERR (file)) goto out; - error = -EINVAL ; + error = -EACCES ;if (!S_ISREG (file_inode (file)->i_mode)) goto exit; - error = -EACCES ;if (path_noexec (&file->f_path)) goto exit;
_
Patches currently in -mm which might be from [email protected] are
exec-relocate-s_isreg-check.patch exec-relocate-path_noexec-check.patch fs-include-fmode_exec-when-converting-flags-to-f_mode.patch
[to-be-updated] exec-relocate-s_isreg-check.patch removed from -mm tree
In reply to Andrew MortonThe patch titled Subject: exec: relocate S_ISREG() check has been removed from the -mm tree. Its filename was exec-relocate-s_isreg-check.patch
The patch titled
Subject: exec: relocate S_ISREG() check
has been removed from the -mm tree. Its filename was
exec-relocate-s_isreg-check.patch
This patch was dropped because an updated version will be merged
------------------------------------------------------
From: Kees Cook <[email protected]>
Subject: exec: relocate S_ISREG() check
The execve(2)/uselib(2) syscalls have always rejected non-regular files. Recently, it was noticed that a deadlock was introduced when trying to execute pipes, as the S_ISREG() test was happening too late. This was fixed in commit 73601ea5b7b1 ("fs/open.c: allow opening only regular files during execve()"), but it was added after inode_permission() had already run, which meant LSMs could see bogus attempts to execute non-regular files. Move the test earlier.
Also include a comment with the redundant S_ISREG() checks at the end of execve(2)/uselib(2) to note that they are present to avoid any mistakes.
Finally, instead of dereferencing the inode, use dcache for S_ISREG() test.
My notes on the call path, and related arguments, checks, etc:
do_open_execat()
struct open_flags open_exec_flags = {
.open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC, ...
do_filp_open(dfd, filename, open_flags)
path_openat(nameidata, open_flags, flags)
/* f_mode populated from open_flags in alloc_empty_file() */
file = alloc_empty_file(open_flags, current_cred());
do_open(nameidata, file, open_flags)
/* new location of FMODE_EXEC vs S_ISREG() test */
may_open(path, acc_mode, open_flag)
inode_permission(inode, MAY_OPEN | acc_mode)
security_inode_permission(inode, acc_mode)
vfs_open(path, file)
do_dentry_open(file, path->dentry->d_inode, open)
/* old location of FMODE_EXEC vs S_ISREG() test */
security_file_open(f)
open()---
fs/exec.c | 8 ++++++++ fs/namei.c | 4 ++++ fs/open.c | 6 ------ 3 files changed, 12 insertions(+), 6 deletions(-)
fs/exec.c renamed from fs/exec.c~exec-relocate-s_isreg-check +8 -0
@@ -139,6 +139,10 @@ SYSCALL_DEFINE1(uselib, const char __useif (IS_ERR (file)) goto out; +/* +* do_open() has already checked for this, but we can be extra +* cautious and check again at the very end too. +*/ error = -EACCES ;if (!S_ISREG (file_inode (file)->i_mode)) goto exit;
@@ -884,6 +888,10 @@ static struct file *do_open_execat(int fif (IS_ERR (file)) goto out; +/* +* do_open() has already checked for this, but we can be extra +* cautious and check again at the very end too. +*/ err = -EACCES ;if (!S_ISREG (file_inode (file)->i_mode)) goto exit;
fs/namei.c renamed from fs/namei.c~exec-relocate-s_isreg-check +4 -0
@@ -3212,6 +3212,10 @@ static int do_open(struct nameidata *nd,if ((nd->flags &LOOKUP_DIRECTORY ) && !d_can_lookup (nd->path.dentry))return -ENOTDIR ; +/* Any file opened for execution has to be a regular file. */ +if ((file->f_flags &FMODE_EXEC ) && !d_is_reg (nd->path.dentry)) +return -EACCES ; + do_truncate = false; acc_mode = op->acc_mode;if (file->f_mode &FMODE_CREATED ) {
fs/open.c renamed from fs/open.c~exec-relocate-s_isreg-check +0 -5
@@ -784,12 +784,6 @@ static int do_dentry_open(struct file *freturn 0 ; } -/* Any file opened for execve()/uselib() has to be a regular file. */ -if (unlikely (f->f_flags &FMODE_EXEC && !S_ISREG (inode->i_mode))) { - error = -EACCES ; - goto cleanup_file; - }
[to-be-updated] exec-relocate-path_noexec-check.patch removed from -mm tree
In reply to Andrew MortonThe patch titled Subject: exec: relocate path_noexec() check has been removed from the -mm tree. Its filename was exec-relocate-path_noexec-check.patch
The patch titled
Subject: exec: relocate path_noexec() check
has been removed from the -mm tree. Its filename was
exec-relocate-path_noexec-check.patch
This patch was dropped because an updated version will be merged
------------------------------------------------------
From: Kees Cook <[email protected]>
Subject: exec: relocate path_noexec() check
The path_noexec() check, like the regular file check, was happening too late, letting LSMs see impossible execve()s. Check it earlier as well and collect the redundant fs/exec.c path_noexec() test under the same robustness comment as the S_ISREG() check.
My notes on the call path, and related arguments, checks, etc:
do_open_execat()
struct open_flags open_exec_flags = {
.open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC, ...
do_filp_open(dfd, filename, open_flags)
path_openat(nameidata, open_flags, flags)
/* f_mode populated from open_flags in alloc_empty_file() */
file = alloc_empty_file(open_flags, current_cred());
do_open(nameidata, file, open_flags)
/* new location of FMODE_EXEC vs path_noexec() test */
may_open(path, acc_mode, open_flag)
inode_permission(inode, MAY_OPEN | acc_mode)
security_inode_permission(inode, acc_mode)
vfs_open(path, file)
do_dentry_open(file, path->dentry->d_inode, open)
security_file_open(f)
open()
/* old location of path_noexec() test */---
fs/exec.c | 6 ++---- fs/namei.c | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-)
fs/exec.c renamed from fs/exec.c~exec-relocate-path_noexec-check +2 -3
@@ -140,13 +140,12 @@ SYSCALL_DEFINE1(uselib, const char __use goto out;/* -* do_open() has already checked for this, but we can be extra +* do_open() has already checked for these, but we can be extra * cautious and check again at the very end too. */ error = -EACCES ;if (!S_ISREG (file_inode (file)->i_mode)) goto exit; -if (path_noexec (&file->f_path)) goto exit;
@@ -889,13 +888,12 @@ static struct file *do_open_execat(int f goto out;/* -* do_open() has already checked for this, but we can be extra +* do_open() has already checked for these, but we can be extra * cautious and check again at the very end too. */ err = -EACCES ;if (!S_ISREG (file_inode (file)->i_mode)) goto exit;
[to-be-updated] fs-include-fmode_exec-when-converting-flags-to-f_mode.patch removed from -mm tree
In reply to Andrew MortonThe patch titled Subject: fs: include FMODE_EXEC when converting flags to f_mode has been removed from the -mm tree. Its filename was fs-include-fmode_exec-when-converting-flags-to-f_mode.patch
The patch titled
Subject: fs: include FMODE_EXEC when converting flags to f_mode
has been removed from the -mm tree. Its filename was
fs-include-fmode_exec-when-converting-flags-to-f_mode.patch
This patch was dropped because an updated version will be merged
------------------------------------------------------
From: Kees Cook <[email protected]>
Subject: fs: include FMODE_EXEC when converting flags to f_mode
Include FMODE_EXEC when building the f_mode field, so that code can actually test the correct field and values. Only three places actually examine f_flags for FMODE_EXEC:
fs/open.c: if (unlikely((f->f_mode & FMODE_EXEC) && !S_ISREG(inode->i_mode))) {
include/linux/fsnotify.h: if (file->f_mode & FMODE_EXEC) {
include/linux/fsnotify.h: if (file->f_mode & FMODE_EXEC)---
fs/namei.c | 4 ++-- include/linux/fs.h | 3 ++- include/linux/fsnotify.h | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-)
fs/namei.c renamed from fs/namei.c~fs-include-fmode_exec-when-converting-flags-to-f_mode +2 -2
@@ -3213,8 +3213,8 @@ static int do_open(struct nameidata *nd,return -ENOTDIR ;/* Opening for execution requires a regular file on an exec mnt. */ -if ((file->f_flags &FMODE_EXEC ) && (!d_is_reg (nd->path.dentry) || -path_noexec (&nd->path))) +if ((file->f_mode &FMODE_EXEC ) && (!d_is_reg (nd->path.dentry) || +path_noexec (&nd->path)))return -EACCES ; do_truncate = false;
include/linux/fs.h renamed from include/linux/fs.h~fs-include-fmode_exec-when-converting-flags-to-f_mode +2 -1
@@ -3564,10 +3564,11 @@ int __init get_filesystem_list(char *buf#define __FMODE_EXEC ((__force int) FMODE_EXEC)#define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY) +#define __SMUGGLED_FMODE_FLAGS (__FMODE_EXEC | __FMODE_NONOTIFY)#define ACC_MODE (x) ("\004\002\006\006"[(x)&O_ACCMODE])#define OPEN_FMODE (flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE) | \ - (flag & __FMODE_NONOTIFY))) + (flag & __SMUGGLED_FMODE_FLAGS)))static inline bool is_sxid (umode_t mode) {
include/linux/fsnotify.h renamed from include/linux/fsnotify.h~fs-include-fmode_exec-when-converting-flags-to-f_mode +2 -2
@@ -90,7 +90,7 @@ static inline int fsnotify_perm(struct fif (mask &MAY_OPEN ) { fsnotify_mask =FS_OPEN_PERM ; -if (file->f_flags & __FMODE_EXEC) { +if (file->f_mode &FMODE_EXEC ) { ret =fsnotify_file (file,FS_OPEN_EXEC_PERM );if (ret)
@@ -264,7 +264,7 @@ static inline void fsnotify_open(struct {__u32 mask =FS_OPEN ; -if (file->f_flags & __FMODE_EXEC) +if (file->f_mode &FMODE_EXEC ) mask |=FS_OPEN_EXEC ;fsnotify_file (file, mask);
_
Patches currently in -mm which might be from [email protected] are
+ exec-change-uselib2-is_sreg-failure-to-eacces.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: exec: change uselib(2) IS_SREG() failure to EACCES has been added to the -mm tree. Its filename is exec-change-uselib2-is_sreg-failure-to-eacces.patch
The patch titled
Subject: exec: change uselib(2) IS_SREG() failure to EACCES
has been added to the -mm tree. Its filename is
exec-change-uselib2-is_sreg-failure-to-eacces.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/exec-change-uselib2-is_sreg-failure-to-eacces.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/exec-change-uselib2-is_sreg-failure-to-eacces.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Kees Cook <[email protected]>
Subject: exec: change uselib(2) IS_SREG() failure to EACCES
Patch series "Relocate execve() sanity checks", v2.
While looking at the code paths for the proposed O_MAYEXEC flag, I saw some things that looked like they should be fixed up.
exec: Change uselib(2) IS_SREG() failure to EACCES
This just regularizes the return code on uselib(2).
exec: Move S_ISREG() check earlier
This moves the S_ISREG() check even earlier than it was already.
exec: Move path_noexec() check earlier
This adds the path_noexec() check to the same place as the S_ISREG() check.
This patch (of 3):
Change uselib(2)' S_ISREG() error return to EACCES instead of EINVAL so the behavior matches execve(2), and the seemingly documented value. The "not a regular file" failure mode of execve(2) is explicitly documented[1], but it is not mentioned in uselib(2)[2] which does, however, say that open(2) and mmap(2) errors may apply. The documentation for open(2) does not include a "not a regular file" error[3], but mmap(2) does[4], and it is EACCES.
[1] http://man7.org/linux/man-pages/man2/execve.2.html#ERRORS
[2] http://man7.org/linux/man-pages/man2/uselib.2.html#ERRORS
[3] http://man7.org/linux/man-pages/man2/open.2.html#ERRORS
[4] http://man7.org/linux/man-pages/man2/mmap.2.html#ERRORS
---
fs/exec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/exec.c renamed from fs/exec.c~exec-change-uselib2-is_sreg-failure-to-eacces +1 -2
@@ -141,11 +141,10 @@ SYSCALL_DEFINE1(uselib, const char __useif (IS_ERR (file)) goto out; - error = -EINVAL ; + error = -EACCES ;if (!S_ISREG (file_inode (file)->i_mode)) goto exit; - error = -EACCES ;if (path_noexec (&file->f_path)) goto exit;
_
Patches currently in -mm which might be from [email protected] are
exec-change-uselib2-is_sreg-failure-to-eacces.patch exec-move-s_isreg-check-earlier.patch exec-move-path_noexec-check-earlier.patch
+ exec-move-s_isreg-check-earlier.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: exec: move S_ISREG() check earlier has been added to the -mm tree. Its filename is exec-move-s_isreg-check-earlier.patch
The patch titled
Subject: exec: move S_ISREG() check earlier
has been added to the -mm tree. Its filename is
exec-move-s_isreg-check-earlier.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/exec-move-s_isreg-check-earlier.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/exec-move-s_isreg-check-earlier.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Kees Cook <[email protected]>
Subject: exec: move S_ISREG() check earlier
The execve(2)/uselib(2) syscalls have always rejected non-regular files. Recently, it was noticed that a deadlock was introduced when trying to execute pipes, as the S_ISREG() test was happening too late. This was fixed in commit 73601ea5b7b1 ("fs/open.c: allow opening only regular files during execve()"), but it was added after inode_permission() had already run, which meant LSMs could see bogus attempts to execute non-regular files.
Move the test into the other inode type checks (which already look for other pathological conditions[1]). Since there is no need to use FMODE_EXEC while we still have access to "acc_mode", also switch the test to MAY_EXEC.
Also include a comment with the redundant S_ISREG() checks at the end of execve(2)/uselib(2) to note that they are present to avoid any mistakes.
My notes on the call path, and related arguments, checks, etc:
do_open_execat()
struct open_flags open_exec_flags = {
.open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC, .acc_mode = MAY_EXEC,
...
do_filp_open(dfd, filename, open_flags)
path_openat(nameidata, open_flags, flags)
file = alloc_empty_file(open_flags, current_cred()); do_open(nameidata, file, open_flags)
may_open(path, acc_mode, open_flag)
/* new location of MAY_EXEC vs S_ISREG() test */ inode_permission(inode, MAY_OPEN | acc_mode)
security_inode_permission(inode, acc_mode)
vfs_open(path, file)
do_dentry_open(file, path->dentry->d_inode, open)
/* old location of FMODE_EXEC vs S_ISREG() test */ security_file_open(f)
open()
[1] https://lore.kernel.org/lkml/202006041910.9EF0C602@keescook/
---
fs/exec.c | 14 ++++++++++++-- fs/namei.c | 6 ++++-- fs/open.c | 6 ------ 3 files changed, 16 insertions(+), 10 deletions(-)
fs/exec.c renamed from fs/exec.c~exec-move-s_isreg-check-earlier +12 -2
@@ -141,8 +141,13 @@ SYSCALL_DEFINE1(uselib, const char __useif (IS_ERR (file)) goto out; +/* +* may_open() has already checked for this, so it should be +* impossible to trip now. But we need to be extra cautious +* and check again at the very end too. +*/ error = -EACCES ; -if (!S_ISREG (file_inode (file)->i_mode)) +if (WARN_ON_ONCE (!S_ISREG (file_inode (file)->i_mode))) goto exit;if (path_noexec (&file->f_path))
@@ -886,8 +891,13 @@ static struct file *do_open_execat(int fif (IS_ERR (file)) goto out; +/* +* may_open() has already checked for this, so it should be +* impossible to trip now. But we need to be extra cautious +* and check again at the very end too. +*/ err = -EACCES ; -if (!S_ISREG (file_inode (file)->i_mode)) +if (WARN_ON_ONCE (!S_ISREG (file_inode (file)->i_mode))) goto exit;if (path_noexec (&file->f_path))
fs/namei.c renamed from fs/namei.c~exec-move-s_isreg-check-earlier +4 -2
@@ -2835,16 +2835,18 @@ static int may_open(const struct path *pcase S_IFLNK :return -ELOOP ;case S_IFDIR : -if (acc_mode &MAY_WRITE ) +if (acc_mode & (MAY_WRITE |MAY_EXEC ))return -EISDIR ;break ;case S_IFBLK :case S_IFCHR :if (!may_open_dev (path))return -EACCES ; -/*FALLTHRU*/ + fallthrough;case S_IFIFO :case S_IFSOCK : +if (acc_mode &MAY_EXEC ) +return -EACCES ; flag &= ~O_TRUNC ;break ; }
fs/open.c renamed from fs/open.c~exec-move-s_isreg-check-earlier +0 -5
@@ -784,12 +784,6 @@ static int do_dentry_open(struct file *freturn 0 ; } -/* Any file opened for execve()/uselib() has to be a regular file. */ -if (unlikely (f->f_flags &FMODE_EXEC && !S_ISREG (inode->i_mode))) { - error = -EACCES ; - goto cleanup_file; - }
+ exec-move-path_noexec-check-earlier.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: exec: move path_noexec() check earlier has been added to the -mm tree. Its filename is exec-move-path_noexec-check-earlier.patch
The patch titled
Subject: exec: move path_noexec() check earlier
has been added to the -mm tree. Its filename is
exec-move-path_noexec-check-earlier.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/exec-move-path_noexec-check-earlier.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/exec-move-path_noexec-check-earlier.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Kees Cook <[email protected]>
Subject: exec: move path_noexec() check earlier
The path_noexec() check, like the regular file check, was happening too late, letting LSMs see impossible execve()s. Check it earlier as well in may_open() and collect the redundant fs/exec.c path_noexec() test under the same robustness comment as the S_ISREG() check.
My notes on the call path, and related arguments, checks, etc:
do_open_execat()
struct open_flags open_exec_flags = {
.open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC, .acc_mode = MAY_EXEC,
...
do_filp_open(dfd, filename, open_flags)
path_openat(nameidata, open_flags, flags)
file = alloc_empty_file(open_flags, current_cred()); do_open(nameidata, file, open_flags)
may_open(path, acc_mode, open_flag)
/* new location of MAY_EXEC vs path_noexec() test */ inode_permission(inode, MAY_OPEN | acc_mode)
security_inode_permission(inode, acc_mode)
vfs_open(path, file)
do_dentry_open(file, path->dentry->d_inode, open)
security_file_open(f)
open()
/* old location of path_noexec() test */
---
fs/exec.c | 12 ++++-------- fs/namei.c | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-)
fs/exec.c renamed from fs/exec.c~exec-move-path_noexec-check-earlier +2 -6
@@ -147,10 +147,8 @@ SYSCALL_DEFINE1(uselib, const char __use* and check again at the very end too. */ error = -EACCES ; -if (WARN_ON_ONCE (!S_ISREG (file_inode (file)->i_mode))) - goto exit; - -if (path_noexec (&file->f_path)) +if (WARN_ON_ONCE (!S_ISREG (file_inode (file)->i_mode) || +path_noexec (&file->f_path))) goto exit;fsnotify_open (file);
@@ -897,10 +895,8 @@ static struct file *do_open_execat(int f* and check again at the very end too. */ err = -EACCES ; -if (WARN_ON_ONCE (!S_ISREG (file_inode (file)->i_mode))) - goto exit;
+ khugepaged-selftests-fix-timeout-condition-in-wait_for_scan.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: khugepaged: selftests: fix timeout condition in wait_for_scan() has been added to the -mm tree. Its filename is…
The patch titled
Subject: khugepaged: selftests: fix timeout condition in wait_for_scan()
has been added to the -mm tree. Its filename is
khugepaged-selftests-fix-timeout-condition-in-wait_for_scan.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/khugepaged-selftests-fix-timeout-condition-in-wait_for_scan.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/khugepaged-selftests-fix-timeout-condition-in-wait_for_scan.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Dan Carpenter <[email protected]>
Subject: khugepaged: selftests: fix timeout condition in wait_for_scan()
The loop exits with "timeout" set to -1 and not to 0 so the test needs to be fixed.
---
tools/testing/selftests/vm/khugepaged.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/vm/khugepaged.c renamed from tools/testing/selftests/vm/khugepaged.c~khugepaged-selftests-fix-timeout-condition-in-wait_for_scan +1 -1
@@ -502,7 +502,7 @@ static bool wait_for_scan(const char *msmadvise (p, hpage_pmd_size,MADV_NOHUGEPAGE ); -return !timeout; +return timeout ==-1 ; }static void alloc_at_fault (void )
_
Patches currently in -mm which might be from [email protected] are
khugepaged-selftests-fix-timeout-condition-in-wait_for_scan.patch
+ scripts-spelling-add-a-few-more-typos.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: scripts/spelling: add a few more typos has been added to the -mm tree. Its filename is scripts-spelling-add-a-few-more-typos.patch
The patch titled
Subject: scripts/spelling: add a few more typos
has been added to the -mm tree. Its filename is
scripts-spelling-add-a-few-more-typos.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/scripts-spelling-add-a-few-more-typos.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/scripts-spelling-add-a-few-more-typos.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: SeongJae Park <[email protected]>
Subject: scripts/spelling: add a few more typos
This commit adds typos I found from another work.
---
scripts/spelling.txt | 9 +++++++++ 1 file changed, 9 insertions(+)
scripts/spelling.txt renamed from scripts/spelling.txt~scripts-spelling-add-a-few-more-typos +9 -0
@@ -59,6 +59,7 @@ actualy||actually acumulating||accumulating acumulative||accumulative acumulator||accumulator +acutally||actually adapater||adapter addional||additional additionaly||additionally
@@ -249,6 +250,7 @@ calescing||coalescing calle||called callibration||calibration callled||called +callser||caller calucate||calculate calulate||calculate cancelation||cancellation
@@ -671,6 +673,7 @@ hanlde||handle hanled||handled happend||happened harware||hardware +havind||having heirarchically||hierarchically helpfull||helpful hexdecimal||hexadecimal
@@ -845,6 +848,7 @@ logile||logfile loobpack||loopback loosing||losing losted||lost +maangement||management machinary||machinery maibox||mailbox maintainance||maintenance
@@ -905,6 +909,7 @@ modfiy||modify modulues||modules momery||memory memomry||memory +monitring||monitoring monochorome||monochrome monochromo||monochrome monocrome||monochrome
@@ -1010,6 +1015,7 @@ partiton||partition pased||passed passin||passing pathes||paths +pattrns||patterns pecularities||peculiarities peformance||performance peforming||performing
@@ -1256,6 +1262,7 @@ shoule||should shrinked||shrunk siginificantly||significantly signabl||signal +significanly||significantly similary||similarly similiar||similar simlar||similar
@@ -1371,6 +1378,7 @@ thead||thread therfore||therefore thier||their threds||threads +threee||three threshhold||threshold thresold||threshold throught||through
@@ -1410,6 +1418,7 @@ tyep||type udpate||update uesd||used uknown||unknown +usccess||success usupported||unsupported uncommited||uncommitted unconditionaly||unconditionally
_
Patches currently in -mm which might be from [email protected] are
scripts-spelling-add-a-few-more-typos.patch
+ mm-page_idlec-skip-offline-pages.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm/page_idle.c: Skip offline pages has been added to the -mm tree. Its filename is mm-page_idlec-skip-offline-pages.patch
The patch titled
Subject: mm/page_idle.c: Skip offline pages
has been added to the -mm tree. Its filename is
mm-page_idlec-skip-offline-pages.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-page_idlec-skip-offline-pages.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-page_idlec-skip-offline-pages.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: SeongJae Park <[email protected]>
Subject: mm/page_idle.c: Skip offline pages
'Idle page tracking' users can pass random pfn that might be mapped to an offline page. To avoid accessing such pages, this commit modifies the 'page_idle_get_page()' to use 'pfn_to_online_page()' instead of 'pfn_valid()' and 'pfn_to_page()' combination, so that the pfn mapped to an offline page can be skipped.
---
mm/page_idle.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
mm/page_idle.c renamed from mm/page_idle.c~mm-page_idlec-skip-offline-pages +2 -3
@@ -4,6 +4,7 @@#include <linux/fs.h> #include <linux/sysfs.h> #include <linux/kobject.h> +#include <linux/memory_hotplug.h> #include <linux/mm.h> #include <linux/mmzone.h> #include <linux/pagemap.h>
@@ -30,13 +31,9 @@*/ static struct page *page_idle_get_page (unsigned long pfn) { -struct page *page; +struct page *page =pfn_to_online_page (pfn);pg_data_t *pgdat; -if (!pfn_valid (pfn)) -return NULL ;
+ nilfs2-fix-null-pointer-dereference-at-nilfs_segctor_do_construct.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: nilfs2: fix null pointer dereference at nilfs_segctor_do_construct() has been added to the -mm tree. Its filename is…
The patch titled
Subject: nilfs2: fix null pointer dereference at nilfs_segctor_do_construct()
has been added to the -mm tree. Its filename is
nilfs2-fix-null-pointer-dereference-at-nilfs_segctor_do_construct.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/nilfs2-fix-null-pointer-dereference-at-nilfs_segctor_do_construct.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/nilfs2-fix-null-pointer-dereference-at-nilfs_segctor_do_construct.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Ryusuke Konishi <[email protected]>
Subject: nilfs2: fix null pointer dereference at nilfs_segctor_do_construct()
After commit c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages"), the following null pointer dereference has been reported on nilfs2:
BUG: kernel NULL pointer dereference, address: 00000000000000a8 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: 0000 [#1] SMP PTI ... RIP: 0010:percpu_counter_add_batch+0xa/0x60 ... Call Trace: __test_set_page_writeback+0x2d3/0x330 nilfs_segctor_do_construct+0x10d3/0x2110 [nilfs2] nilfs_segctor_construct+0x168/0x260 [nilfs2] nilfs_segctor_thread+0x127/0x3b0 [nilfs2] kthread+0xf8/0x130 ...
This crash turned out to be caused by set_page_writeback() call for segment summary buffers at nilfs_segctor_prepare_write().
set_page_writeback() can call inc_wb_stat(inode_to_wb(inode), WB_WRITEBACK) where inode_to_wb(inode) is NULL if the inode of underlying block device does not have an associated wb.
This fixes the issue by calling inode_attach_wb() in advance to ensure to associate the bdev inode with its wb.
---
fs/nilfs2/segment.c | 2 ++ 1 file changed, 2 insertions(+)
fs/nilfs2/segment.c renamed from fs/nilfs2/segment.c~nilfs2-fix-null-pointer-dereference-at-nilfs_segctor_do_construct +2 -0
@@ -2780,6 +2780,8 @@ int nilfs_attach_log_writer(struct superif (!nilfs->ns_writer)return -ENOMEM ; +inode_attach_wb (nilfs->ns_bdev->bd_inode,NULL ); + err =nilfs_segctor_start_thread (nilfs->ns_writer);if (err) {kfree (nilfs->ns_writer);
_
Patches currently in -mm which might be from [email protected] are
nilfs2-fix-null-pointer-dereference-at-nilfs_segctor_do_construct.patch
+ mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3 has been added to the -mm tree. Its filename is mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3.patch
The patch titled
Subject: mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3
has been added to the -mm tree. Its filename is
mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Stephen Rothwell <[email protected]>
Subject: mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3
Fix powerpc build
---
arch/powerpc/include/asm/nohash/32/pgtable.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/nohash/32/pgtable.h renamed from arch/powerpc/include/asm/nohash/32/pgtable.h~mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3 +4 -1
@@ -205,6 +205,9 @@ static inline void pmd_clear(pmd_t *pmdp *pmdp =__pmd (0 ); } +/* to find an entry in a page-table-directory */ +#define pgd_index (address) ((address) >> PGDIR_SHIFT) +#define pgd_offset (mm, address) ((mm)->pgd + pgd_index(address))/* * PTE updates. This function is called whenever an existing
@@ -234,7 +237,7 @@ static inline pte_basic_t pte_update(strpte_basic_t old =pte_val (*p);pte_basic_t new = (old & ~(pte_basic_t )clr) | set;int num, i; -pmd_t *pmd =pmd_offset (pud_offset (pgd_offset (mm, addr), addr), addr); +pmd_t *pmd =pmd_offset (pud_offset (p4d_offset (pgd_offset (mm, addr), addr), addr), addr);if (!huge) num =PAGE_SIZE /SZ_4K ;
_
Patches currently in -mm which might be from [email protected] are
kernel-better-document-the-use_mm-unuse_mm-api-contract-v2-fix.patch kernel-better-document-the-use_mm-unuse_mm-api-contract-fix-2.patch mm-consolidate-pgd_index-and-pgd_offset_k-definitions-fix-3.patch maccess-unexport-probe_kernel_write-and-probe_user_write-fix.patch
+ tracing-kprobes-handle-mixed-kernel-userspace-probes-better-fix.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: kprobes: use strncpy_from_kernel_nofault() in fetch_store_string() has been added to the -mm tree. Its filename is…
The patch titled
Subject: kprobes: use strncpy_from_kernel_nofault() in fetch_store_string()
has been added to the -mm tree. Its filename is
tracing-kprobes-handle-mixed-kernel-userspace-probes-better-fix.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/tracing-kprobes-handle-mixed-kernel-userspace-probes-better-fix.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/tracing-kprobes-handle-mixed-kernel-userspace-probes-better-fix.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Sven Schnelle <[email protected]>
Subject: kprobes: use strncpy_from_kernel_nofault() in fetch_store_string()
With the latest linux-next i noticed that some tests in the ftrace test suites are failing on s390, namely:
[FAIL] Kprobe event symbol argument
[FAIL] Kprobe event with comm arguments
The following doesn't work anymore:
cd /sys/kernel/tracing
echo 'p:testprobe _do_fork comm=$comm ' >kprobe_events echo 1 >events/kprobes/testprobe/enable
cat trace
it will just show
test.sh-519 [012] .... 18.580625: testprobe: (_do_fork+0x0/0x3c8) comm=(fault)
Looking at the source i see that there are two helpers for reading strings:
fetch_store_string_user() -> read string from user space fetch_store_string() -> read string from kernel space(?)
but in the end both are using strncpy_from_user_nofault(), but fetch_store_string() should use strncpy_from_kernel_nofault().
---
kernel/trace/trace_kprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_kprobe.c renamed from kernel/trace/trace_kprobe.c~tracing-kprobes-handle-mixed-kernel-userspace-probes-better-fix +1 -1
@@ -1278,7 +1278,7 @@ fetch_store_string(unsigned long addr, v* Try to get string again, since the string can be changed while * probing. */ - ret =strncpy_from_user_nofault (__dest, (void *)addr, maxlen); + ret =strncpy_from_kernel_nofault (__dest, (void *)addr, maxlen);if (ret >=0 ) *(u32 *)dest =make_data_loc (ret, __dest - base);
_
Patches currently in -mm which might be from [email protected] are
tracing-kprobes-handle-mixed-kernel-userspace-probes-better-fix.patch
+ docs-mm-gup-pin_user_pagesrst-add-a-case-5-v2.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: docs: mm/gup: pin_user_pages.rst: add a "case 5" has been added to the -mm tree. Its filename is
The patch titled
Subject: docs: mm/gup: pin_user_pages.rst: add a "case 5"
has been added to the -mm tree. Its filename is
docs-mm-gup-pin_user_pagesrst-add-a-case-5-v2.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/docs-mm-gup-pin_user_pagesrst-add-a-case-5-v2.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/docs-mm-gup-pin_user_pagesrst-add-a-case-5-v2.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: John Hubbard <[email protected]>
Subject: docs: mm/gup: pin_user_pages.rst: add a "case 5"
There are four cases listed in pin_user_pages.rst. These are intended to help developers figure out whether to use get_user_pages*(), or pin_user_pages*(). However, the four cases do not cover all the situations. For example, drivers/vhost/vhost.c has a "pin, write to page, set page dirty, unpin" case.
Add a fifth case, to help explain that there is a general pattern that requires pin_user_pages*() API calls.
---
Documentation/core-api/pin_user_pages.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
Documentation/core-api/pin_user_pages.rst renamed from Documentation/core-api/pin_user_pages.rst~docs-mm-gup-pin_user_pagesrst-add-a-case-5-v2 +3 -5
@@ -174,21 +174,19 @@ needs to be set. CASE 5: Pinning in order to write to the data within the page ------------------------------------------------------------- Even though neither DMA nor Direct IO is involved, just a simple case of "pin, -access page's data, unpin" can cause a problem. Case 5 may be considered a +write to a page's data, unpin" can cause a problem. Case 5 may be considered a superset of Case 1, plus Case 2, plus anything that invokes that pattern. In other words, if the code is neither Case 1 nor Case 2, it may still require FOLL_PIN, for patterns like this: Correct (uses FOLL_PIN calls): pin_user_pages() - access the data within the pages - set_page_dirty_lock() + write to the data within the pages unpin_user_pages() INCORRECT (uses FOLL_GET calls): get_user_pages() - access the data within the pages - set_page_dirty_lock() + write to the data within the pages put_page() page_maybe_dma_pinned(): the whole point of pinning
_
Patches currently in -mm which might be from [email protected] are
mm-gup-update-pin_user_pagesrst-for-case-3-mmu-notifiers.patch mm-gup-introduce-pin_user_pages_locked.patch mm-gup-introduce-pin_user_pages_locked-v2.patch mm-gup-frame_vector-convert-get_user_pages-pin_user_pages.patch mm-gup-documentation-fix-for-pin_user_pages-apis.patch docs-mm-gup-pin_user_pagesrst-add-a-case-5.patch docs-mm-gup-pin_user_pagesrst-add-a-case-5-v2.patch vhost-convert-get_user_pages-pin_user_pages.patch
+ kcov-check-kcov_softirq-in-kcov_remote_stop.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: kcov: check kcov_softirq in kcov_remote_stop() has been added to the -mm tree. Its filename is kcov-check-kcov_softirq-in-kcov_remote_stop.patch
The patch titled
Subject: kcov: check kcov_softirq in kcov_remote_stop()
has been added to the -mm tree. Its filename is
kcov-check-kcov_softirq-in-kcov_remote_stop.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/kcov-check-kcov_softirq-in-kcov_remote_stop.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/kcov-check-kcov_softirq-in-kcov_remote_stop.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Andrey Konovalov <[email protected]>
Subject: kcov: check kcov_softirq in kcov_remote_stop()
kcov_remote_stop() should check that the corresponding kcov_remote_start() actually found the specified remote handle and started collecting coverage. This is done by checking the per thread kcov_softirq flag.
A particular failure scenario where this was observed involved a softirq with a remote coverage collection section coming between check_kcov_mode() and the access to t->kcov_area in __sanitizer_cov_trace_pc(). In that softirq kcov_remote_start() bailed out after kcov_remote_find() check, but the matching kcov_remote_stop() didn't check if kcov_remote_start() succeeded, and overwrote per thread kcov parameters with invalid (zero) values.
---
kernel/kcov.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
kernel/kcov.c renamed from kernel/kcov.c~kcov-check-kcov_softirq-in-kcov_remote_stop +4 -7
@@ -427,7 +427,8 @@ void kcov_task_exit(struct task_struct ** WARN_ON(!kcov->remote && kcov->t != t); * * For KCOV_REMOTE_ENABLE devices, the exiting task is either: -* 2. A remote task between kcov_remote_start() and kcov_remote_stop(). +* +* 1. A remote task between kcov_remote_start() and kcov_remote_stop(). * In this case we should print a warning right away, since a task * shouldn't be exiting when it's in a kcov coverage collection * section. Here t points to the task that is collecting remote
@@ -437,7 +438,7 @@ void kcov_task_exit(struct task_struct ** WARN_ON(kcov->remote && kcov->t != t); * * 2. The task that created kcov exiting without calling KCOV_DISABLE, -* and then again we can make sure that t->kcov->t == t: +* and then again we make sure that t->kcov->t == t: * WARN_ON(kcov->remote && kcov->t != t); * * By combining all three checks into one we get:
@@ -764,7 +765,7 @@ static const struct file_operations kcov* Internally, kcov_remote_start() looks up the kcov device associated with the * provided handle, allocates an area for coverage collection, and saves the * pointers to kcov and area into the current task_struct to allow coverage to -* be collected via __sanitizer_cov_trace_pc() +* be collected via __sanitizer_cov_trace_pc(). * In turns kcov_remote_stop() clears those pointers from task_struct to stop * collecting coverage and copies all collected coverage into the kcov area. */
@@ -972,16 +973,25 @@ void kcov_remote_stop(void)local_irq_restore (flags);return ; } - kcov = t->kcov; - area = t->kcov_area; - size = t->kcov_size; - sequence = t->kcov_sequence;
+ lib-lz4-lz4_decompressc-document-deliberate-use-of.patch added to -mm tree
In reply to Andrew MortonThe patch titled Subject: lib/lz4/lz4_decompress.c: document deliberate use of `&' has been added to the -mm tree. Its filename is lib-lz4-lz4_decompressc-document-deliberate-use-of.patch
The patch titled
Subject: lib/lz4/lz4_decompress.c: document deliberate use of `&'
has been added to the -mm tree. Its filename is
lib-lz4-lz4_decompressc-document-deliberate-use-of.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/lib-lz4-lz4_decompressc-document-deliberate-use-of.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/lib-lz4-lz4_decompressc-document-deliberate-use-of.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated there every 3-4 working days
------------------------------------------------------
From: Joe Perches <[email protected]>
Subject: lib/lz4/lz4_decompress.c: document deliberate use of `&'
This operation was intentional, but tools such as smatch will warn that it might not have been.
---
lib/lz4/lz4_decompress.c | 3 +++ 1 file changed, 3 insertions(+)
lib/lz4/lz4_decompress.c renamed from lib/lz4/lz4_decompress.c~lib-lz4-lz4_decompressc-document-deliberate-use-of +3 -0
@@ -141,6 +141,9 @@ static FORCE_INLINE int LZ4_decompress_g* space in the output for those 18 bytes earlier, upon * entering the shortcut (in other words, there is a * combined check for both stages). +* +* The & in the likely() below is intentionally not && so that +* some compilers can produce better parallelized runtime code */ if ((endOnInput ? length !=RUN_MASK : length <=8 )/*
_
Patches currently in -mm which might be from [email protected] are
lib-lz4-lz4_decompressc-document-deliberate-use-of.patch checkpatch-test-git_dir-changes.patch checkpatch-add-test-for-possible-misuse-of-is_enabled-without-config_.patch