Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
da743a92
Commit
da743a92
authored
Oct 04, 2022
by
Petr Mladek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'for-6.1-hash-pointer-init' into for-linus
parents
dc453dd8
6f0ac3b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
21 deletions
+26
-21
lib/vsprintf.c
lib/vsprintf.c
+26
-21
No files found.
lib/vsprintf.c
View file @
da743a92
...
...
@@ -750,37 +750,42 @@ static int __init debug_boot_weak_hash_enable(char *str)
}
early_param
(
"debug_boot_weak_hash"
,
debug_boot_weak_hash_enable
);
static
DEFINE_STATIC_KEY_FALSE
(
filled_random_ptr_key
);
static
bool
filled_random_ptr_key
__read_mostly
;
static
siphash_key_t
ptr_key
__read_mostly
;
static
void
fill_ptr_key_workfn
(
struct
work_struct
*
work
);
static
DECLARE_DELAYED_WORK
(
fill_ptr_key_work
,
fill_ptr_key_workfn
);
static
void
enable
_ptr_key_workfn
(
struct
work_struct
*
work
)
static
void
fill
_ptr_key_workfn
(
struct
work_struct
*
work
)
{
static_branch_enable
(
&
filled_random_ptr_key
);
if
(
!
rng_is_initialized
())
{
queue_delayed_work
(
system_unbound_wq
,
&
fill_ptr_key_work
,
HZ
*
2
);
return
;
}
get_random_bytes
(
&
ptr_key
,
sizeof
(
ptr_key
));
/* Pairs with smp_rmb() before reading ptr_key. */
smp_wmb
();
WRITE_ONCE
(
filled_random_ptr_key
,
true
);
}
static
int
__init
vsprintf_init_hashval
(
void
)
{
fill_ptr_key_workfn
(
NULL
);
return
0
;
}
subsys_initcall
(
vsprintf_init_hashval
)
/* Maps a pointer to a 32 bit unique identifier. */
static
inline
int
__ptr_to_hashval
(
const
void
*
ptr
,
unsigned
long
*
hashval_out
)
{
static
siphash_key_t
ptr_key
__read_mostly
;
unsigned
long
hashval
;
if
(
!
static_branch_likely
(
&
filled_random_ptr_key
))
{
static
bool
filled
=
false
;
static
DEFINE_SPINLOCK
(
filling
);
static
DECLARE_WORK
(
enable_ptr_key_work
,
enable_ptr_key_workfn
);
unsigned
long
flags
;
if
(
!
system_unbound_wq
||
!
rng_is_initialized
()
||
!
spin_trylock_irqsave
(
&
filling
,
flags
))
return
-
EAGAIN
;
if
(
!
filled
)
{
get_random_bytes
(
&
ptr_key
,
sizeof
(
ptr_key
));
queue_work
(
system_unbound_wq
,
&
enable_ptr_key_work
);
filled
=
true
;
}
spin_unlock_irqrestore
(
&
filling
,
flags
);
}
if
(
!
READ_ONCE
(
filled_random_ptr_key
))
return
-
EBUSY
;
/* Pairs with smp_wmb() after writing ptr_key. */
smp_rmb
();
#ifdef CONFIG_64BIT
hashval
=
(
unsigned
long
)
siphash_1u64
((
u64
)
ptr
,
&
ptr_key
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment