Patch "random: move randomize_page() into mm where it belongs" has been added to the 5.18-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    random: move randomize_page() into mm where it belongs

to the 5.18-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     random-move-randomize_page-into-mm-where-it-belongs.patch
and it can be found in the queue-5.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.


>From foo@baz Thu May 26 04:17:01 PM CEST 2022
From: "Jason A. Donenfeld" <Jason@xxxxxxxxx>
Date: Sat, 14 May 2022 13:59:30 +0200
Subject: random: move randomize_page() into mm where it belongs

From: "Jason A. Donenfeld" <Jason@xxxxxxxxx>

commit 5ad7dd882e45d7fe432c32e896e2aaa0b21746ea upstream.

randomize_page is an mm function. It is documented like one. It contains
the history of one. It has the naming convention of one. It looks
just like another very similar function in mm, randomize_stack_top().
And it has always been maintained and updated by mm people. There is no
need for it to be in random.c. In the "which shape does not look like
the other ones" test, pointing to randomize_page() is correct.

So move randomize_page() into mm/util.c, right next to the similar
randomize_stack_top() function.

This commit contains no actual code changes.

Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/char/random.c  |   32 --------------------------------
 include/linux/mm.h     |    1 +
 include/linux/random.h |    2 --
 mm/util.c              |   32 ++++++++++++++++++++++++++++++++
 4 files changed, 33 insertions(+), 34 deletions(-)

--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -622,38 +622,6 @@ int __cold random_prepare_cpu(unsigned i
 }
 #endif
 
-/**
- * randomize_page - Generate a random, page aligned address
- * @start:	The smallest acceptable address the caller will take.
- * @range:	The size of the area, starting at @start, within which the
- *		random address must fall.
- *
- * If @start + @range would overflow, @range is capped.
- *
- * NOTE: Historical use of randomize_range, which this replaces, presumed that
- * @start was already page aligned.  We now align it regardless.
- *
- * Return: A page aligned address within [start, start + range).  On error,
- * @start is returned.
- */
-unsigned long randomize_page(unsigned long start, unsigned long range)
-{
-	if (!PAGE_ALIGNED(start)) {
-		range -= PAGE_ALIGN(start) - start;
-		start = PAGE_ALIGN(start);
-	}
-
-	if (start > ULONG_MAX - range)
-		range = ULONG_MAX - start;
-
-	range >>= PAGE_SHIFT;
-
-	if (range == 0)
-		return start;
-
-	return start + (get_random_long() % range << PAGE_SHIFT);
-}
-
 /*
  * This function will use the architecture-specific hardware random
  * number generator if it is available. It is not recommended for
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2677,6 +2677,7 @@ extern int install_special_mapping(struc
 				   unsigned long flags, struct page **pages);
 
 unsigned long randomize_stack_top(unsigned long stack_top);
+unsigned long randomize_page(unsigned long start, unsigned long range);
 
 extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
 
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -73,8 +73,6 @@ static inline unsigned long get_random_c
 	return get_random_long() & CANARY_MASK;
 }
 
-unsigned long randomize_page(unsigned long start, unsigned long range);
-
 int __init random_init(const char *command_line);
 bool rng_is_initialized(void);
 int wait_for_random_bytes(void);
--- a/mm/util.c
+++ b/mm/util.c
@@ -343,6 +343,38 @@ unsigned long randomize_stack_top(unsign
 #endif
 }
 
+/**
+ * randomize_page - Generate a random, page aligned address
+ * @start:	The smallest acceptable address the caller will take.
+ * @range:	The size of the area, starting at @start, within which the
+ *		random address must fall.
+ *
+ * If @start + @range would overflow, @range is capped.
+ *
+ * NOTE: Historical use of randomize_range, which this replaces, presumed that
+ * @start was already page aligned.  We now align it regardless.
+ *
+ * Return: A page aligned address within [start, start + range).  On error,
+ * @start is returned.
+ */
+unsigned long randomize_page(unsigned long start, unsigned long range)
+{
+	if (!PAGE_ALIGNED(start)) {
+		range -= PAGE_ALIGN(start) - start;
+		start = PAGE_ALIGN(start);
+	}
+
+	if (start > ULONG_MAX - range)
+		range = ULONG_MAX - start;
+
+	range >>= PAGE_SHIFT;
+
+	if (range == 0)
+		return start;
+
+	return start + (get_random_long() % range << PAGE_SHIFT);
+}
+
 #ifdef CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
 unsigned long arch_randomize_brk(struct mm_struct *mm)
 {


Patches currently in stable-queue which might be from Jason@xxxxxxxxx are

queue-5.18/random-remove-ratelimiting-for-in-kernel-unseeded-randomness.patch
queue-5.18/random-fix-sysctl-documentation-nits.patch
queue-5.18/random-help-compiler-out-with-fast_mix-by-using-simpler-arguments.patch
queue-5.18/siphash-use-one-source-of-truth-for-siphash-permutations.patch
queue-5.18/um-use-fallback-for-random_get_entropy-instead-of-zero.patch
queue-5.18/random-order-timer-entropy-functions-below-interrupt-functions.patch
queue-5.18/random-unify-batched-entropy-implementations.patch
queue-5.18/random-make-consistent-use-of-buf-and-len.patch
queue-5.18/random-move-randomize_page-into-mm-where-it-belongs.patch
queue-5.18/random-use-first-128-bits-of-input-as-fast-init.patch
queue-5.18/random-use-proper-return-types-on-get_random_-int-long-_wait.patch
queue-5.18/s390-define-get_cycles-macro-for-arch-override.patch
queue-5.18/timekeeping-add-raw-clock-fallback-for-random_get_entropy.patch
queue-5.18/random-use-static-branch-for-crng_ready.patch
queue-5.18/arm-use-fallback-for-random_get_entropy-instead-of-zero.patch
queue-5.18/mips-use-fallback-for-random_get_entropy-instead-of-just-c0-random.patch
queue-5.18/random-avoid-initializing-twice-in-credit-race.patch
queue-5.18/random-move-initialization-functions-out-of-hot-pages.patch
queue-5.18/random-do-not-pretend-to-handle-premature-next-security-model.patch
queue-5.18/random-do-not-use-batches-when-crng_ready.patch
queue-5.18/m68k-use-fallback-for-random_get_entropy-instead-of-zero.patch
queue-5.18/random-move-initialization-out-of-reseeding-hot-path.patch
queue-5.18/x86-tsc-use-fallback-for-random_get_entropy-instead-of-zero.patch
queue-5.18/random-credit-architectural-init-the-exact-amount.patch
queue-5.18/random-check-for-signals-after-page-of-pool-writes.patch
queue-5.18/random-remove-extern-from-functions-in-header.patch
queue-5.18/random-do-not-use-input-pool-from-hard-irqs.patch
queue-5.18/random-wire-up-fops-splice_-read-write-_iter.patch
queue-5.18/random-insist-on-random_get_entropy-existing-in-order-to-simplify.patch
queue-5.18/powerpc-define-get_cycles-macro-for-arch-override.patch
queue-5.18/parisc-define-get_cycles-macro-for-arch-override.patch
queue-5.18/sparc-use-fallback-for-random_get_entropy-instead-of-zero.patch
queue-5.18/nios2-use-fallback-for-random_get_entropy-instead-of-zero.patch
queue-5.18/init-call-time_init-before-rand_initialize.patch
queue-5.18/riscv-use-fallback-for-random_get_entropy-instead-of-zero.patch
queue-5.18/ia64-define-get_cycles-macro-for-arch-override.patch
queue-5.18/random-handle-latent-entropy-and-command-line-from-random_init.patch
queue-5.18/random-use-proper-jiffies-comparison-macro.patch
queue-5.18/alpha-define-get_cycles-macro-for-arch-override.patch
queue-5.18/random-convert-to-using-fops-read_iter.patch
queue-5.18/xtensa-use-fallback-for-random_get_entropy-instead-of-zero.patch
queue-5.18/random-use-symbolic-constants-for-crng_init-states.patch
queue-5.18/random-convert-to-using-fops-write_iter.patch



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux