uaccess fixes
Subsystems (3)
cover uaccess fixes
An i915 redundant CLAC fix, and an objtool fix which would have caught it earlier.
Josh Poimboeuf (1):
drm/i915: Remove redundant user_access_end() from __copy_from_user()
error path
Peter Zijlstra (1):
objtool: Improve UACCESS coverage
.../gpu/drm/i915/gem/i915_gem_execbuffer.c | 20 +++++++++---------- tools/objtool/check.c | 7 ++++--- tools/objtool/check.h | 3 ++- 3 files changed, 15 insertions(+), 15 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/2 drm/i915: Remove redundant user_access_end() from __copy_from_user() error path
Objtool reports:
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0x36: redundant UACCESS disable
__copy_from_user() already does both STAC and CLAC, so the user_access_end() in its error path adds an extra unnecessary CLAC.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +9 -11
@@ -1628,6 +1628,7 @@ static int check_relocations(const struct drm_i915_gem_exec_object2 *entry)static int eb_copy_relocations (const struct i915_execbuffer *eb) { +struct drm_i915_gem_relocation_entry *relocs;const unsigned int count = eb->buffer_count;unsigned int i;int err;
@@ -1635,7 +1636,6 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb)for (i =0 ; i < count; i++) {const unsigned int nreloc = eb->exec[i].relocation_count;struct drm_i915_gem_relocation_entry __user *urelocs; -struct drm_i915_gem_relocation_entry *relocs;unsigned long size;unsigned long copied;
@@ -1663,14 +1663,8 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb)if (__copy_from_user ((char *)relocs + copied, (char __user *)urelocs + copied, - len)) { -end_user: -user_access_end (); -end: -kvfree (relocs); - err = -EFAULT ; - goto err; - } + len)) + goto end; copied += len; }while (copied < size);
@@ -1699,10 +1693,14 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb)return 0 ; +end_user: +user_access_end (); +end: +kvfree (relocs); + err = -EFAULT ; err:while (i--) { -struct drm_i915_gem_relocation_entry *relocs = -u64_to_ptr (typeof (*relocs), eb->exec[i].relocs_ptr); + relocs =u64_to_ptr (typeof (*relocs), eb->exec[i].relocs_ptr);if (eb->exec[i].relocation_count)kvfree (relocs); }
Signature · 1 line
2.20.1
Re: [PATCH 1/2] drm/i915: Remove redundant user_access_end() from __copy_from_user() error path
Quoted 8 lines · Josh Poimboeuf
Objtool reports:
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0x36: redundant UACCESS disable
__copy_from_user()already does both STAC and CLAC, so theuser_access_end()in its error path adds an extra unnecessary CLAC.
Quoted 7 lines
Fixes 0b2c8f8b6b0c ("i915: fix missing user_access_end() in page fault exception case")Reported-by Thomas Gleixner <[email protected]>Reported-by Sedat Dilek <[email protected]>Tested-by Nick Desaulniers <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>
Just for the records and ensuing ages:
Quoted 61 lines
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +9
-12@@ -1628,6 +1628,7 @@ static int check_relocations(const struct drm_i915_gem_exec_object2 *entry)static int eb_copy_relocations (const struct i915_execbuffer *eb) { +struct drm_i915_gem_relocation_entry *relocs;const unsigned int count = eb->buffer_count;unsigned int i;int err;@@ -1635,7 +1636,6 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb)for (i =0 ; i < count; i++) {const unsigned int nreloc = eb->exec[i].relocation_count;struct drm_i915_gem_relocation_entry __user *urelocs; -struct drm_i915_gem_relocation_entry *relocs;unsigned long size;unsigned long copied;@@ -1663,14 +1663,8 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb)if (__copy_from_user ((char *)relocs + copied, (char __user *)urelocs + copied, - len)) { -end_user: -user_access_end (); -end: -kvfree (relocs); - err = -EFAULT ; - goto err; - } + len)) + goto end; copied += len; }while (copied < size);@@ -1699,10 +1693,14 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb)return 0 ; +end_user: +user_access_end (); +end: +kvfree (relocs); + err = -EFAULT ; err:while (i--) { -struct drm_i915_gem_relocation_entry *relocs = -u64_to_ptr (typeof (*relocs), eb->exec[i].relocs_ptr); + relocs =u64_to_ptr (typeof (*relocs), eb->exec[i].relocs_ptr);if (eb->exec[i].relocation_count)kvfree (relocs); } --2.20.1
Re: [PATCH 1/2] drm/i915: Remove redundant user_access_end() from __copy_from_user() error path
Quoted 17 lines · Sedat Dilek
Quoted 8 lines · Josh Poimboeuf
Objtool reports:
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0x36: redundant UACCESS disable
__copy_from_user()already does both STAC and CLAC, so theuser_access_end()in its error path adds an extra unnecessary CLAC.Quoted 7 lines
Fixes 0b2c8f8b6b0c ("i915: fix missing user_access_end() in page fault exception case")Reported-by Thomas Gleixner <[email protected]>Reported-by Sedat Dilek <[email protected]>Tested-by Nick Desaulniers <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>
Quoted 3 lines
Just for the records and ensuing ages:
Tested-by Sedat Dilek <[email protected]>
Thanks Sedat. Since the objtool fix already got merged separately I'll resend this patch to the drm folks.
Signature · 1 line
Josh
PATCH 2/2 objtool: Improve UACCESS coverage
In reply to Josh PoimboeufFrom: Peter Zijlstra <[email protected]>
A clang build reported an (obvious) double CLAC while a GCC build did not; it turns out we only re-visit instructions if the first visit was with AC=0. If OTOH the first visit was with AC=1, we completely ignore any subsequent visit, even when it has AC=0.
Fix this by using a visited mask instead of a boolean, and (explicitly) mark the AC state.
$ ./objtool check -b --no-fp --retpoline --uaccess drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0x22: redundant UACCESS disable drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0xea: (alt) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0xffffffffffffffff: (branch) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0xd9: (alt) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0xb2: (branch) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0x39: (branch) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0x0: <=== (func)
--- tools/objtool/check.c | 7 ++++--- tools/objtool/check.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-)
tools/objtool/check.c +4 -3
@@ -1946,6 +1946,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,struct alternative *alt;struct instruction *insn, *next_insn;struct section *sec; +u8 visited;int ret; insn = first;
@@ -1972,12 +1973,12 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,return 1 ; } + visited =1 << state.uaccess;if (insn->visited) {if (!insn->hint && !insn_state_match (insn, &state))return 1 ; -/* If we were here with AC=0, but now have AC=1, go again */ -if (insn->state.uaccess || !state.uaccess) +if (insn->visited & visited)return 0 ; }
@@ -2024,7 +2025,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, }else insn->state = state; - insn->visited = true; + insn->visited |= visited;if (!insn->ignore_alts) {bool skip_orig = false;
tools/objtool/check.h +2 -1
@@ -33,8 +33,9 @@ struct instruction {unsigned int len;enum insn_type type;unsigned long immediate; -bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts; +bool alt_group, dead_end, ignore, hint, save, restore, ignore_alts;bool retpoline_safe; +u8 visited;struct symbol *call_dest;struct instruction *jump_dest;struct instruction *first_jump_src;
Signature · 1 line
2.20.1
tip-bot for Peter Zijlstra
merge bot[tip:core/urgent] objtool: Improve UACCESS coverage
objtool: Improve UACCESS coverage
Commit-ID: 882a0db9d143e5e8dac54b96e83135bccd1f68d1 Gitweb: https://git.kernel.org/tip/882a0db9d143e5e8dac54b96e83135bccd1f68d1 Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 24 Jul 2019 17:47:26 -0500 Committer: Thomas Gleixner <[email protected]> CommitDate: Thu, 25 Jul 2019 08:36:39 +0200
objtool: Improve UACCESS coverage
A clang build reported an (obvious) double CLAC while a GCC build did not; it turns out that objtool only re-visits instructions if the first visit was with AC=0. If OTOH the first visit was with AC=1, it completely ignores any subsequent visit, even when it has AC=0.
Fix this by using a visited mask instead of a boolean, and (explicitly) mark the AC state.
$ ./objtool check -b --no-fp --retpoline --uaccess drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0x22: redundant UACCESS disable drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0xea: (alt) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0xffffffffffffffff: (branch) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0xd9: (alt) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0xb2: (branch) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0x39: (branch) drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0x0: <=== (func)
--- tools/objtool/check.c | 7 ++++--- tools/objtool/check.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-)
tools/objtool/check.c +4 -3
@@ -1946,6 +1946,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,struct alternative *alt;struct instruction *insn, *next_insn;struct section *sec; +u8 visited;int ret; insn = first;
@@ -1972,12 +1973,12 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,return 1 ; } + visited =1 << state.uaccess;if (insn->visited) {if (!insn->hint && !insn_state_match (insn, &state))return 1 ; -/* If we were here with AC=0, but now have AC=1, go again */ -if (insn->state.uaccess || !state.uaccess) +if (insn->visited & visited)return 0 ; }
@@ -2024,7 +2025,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, }else insn->state = state; - insn->visited = true; + insn->visited |= visited;if (!insn->ignore_alts) {bool skip_orig = false;
tools/objtool/check.h +2 -1
@@ -33,8 +33,9 @@ struct instruction {unsigned int len;enum insn_type type;unsigned long immediate; -bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts; +bool alt_group, dead_end, ignore, hint, save, restore, ignore_alts;bool retpoline_safe; +u8 visited;struct symbol *call_dest;struct instruction *jump_dest;struct instruction *first_jump_src;