Skip to content

Commit 0de0b76

Browse files
committed
Merge tag 'selinux-pr-20221020' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux fix from Paul Moore: "A small SELinux fix for a GFP_KERNEL allocation while a spinlock is held. The patch, while still fairly small, is a bit larger than one might expect from a simple s/GFP_KERNEL/GFP_ATOMIC/ conversion because we added support for the function to be called with different gfp flags depending on the context, preserving GFP_KERNEL for those cases that can safely sleep" * tag 'selinux-pr-20221020' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: enable use of both GFP_KERNEL and GFP_ATOMIC in convert_context()
2 parents 440b789 + abe3c63 commit 0de0b76

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

security/selinux/ss/services.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,8 @@ static inline int convert_context_handle_invalid_context(
20222022
* in `newc'. Verify that the context is valid
20232023
* under the new policy.
20242024
*/
2025-
static int convert_context(struct context *oldc, struct context *newc, void *p)
2025+
static int convert_context(struct context *oldc, struct context *newc, void *p,
2026+
gfp_t gfp_flags)
20262027
{
20272028
struct convert_context_args *args;
20282029
struct ocontext *oc;
@@ -2036,7 +2037,7 @@ static int convert_context(struct context *oldc, struct context *newc, void *p)
20362037
args = p;
20372038

20382039
if (oldc->str) {
2039-
s = kstrdup(oldc->str, GFP_KERNEL);
2040+
s = kstrdup(oldc->str, gfp_flags);
20402041
if (!s)
20412042
return -ENOMEM;
20422043

security/selinux/ss/sidtab.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ int sidtab_context_to_sid(struct sidtab *s, struct context *context,
325325
}
326326

327327
rc = convert->func(context, &dst_convert->context,
328-
convert->args);
328+
convert->args, GFP_ATOMIC);
329329
if (rc) {
330330
context_destroy(&dst->context);
331331
goto out_unlock;
@@ -404,7 +404,7 @@ static int sidtab_convert_tree(union sidtab_entry_inner *edst,
404404
while (i < SIDTAB_LEAF_ENTRIES && *pos < count) {
405405
rc = convert->func(&esrc->ptr_leaf->entries[i].context,
406406
&edst->ptr_leaf->entries[i].context,
407-
convert->args);
407+
convert->args, GFP_KERNEL);
408408
if (rc)
409409
return rc;
410410
(*pos)++;

security/selinux/ss/sidtab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct sidtab_isid_entry {
6565
};
6666

6767
struct sidtab_convert_params {
68-
int (*func)(struct context *oldc, struct context *newc, void *args);
68+
int (*func)(struct context *oldc, struct context *newc, void *args, gfp_t gfp_flags);
6969
void *args;
7070
struct sidtab *target;
7171
};

0 commit comments

Comments
 (0)