ANDROID: random: add back removed callback functions

Commit 6da877d2d46b ("random: replace custom notifier chain with
standard one") in 5.15.44 removed the add_random_ready_callback() and
del_random_ready_callback() functions, which are part of the current
Android ABI in this branch.  To handle this properly, add them back in
order for out-of-tree code to continue working.

Bug: 161946584
Fixes: 6da877d2d46b ("random: replace custom notifier chain with standard one")
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I422f3af1a28c5cf2e7f7806d6fb37d66901e3a33
This commit is contained in:
Greg Kroah-Hartman
2022-06-24 11:42:55 +02:00
parent 6cc2db3cde
commit fee299e72e
2 changed files with 89 additions and 0 deletions

View File

@@ -180,6 +180,7 @@ int __cold unregister_random_ready_notifier(struct notifier_block *nb)
}
EXPORT_SYMBOL(unregister_random_ready_notifier);
static void process_oldschool_random_ready_list(void);
static void __cold process_random_ready_list(void)
{
unsigned long flags;
@@ -187,6 +188,8 @@ static void __cold process_random_ready_list(void)
spin_lock_irqsave(&random_ready_chain_lock, flags);
raw_notifier_call_chain(&random_ready_chain, 0, NULL);
spin_unlock_irqrestore(&random_ready_chain_lock, flags);
process_oldschool_random_ready_list();
}
#define warn_unseeded_randomness() \
@@ -1533,3 +1536,76 @@ struct ctl_table random_table[] = {
{ }
};
#endif /* CONFIG_SYSCTL */
/*
* Android KABI fixups
*
* Add back two functions that were being used by out-of-tree drivers.
*
* Yes, horrible hack, the things we do for FIPS "compliance"...
*/
static DEFINE_SPINLOCK(random_ready_list_lock);
static LIST_HEAD(random_ready_list);
int add_random_ready_callback(struct random_ready_callback *rdy)
{
struct module *owner;
unsigned long flags;
int err = -EALREADY;
if (crng_ready())
return err;
owner = rdy->owner;
if (!try_module_get(owner))
return -ENOENT;
spin_lock_irqsave(&random_ready_list_lock, flags);
if (crng_ready())
goto out;
owner = NULL;
list_add(&rdy->list, &random_ready_list);
err = 0;
out:
spin_unlock_irqrestore(&random_ready_list_lock, flags);
module_put(owner);
return err;
}
EXPORT_SYMBOL(add_random_ready_callback);
void del_random_ready_callback(struct random_ready_callback *rdy)
{
unsigned long flags;
struct module *owner = NULL;
spin_lock_irqsave(&random_ready_list_lock, flags);
if (!list_empty(&rdy->list)) {
list_del_init(&rdy->list);
owner = rdy->owner;
}
spin_unlock_irqrestore(&random_ready_list_lock, flags);
module_put(owner);
}
EXPORT_SYMBOL(del_random_ready_callback);
static void process_oldschool_random_ready_list(void)
{
unsigned long flags;
struct random_ready_callback *rdy, *tmp;
spin_lock_irqsave(&random_ready_list_lock, flags);
list_for_each_entry_safe(rdy, tmp, &random_ready_list, list) {
struct module *owner = rdy->owner;
list_del_init(&rdy->list);
rdy->func(rdy);
module_put(owner);
}
spin_unlock_irqrestore(&random_ready_list_lock, flags);
}

View File

@@ -138,4 +138,17 @@ int random_online_cpu(unsigned int cpu);
extern const struct file_operations random_fops, urandom_fops;
#endif
/*
* Android KABI fixups
* Added back the following structure and calls to preserve the ABI for
* out-of-tree drivers that were using them.
*/
struct random_ready_callback {
struct list_head list;
void (*func)(struct random_ready_callback *rdy);
struct module *owner;
};
extern int add_random_ready_callback(struct random_ready_callback *rdy);
extern void del_random_ready_callback(struct random_ready_callback *rdy);
#endif /* _LINUX_RANDOM_H */