4.9.320-rc1 review
Subsystems (5)
Greg Kroah-Hartman
maintainerPATCH 212/264 random: wire up fops->splice_{read,write}_iter()
In reply to Greg Kroah-HartmanFrom: Jens Axboe <[email protected]>
commit 79025e727a846be6fd215ae9cdb654368ac3f9a6 upstream.
Now that random/urandom is using {read,write}_iter, we can wire it up to using the generic splice handlers.
[Jason: added the splice_write path. Note that sendfile() and such still
does not work for read, though it does for write, because of a file type restriction in splice_direct_to_actor(), which I'll address separately.]
--- drivers/char/random.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/char/random.c +4 -0
@@ -1382,6 +1382,8 @@ const struct file_operations random_fops .unlocked_ioctl = random_ioctl, .fasync = random_fasync, .llseek = noop_llseek, + .splice_read = generic_file_splice_read, + .splice_write = iter_file_splice_write, };const struct file_operations urandom_fops = {
@@ -1390,6 +1392,8 @@ const struct file_operations urandom_fop .unlocked_ioctl = random_ioctl, .fasync = random_fasync, .llseek = noop_llseek, + .splice_read = generic_file_splice_read, + .splice_write = iter_file_splice_write, };
Greg Kroah-Hartman
maintainerPATCH 213/264 random: check for signals after page of pool writes
In reply to Greg Kroah-HartmanFrom: "Jason A. Donenfeld" <[email protected]>
commit 1ce6c8d68f8ac587f54d0a271ac594d3d51f3efb upstream.
get_random_bytes_user() checks for signals after producing a PAGE_SIZE worth of output, just like /dev/zero does. write_pool() is doing basically the same work (actually, slightly more expensive), and so should stop to check for signals in the same way. Let's also name it write_pool_user() to match get_random_bytes_user(), so this won't be misused in the future.
Before this patch, massive writes to /dev/urandom would tie up the process for an extremely long time and make it unterminatable. After, it can be successfully interrupted. The following test program can be used to see this works as intended:
#include <unistd.h> #include <fcntl.h> #include <signal.h> #include <stdio.h> static unsigned char x[~0U];
static void handle(int) { }
int main(int argc, char *argv[])
{
pid_t pid = getpid(), child;
int fd;
signal(SIGUSR1, handle);
if (!(child = fork())) {
for (;;)
kill(pid, SIGUSR1);
}
fd = open("/dev/urandom", O_WRONLY);
pause();
printf("interrupted after writing %zd bytes\n", write(fd, x, sizeof(x)));
close(fd);
kill(child, SIGTERM);
return 0;
}Result before: "interrupted after writing 2147479552 bytes" Result after: "interrupted after writing 4096 bytes"
--- drivers/char/random.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/char/random.c +10 -4
@@ -1252,7 +1252,7 @@ static unsigned int random_poll(struct freturn crng_ready () ?POLLIN |POLLRDNORM :POLLOUT |POLLWRNORM ; } -static ssize_t write_pool (struct iov_iter *iter) +static ssize_t write_pool_user (struct iov_iter *iter) {u8 block[BLAKE2S_BLOCK_SIZE ];ssize_t ret =0 ;
@@ -1267,7 +1267,13 @@ static ssize_t write_pool(struct iov_itemix_pool_bytes (block, copied);if (!iov_iter_count (iter) || copied !=sizeof (block))break ; -cond_resched (); + +BUILD_BUG_ON (PAGE_SIZE %sizeof (block) !=0 ); +if (ret %PAGE_SIZE ==0 ) { +if (signal_pending (current)) +break ; +cond_resched (); + } }memzero_explicit (block,sizeof (block));
@@ -1276,7 +1282,7 @@ static ssize_t write_pool(struct iov_itestatic ssize_t random_write_iter (struct kiocb *kiocb,struct iov_iter *iter) { -return write_pool (iter); +return write_pool_user (iter); }static ssize_t urandom_read_iter (struct kiocb *kiocb,struct iov_iter *iter)
@@ -1343,7 +1349,7 @@ static long random_ioctl(struct file *f, ret =import_single_range (WRITE , p, len, &iov, &iter);if (unlikely (ret))return ret; - ret =write_pool (&iter); + ret =write_pool_user (&iter);if (unlikely (ret <0 ))return ret;/* Since we're crediting, enforce that it was all written into the pool. */
Greg Kroah-Hartman
maintainerPATCH 214/264 Revert "random: use static branch for crng_ready()"
In reply to Greg Kroah-HartmanFrom: "Jason A. Donenfeld" <[email protected]>
This reverts upstream commit f5bda35fba615ace70a656d4700423fa6c9bebee from stable. It's not essential and will take some time during 5.19 to work out properly.
--- drivers/char/random.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/char/random.c +2 -10
@@ -80,8 +80,7 @@ static enum {CRNG_EARLY =1 ,/* At least POOL_EARLY_BITS collected */ CRNG_READY = 2 /* Fully initialized with POOL_READY_BITS collected */ } crng_init__read_mostly =CRNG_EMPTY ; -static DEFINE_STATIC_KEY_FALSE (crng_is_ready); -#define crng_ready () (static_branch_likely(&crng_is_ready) || crng_init >= CRNG_READY) +#define crng_ready () (likely(crng_init >= CRNG_READY))/* Various types of waiters for crng_init->CRNG_READY transition. */ static DECLARE_WAIT_QUEUE_HEAD (crng_init_wait);static struct fasync_struct *fasync;
@@ -111,11 +110,6 @@ bool rng_is_initialized(void) }EXPORT_SYMBOL (rng_is_initialized); -static void __cold crng_set_ready (struct work_struct *work) -{ -static_branch_enable (&crng_is_ready); -} -/* Used by wait_for_random_bytes(), and considered an entropy collector, below. */ static void try_to_generate_entropy (void );
@@ -269,7 +263,7 @@ static void crng_reseed(void) ++next_gen;WRITE_ONCE (base_crng.generation, next_gen);WRITE_ONCE (base_crng.birth, jiffies); -if (!static_branch_likely (&crng_is_ready)) +if (!crng_ready ()) crng_init =CRNG_READY ;spin_unlock_irqrestore (&base_crng.lock, flags);memzero_explicit (key,sizeof (key));
@@ -710,7 +704,6 @@ static void extract_entropy(void *buf, sstatic void __cold _credit_init_bits (size_t bits) { -static struct execute_work set_ready;unsigned int new, orig, add;unsigned long flags;
@@ -726,7 +719,6 @@ static void __cold _credit_init_bits(sizif (orig <POOL_READY_BITS && new >=POOL_READY_BITS ) {crng_reseed ();/* Sets crng_init to CRNG_READY under base_crng.lock. */ -execute_in_process_context (crng_set_ready, &set_ready);process_random_ready_list ();wake_up_interruptible (&crng_init_wait);kill_fasync (&fasync,SIGIO ,POLL_IN );
Greg Kroah-Hartman
maintainerPATCH 215/264 crypto: drbg - add FIPS 140-2 CTRNG for noise source
In reply to Greg Kroah-HartmanFrom: Stephan Mueller <[email protected]>
commit db07cd26ac6a418dc2823187958edcfdb415fa83 upstream.
FIPS 140-2 section 4.9.2 requires a continuous self test of the noise source. Up to kernel 4.8 drivers/char/random.c provided this continuous self test. Afterwards it was moved to a location that is inconsistent with the FIPS 140-2 requirements. The relevant patch was e192be9d9a30555aae2ca1dc3aad37cba484cd4a .
Thus, the FIPS 140-2 CTRNG is added to the DRBG when it obtains the seed. This patch resurrects the function drbg_fips_continous_test that existed some time ago and applies it to the noise sources. The patch that removed the drbg_fips_continous_test was b3614763059b82c26bdd02ffcb1c016c1132aad0 .
The Jitter RNG implements its own FIPS 140-2 self test and thus does not need to be subjected to the test in the DRBG.
The patch contains a tiny fix to ensure proper zeroization in case of an error during the Jitter RNG data gathering.
--- crypto/drbg.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++-- include/crypto/drbg.h | 2 + 2 files changed, 93 insertions(+), 3 deletions(-)
crypto/drbg.c +91 -3
@@ -220,6 +220,57 @@ static inline unsigned short drbg_sec_st }/* +* FIPS 140-2 continuous self test for the noise source +* The test is performed on the noise source input data. Thus, the function +* implicitly knows the size of the buffer to be equal to the security +* strength. +* +* Note, this function disregards the nonce trailing the entropy data during +* initial seeding. +* +* drbg->drbg_mutex must have been taken. +* +* @drbg DRBG handle +* @entropy buffer of seed data to be checked +* +* return: +* 0 on success +* -EAGAIN on when the CTRNG is not yet primed +* < 0 on error +*/ +static int drbg_fips_continuous_test (struct drbg_state *drbg, +const unsigned char *entropy) +{ +unsigned short entropylen =drbg_sec_strength (drbg->core->flags); +int ret =0 ; + +if (!IS_ENABLED (CONFIG_CRYPTO_FIPS )) +return 0 ; + +/* skip test if we test the overall system */ +if (list_empty (&drbg->test_data.list)) +return 0 ; +/* only perform test in FIPS mode */ +if (!fips_enabled) +return 0 ; + +if (!drbg->fips_primed) { +/* Priming of FIPS test */ +memcpy (drbg->prev, entropy, entropylen); + drbg->fips_primed = true; +/* priming: another round is needed */ +return -EAGAIN ; + } + ret =memcmp (drbg->prev, entropy, entropylen); +if (!ret) +panic ("DRBG continuous self test failed\n" ); +memcpy (drbg->prev, entropy, entropylen); + +/* the test shall pass when the two values are not equal */ +return 0 ; +} + +/* * Convert an integer into a byte representation of this integer. * The byte representation is big-endian *
@@ -1000,6 +1051,22 @@ static inline int __drbg_seed(struct drbreturn ret; } +static inline int drbg_get_random_bytes (struct drbg_state *drbg, +unsigned char *entropy, +unsigned int entropylen) +{ +int ret; + +do { +get_random_bytes (entropy, entropylen); + ret =drbg_fips_continuous_test (drbg, entropy); +if (ret && ret != -EAGAIN ) +return ret; + }while (ret); + +return 0 ; +} +static void drbg_async_seed (struct work_struct *work) {struct drbg_string data;
@@ -1008,16 +1075,20 @@ static void drbg_async_seed(struct work_ seed_work);unsigned int entropylen =drbg_sec_strength (drbg->core->flags);unsigned char entropy[32 ]; +int ret;BUG_ON (!entropylen);BUG_ON (entropylen >sizeof (entropy)); -get_random_bytes (entropy, entropylen);drbg_string_fill (&data, entropy, entropylen);list_add_tail (&data.list, &seedlist);mutex_lock (&drbg->drbg_mutex); + ret =drbg_get_random_bytes (drbg, entropy, entropylen); +if (ret) + goto unlock; +/* If nonblocking pool is initialized, deactivate Jitter RNG */ crypto_free_rng (drbg->jent); drbg->jent =NULL ;
@@ -1032,6 +1103,7 @@ static void drbg_async_seed(struct work_if (drbg->seeded) drbg->reseed_threshold =drbg_max_requests (drbg); +unlock:mutex_unlock (&drbg->drbg_mutex);memzero_explicit (entropy, entropylen);
@@ -1083,7 +1155,9 @@ static int drbg_seed(struct drbg_state *BUG_ON ((entropylen *2 ) >sizeof (entropy));/* Get seed from in-kernel /dev/urandom */ -get_random_bytes (entropy, entropylen); + ret =drbg_get_random_bytes (drbg, entropy, entropylen); +if (ret) + goto out;if (!drbg->jent) {drbg_string_fill (&data1, entropy, entropylen);
@@ -1096,7 +1170,7 @@ static int drbg_seed(struct drbg_state * entropylen);if (ret) {pr_devel ("DRBG: jent failed with %d\n" , ret); -return ret; + goto out; }drbg_string_fill (&data1, entropy, entropylen *2 );
@@ -1123,6 +1197,7 @@ static int drbg_seed(struct drbg_state * ret =__drbg_seed (drbg, &seedlist, reseed); +out:memzero_explicit (entropy, entropylen *2 );return ret;
@@ -1144,6 +1219,11 @@ static inline void drbg_dealloc_state(st drbg->reseed_ctr =0 ; drbg->d_ops =NULL ; drbg->core =NULL ; +if (IS_ENABLED (CONFIG_CRYPTO_FIPS )) { +kzfree (drbg->prev); + drbg->prev =NULL ; + drbg->fips_primed = false; + } }/*
@@ -1213,6 +1293,14 @@ static inline int drbg_alloc_state(struc drbg->scratchpad =PTR_ALIGN (drbg->scratchpadbuf, ret +1 ); } +if (IS_ENABLED (CONFIG_CRYPTO_FIPS )) { + drbg->prev =kzalloc (drbg_sec_strength (drbg->core->flags), +GFP_KERNEL ); +if (!drbg->prev) + goto fini; + drbg->fips_primed = false; + } +return 0 ; fini:
include/crypto/drbg.h +2 -0
@@ -131,6 +131,8 @@ struct drbg_state {bool seeded;/* DRBG fully seeded? */ bool pr;/* Prediction resistance enabled? */ +bool fips_primed;/* Continuous test primed? */ +unsigned char *prev;/* FIPS 140-2 continuous test value */ struct work_struct seed_work;/* asynchronous seeding support */ struct crypto_rng *jent;const struct drbg_state_ops *d_ops;
Greg Kroah-Hartman
maintainerPATCH 216/264 crypto: drbg - always seeded with SP800-90B compliant noise source
In reply to Greg Kroah-HartmanFrom: "Stephan M�ller" <[email protected]>
commit 97f2650e504033376e8813691cb6eccf73151676 upstream.
As the Jitter RNG provides an SP800-90B compliant noise source, use this noise source always for the (re)seeding of the DRBG.
To make sure the DRBG is always properly seeded, the reseed threshold is reduced to 1<<20 generate operations.
The Jitter RNG may report health test failures. Such health test failures are treated as transient as follows. The DRBG will not reseed from the Jitter RNG (but from get_random_bytes) in case of a health test failure. Though, it produces the requested random number.
The Jitter RNG has a failure counter where at most 1024 consecutive resets due to a health test failure are considered as a transient error. If more consecutive resets are required, the Jitter RNG will return a permanent error which is returned to the caller by the DRBG. With this approach, the worst case reseed threshold is significantly lower than mandated by SP800-90A in order to seed with an SP800-90B noise source:
the DRBG has a reseed threshold of 2^20 * 1024 = 2^30 generate requests.
Yet, in case of a transient Jitter RNG health test failure, the DRBG is seeded with the data obtained from get_random_bytes.
However, if the Jitter RNG fails during the initial seeding operation even due to a health test error, the DRBG will send an error to the caller because at that time, the DRBG has received no seed that is SP800-90B compliant.
--- crypto/drbg.c | 26 +++++++++++++++++++------- include/crypto/drbg.h | 6 +----- 2 files changed, 20 insertions(+), 12 deletions(-)
crypto/drbg.c +19 -7
@@ -1089,10 +1089,6 @@ static void drbg_async_seed(struct work_if (ret) goto unlock; -/* If nonblocking pool is initialized, deactivate Jitter RNG */ -crypto_free_rng (drbg->jent); - drbg->jent =NULL ; -/* Set seeded to false so that if __drbg_seed fails the * next generate call will trigger a reseed. */
@@ -1170,7 +1166,23 @@ static int drbg_seed(struct drbg_state * entropylen);if (ret) {pr_devel ("DRBG: jent failed with %d\n" , ret); - goto out; + +/* +* Do not treat the transient failure of the +* Jitter RNG as an error that needs to be +* reported. The combined number of the +* maximum reseed threshold times the maximum +* number of Jitter RNG transient errors is +* less than the reseed threshold required by +* SP800-90A allowing us to treat the +* transient errors as such. +* +* However, we mandate that at least the first +* seeding operation must succeed with the +* Jitter RNG. +*/ +if (!reseed || ret != -EAGAIN ) + goto out; }drbg_string_fill (&data1, entropy, entropylen *2 );
@@ -1495,6 +1507,8 @@ static int drbg_prepare_hrng(struct drbgif (list_empty (&drbg->test_data.list))return 0 ; + drbg->jent =crypto_alloc_rng ("jitterentropy_rng" ,0 ,0 ); +INIT_WORK (&drbg->seed_work, drbg_async_seed); drbg->random_ready.notifier_call = drbg_schedule_async_seed;
@@ -1513,8 +1527,6 @@ static int drbg_prepare_hrng(struct drbgreturn err; } - drbg->jent =crypto_alloc_rng ("jitterentropy_rng" ,0 ,0 ); -/* * Require frequent reseeds until the seed source is fully * initialized.
include/crypto/drbg.h +1 -5
@@ -186,11 +186,7 @@ static inline size_t drbg_max_addtl(strustatic inline size_t drbg_max_requests (struct drbg_state *drbg) {/* SP800-90A requires 2**48 maximum requests before reseeding */ -#if (__BITS_PER_LONG ==32 ) -return SIZE_MAX ; -#else -return (1UL <<48 ); -#endif +return (1 <<20 ); }/*
Greg Kroah-Hartman
maintainerPATCH 217/264 crypto: drbg - prepare for more fine-grained tracking of seeding state
In reply to Greg Kroah-HartmanFrom: Nicolai Stange <[email protected]>
commit ce8ce31b2c5c8b18667784b8c515650c65d57b4e upstream.
There are two different randomness sources the DRBGs are getting seeded from, namely the jitterentropy source (if enabled) and get_random_bytes(). At initial DRBG seeding time during boot, the latter might not have collected sufficient entropy for seeding itself yet and thus, the DRBG implementation schedules a reseed work from a random_ready_callback once that has happened. This is particularly important for the !->pr DRBG instances, for which (almost) no further reseeds are getting triggered during their lifetime.
Because collecting data from the jitterentropy source is a rather expensive operation, the aforementioned asynchronously scheduled reseed work restricts itself to get_random_bytes() only. That is, it in some sense amends the initial DRBG seed derived from jitterentropy output at full (estimated) entropy with fresh randomness obtained from get_random_bytes() once that has been seeded with sufficient entropy itself.
With the advent of rng_is_initialized(), there is no real need for doing the reseed operation from an asynchronously scheduled work anymore and a subsequent patch will make it synchronous by moving it next to related logic already present in drbg_generate().
However, for tracking whether a full reseed including the jitterentropy source is required or a "partial" reseed involving only get_random_bytes() would be sufficient already, the boolean struct drbg_state's ->seeded member must become a tristate value.
Prepare for this by introducing the new enum drbg_seed_state and change struct drbg_state's ->seeded member's type from bool to that type.
For facilitating review, enum drbg_seed_state is made to only contain two members corresponding to the former ->seeded values of false and true resp. at this point: DRBG_SEED_STATE_UNSEEDED and DRBG_SEED_STATE_FULL. A third one for tracking the intermediate state of "seeded from jitterentropy only" will be introduced with a subsequent patch.
There is no change in behaviour at this point.
--- crypto/drbg.c | 19 ++++++++++--------- include/crypto/drbg.h | 7 ++++++- 2 files changed, 16 insertions(+), 10 deletions(-)
crypto/drbg.c +10 -9
@@ -1044,7 +1044,7 @@ static inline int __drbg_seed(struct drbif (ret)return ret; - drbg->seeded = true; + drbg->seeded =DRBG_SEED_STATE_FULL ;/* 10.1.1.2 / 10.1.1.3 step 5 */ drbg->reseed_ctr =1 ;
@@ -1089,14 +1089,14 @@ static void drbg_async_seed(struct work_if (ret) goto unlock; -/* Set seeded to false so that if __drbg_seed fails the -* next generate call will trigger a reseed. +/* Reset ->seeded so that if __drbg_seed fails the next +* generate call will trigger a reseed. */ - drbg->seeded = false; + drbg->seeded =DRBG_SEED_STATE_UNSEEDED ;__drbg_seed (drbg, &seedlist, true); -if (drbg->seeded) +if (drbg->seeded ==DRBG_SEED_STATE_FULL ) drbg->reseed_threshold =drbg_max_requests (drbg); unlock:
@@ -1385,13 +1385,14 @@ static int drbg_generate(struct drbg_sta* here. The spec is a bit convoluted here, we make it simpler. */ if (drbg->reseed_threshold < drbg->reseed_ctr) - drbg->seeded = false; + drbg->seeded =DRBG_SEED_STATE_UNSEEDED ; -if (drbg->pr || !drbg->seeded) { +if (drbg->pr || drbg->seeded ==DRBG_SEED_STATE_UNSEEDED ) {pr_devel ("DRBG: reseeding before generation (prediction " "resistance: %s, state %s)\n" , drbg->pr ?"true" :"false" , - drbg->seeded ?"seeded" :"unseeded" ); + (drbg->seeded ==DRBG_SEED_STATE_FULL ? +"seeded" :"unseeded" ));/* 9.3.1 steps 7.1 through 7.3 */ len =drbg_seed (drbg, addtl, true);if (len)
@@ -1576,7 +1577,7 @@ static int drbg_instantiate(struct drbg_if (!drbg->core) { drbg->core = &drbg_cores[coreref]; drbg->pr = pr; - drbg->seeded = false; + drbg->seeded =DRBG_SEED_STATE_UNSEEDED ; drbg->reseed_threshold =drbg_max_requests (drbg); ret =drbg_alloc_state (drbg);
include/crypto/drbg.h +6 -1
@@ -105,6 +105,11 @@ struct drbg_test_data {struct drbg_string *testentropy;/* TEST PARAMETER: test entropy */ }; +enum drbg_seed_state { +DRBG_SEED_STATE_UNSEEDED , +DRBG_SEED_STATE_FULL , +}; +struct drbg_state {struct mutex drbg_mutex;/* lock around DRBG */ unsigned char *V;/* internal state 10.1.1.1 1a) */
@@ -129,7 +134,7 @@ struct drbg_state {struct completion ctr_completion;/* CTR mode async handler */ int ctr_async_err;/* CTR mode async error */ -bool seeded;/* DRBG fully seeded? */ +enum drbg_seed_state seeded;/* DRBG fully seeded? */ bool pr;/* Prediction resistance enabled? */ bool fips_primed;/* Continuous test primed? */ unsigned char *prev;/* FIPS 140-2 continuous test value */
Greg Kroah-Hartman
maintainerPATCH 218/264 crypto: drbg - track whether DRBG was seeded with !rng_is_initialized()
In reply to Greg Kroah-HartmanFrom: Nicolai Stange <[email protected]>
commit 2bcd25443868aa8863779a6ebc6c9319633025d2 upstream.
Currently, the DRBG implementation schedules asynchronous works from random_ready_callbacks for reseeding the DRBG instances with output from get_random_bytes() once the latter has sufficient entropy available.
However, as the get_random_bytes() initialization state can get queried by means of rng_is_initialized() now, there is no real need for this asynchronous reseeding logic anymore and it's better to keep things simple by doing it synchronously when needed instead, i.e. from drbg_generate() once rng_is_initialized() has flipped to true.
Of course, for this to work, drbg_generate() would need some means by which it can tell whether or not rng_is_initialized() has flipped to true since the last seeding from get_random_bytes(). Or equivalently, whether or not the last seed from get_random_bytes() has happened when rng_is_initialized() was still evaluating to false.
As it currently stands, enum drbg_seed_state allows for the representation of two different DRBG seeding states: DRBG_SEED_STATE_UNSEEDED and DRBG_SEED_STATE_FULL. The former makes drbg_generate() to invoke a full reseeding operation involving both, the rather expensive jitterentropy as well as the get_random_bytes() randomness sources. The DRBG_SEED_STATE_FULL state on the other hand implies that no reseeding at all is required for a !->pr DRBG variant.
Introduce the new DRBG_SEED_STATE_PARTIAL state to enum drbg_seed_state for representing the condition that a DRBG was being seeded when rng_is_initialized() had still been false. In particular, this new state implies that
- the given DRBG instance has been fully seeded from the jitterentropy source (if enabled)
- and drbg_generate() is supposed to reseed from get_random_bytes() *only* once rng_is_initialized() turns to true.
Up to now, the __drbg_seed() helper used to set the given DRBG instance's ->seeded state to constant DRBG_SEED_STATE_FULL. Introduce a new argument allowing for the specification of the to be written ->seeded value instead. Make the first of its two callers, drbg_seed(), determine the appropriate value based on rng_is_initialized(). The remaining caller, drbg_async_seed(), is known to get invoked only once rng_is_initialized() is true, hence let it pass constant DRBG_SEED_STATE_FULL for the new argument to __drbg_seed().
There is no change in behaviour, except for that the pr_devel() in drbg_generate() would now report "unseeded" for ->pr DRBG instances which had last been seeded when rng_is_initialized() was still evaluating to false.
--- crypto/drbg.c | 12 ++++++++---- include/crypto/drbg.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-)
crypto/drbg.c +8 -4
@@ -1037,14 +1037,14 @@ static const struct drbg_state_ops drbg_******************************************************************/ static inline int __drbg_seed (struct drbg_state *drbg,struct list_head *seed, -int reseed) +int reseed,enum drbg_seed_state new_seed_state) {int ret = drbg->d_ops->update (drbg, seed, reseed);if (ret)return ret; - drbg->seeded =DRBG_SEED_STATE_FULL ; + drbg->seeded = new_seed_state;/* 10.1.1.2 / 10.1.1.3 step 5 */ drbg->reseed_ctr =1 ;
@@ -1094,7 +1094,7 @@ static void drbg_async_seed(struct work_*/ drbg->seeded =DRBG_SEED_STATE_UNSEEDED ; -__drbg_seed (drbg, &seedlist, true); +__drbg_seed (drbg, &seedlist, true,DRBG_SEED_STATE_FULL );if (drbg->seeded ==DRBG_SEED_STATE_FULL ) drbg->reseed_threshold =drbg_max_requests (drbg);
@@ -1124,6 +1124,7 @@ static int drbg_seed(struct drbg_state *unsigned int entropylen =drbg_sec_strength (drbg->core->flags);struct drbg_string data1;LIST_HEAD (seedlist); +enum drbg_seed_state new_seed_state =DRBG_SEED_STATE_FULL ;/* 9.1 / 9.2 / 9.3.1 step 3 */ if (pers && pers->len > (drbg_max_addtl (drbg))) {
@@ -1151,6 +1152,9 @@ static int drbg_seed(struct drbg_state *BUG_ON ((entropylen *2 ) >sizeof (entropy));/* Get seed from in-kernel /dev/urandom */ +if (!rng_is_initialized ()) + new_seed_state =DRBG_SEED_STATE_PARTIAL ; + ret =drbg_get_random_bytes (drbg, entropy, entropylen);if (ret) goto out;
@@ -1207,7 +1211,7 @@ static int drbg_seed(struct drbg_state *memset (drbg->C,0 ,drbg_statelen (drbg)); } - ret =__drbg_seed (drbg, &seedlist, reseed); + ret =__drbg_seed (drbg, &seedlist, reseed, new_seed_state); out:memzero_explicit (entropy, entropylen *2 );
include/crypto/drbg.h +1 -0
@@ -107,6 +107,7 @@ struct drbg_test_data {enum drbg_seed_state {DRBG_SEED_STATE_UNSEEDED , +DRBG_SEED_STATE_PARTIAL ,/* Seeded with !rng_is_initialized() */ DRBG_SEED_STATE_FULL , };
Greg Kroah-Hartman
maintainerPATCH 219/264 crypto: drbg - move dynamic ->reseed_threshold adjustments to __drbg_seed()
In reply to Greg Kroah-HartmanFrom: Nicolai Stange <[email protected]>
commit 262d83a4290c331cd4f617a457408bdb82fbb738 upstream.
Since commit 42ea507fae1a ("crypto: drbg - reseed often if seedsource is degraded"), the maximum seed lifetime represented by ->reseed_threshold gets temporarily lowered if the get_random_bytes() source cannot provide sufficient entropy yet, as is common during boot, and restored back to the original value again once that has changed.
More specifically, if the add_random_ready_callback() invoked from drbg_prepare_hrng() in the course of DRBG instantiation does not return -EALREADY, that is, if get_random_bytes() has not been fully initialized at this point yet, drbg_prepare_hrng() will lower ->reseed_threshold to a value of 50. The drbg_async_seed() scheduled from said random_ready_callback will eventually restore the original value.
A future patch will replace the random_ready_callback based notification mechanism and thus, there will be no add_random_ready_callback() return value anymore which could get compared to -EALREADY.
However, there's __drbg_seed() which gets invoked in the course of both, the DRBG instantiation as well as the eventual reseeding from get_random_bytes() in aforementioned drbg_async_seed(), if any. Moreover, it knows about the get_random_bytes() initialization state by the time the seed data had been obtained from it: the new_seed_state argument introduced with the previous patch would get set to DRBG_SEED_STATE_PARTIAL in case get_random_bytes() had not been fully initialized yet and to DRBG_SEED_STATE_FULL otherwise. Thus, __drbg_seed() provides a convenient alternative for managing that ->reseed_threshold lowering and restoring at a central place.
Move all ->reseed_threshold adjustment code from drbg_prepare_hrng() and drbg_async_seed() respectively to __drbg_seed(). Make __drbg_seed() lower the ->reseed_threshold to 50 in case its new_seed_state argument equals DRBG_SEED_STATE_PARTIAL and let it restore the original value otherwise.
There is no change in behaviour.
--- crypto/drbg.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
crypto/drbg.c +20 -9
@@ -1048,6 +1048,26 @@ static inline int __drbg_seed(struct drb/* 10.1.1.2 / 10.1.1.3 step 5 */ drbg->reseed_ctr =1 ; +switch (drbg->seeded) { +case DRBG_SEED_STATE_UNSEEDED : +/* Impossible, but handle it to silence compiler warnings. */ +case DRBG_SEED_STATE_PARTIAL : +/* +* Require frequent reseeds until the seed source is +* fully initialized. +*/ + drbg->reseed_threshold =50 ; +break ; + +case DRBG_SEED_STATE_FULL : +/* +* Seed source has become fully initialized, frequent +* reseeds no longer required. +*/ + drbg->reseed_threshold =drbg_max_requests (drbg); +break ; + } +return ret; }
@@ -1096,9 +1116,6 @@ static void drbg_async_seed(struct work___drbg_seed (drbg, &seedlist, true,DRBG_SEED_STATE_FULL ); -if (drbg->seeded ==DRBG_SEED_STATE_FULL ) - drbg->reseed_threshold =drbg_max_requests (drbg); - unlock:mutex_unlock (&drbg->drbg_mutex);
@@ -1532,12 +1549,6 @@ static int drbg_prepare_hrng(struct drbgreturn err; } -/* -* Require frequent reseeds until the seed source is fully -* initialized. -*/ - drbg->reseed_threshold =50 ; -return err; }
Greg Kroah-Hartman
maintainerPATCH 220/264 crypto: drbg - always try to free Jitter RNG instance
In reply to Greg Kroah-HartmanFrom: "Stephan M�ller" <[email protected]>
commit 819966c06b759022e9932f328284314d9272b9f3 upstream.
The Jitter RNG is unconditionally allocated as a seed source follwoing the patch 97f2650e5040. Thus, the instance must always be deallocated.
--- crypto/drbg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
crypto/drbg.c +4 -2
@@ -1646,10 +1646,12 @@ static int drbg_uninstantiate(struct drbif (drbg->random_ready.notifier_call) {unregister_random_ready_notifier (&drbg->random_ready);cancel_work_sync (&drbg->seed_work); -crypto_free_rng (drbg->jent); - drbg->jent =NULL ; } +if (!IS_ERR_OR_NULL (drbg->jent)) +crypto_free_rng (drbg->jent); + drbg->jent =NULL ; +if (drbg->d_ops) drbg->d_ops->crypto_fini (drbg);drbg_dealloc_state (drbg);
Greg Kroah-Hartman
maintainerPATCH 221/264 crypto: drbg - make reseeding from get_random_bytes() synchronous
In reply to Greg Kroah-HartmanFrom: Nicolai Stange <[email protected]>
commit 074bcd4000e0d812bc253f86fedc40f81ed59ccc upstream.
get_random_bytes() usually hasn't full entropy available by the time DRBG instances are first getting seeded from it during boot. Thus, the DRBG implementation registers random_ready_callbacks which would in turn schedule some work for reseeding the DRBGs once get_random_bytes() has sufficient entropy available.
For reference, the relevant history around handling DRBG (re)seeding in the context of a not yet fully seeded get_random_bytes() is:
commit 16b369a91d0d ("random: Blocking API for accessing
nonblocking_pool")
commit 4c7879907edd ("crypto: drbg - add async seeding operation")
commit 205a525c3342 ("random: Add callback API for random pool
readiness")
commit 57225e679788 ("crypto: drbg - Use callback API for random
readiness")
commit c2719503f5e1 ("random: Remove kernel blocking API")
However, some time later, the initialization state of get_random_bytes() has been made queryable via rng_is_initialized() introduced with commit 9a47249d444d ("random: Make crng state queryable"). This primitive now allows for streamlining the DRBG reseeding from get_random_bytes() by replacing that aforementioned asynchronous work scheduling from random_ready_callbacks with some simpler, synchronous code in drbg_generate() next to the related logic already present therein. Apart from improving overall code readability, this change will also enable DRBG users to rely on wait_for_random_bytes() for ensuring that the initial seeding has completed, if desired.
The previous patches already laid the grounds by making drbg_seed() to record at each DRBG instance whether it was being seeded at a time when rng_is_initialized() still had been false as indicated by ->seeded == DRBG_SEED_STATE_PARTIAL.
All that remains to be done now is to make drbg_generate() check for this condition, determine whether rng_is_initialized() has flipped to true in the meanwhile and invoke a reseed from get_random_bytes() if so.
Make this move:
- rename the former drbg_async_seed() work handler, i.e. the one in charge of reseeding a DRBG instance from get_random_bytes(), to "drbg_seed_from_random()",
- change its signature as appropriate, i.e. make it take a struct drbg_state rather than a work_struct and change its return type from "void" to "int" in order to allow for passing error information from e.g. its __drbg_seed() invocation onwards to callers,
- make drbg_generate() invoke this drbg_seed_from_random() once it encounters a DRBG instance with ->seeded == DRBG_SEED_STATE_PARTIAL by the time rng_is_initialized() has flipped to true and
- prune everything related to the former, random_ready_callback based mechanism.
As drbg_seed_from_random() is now getting invoked from drbg_generate() with the ->drbg_mutex being held, it must not attempt to recursively grab it once again. Remove the corresponding mutex operations from what is now drbg_seed_from_random(). Furthermore, as drbg_seed_from_random() can now report errors directly to its caller, there's no need for it to temporarily switch the DRBG's ->seeded state to DRBG_SEED_STATE_UNSEEDED so that a failure of the subsequently invoked __drbg_seed() will get signaled to drbg_generate(). Don't do it then.
--- crypto/drbg.c | 61 +++++++++----------------------------------------- drivers/char/random.c | 2 - include/crypto/drbg.h | 2 - 3 files changed, 11 insertions(+), 54 deletions(-)
crypto/drbg.c +11 -50
@@ -1087,12 +1087,10 @@ static inline int drbg_get_random_bytes(return 0 ; } -static void drbg_async_seed (struct work_struct *work) +static int drbg_seed_from_random (struct drbg_state *drbg) {struct drbg_string data;LIST_HEAD (seedlist); - struct drbg_state *drbg = container_of(work, struct drbg_state, - seed_work);unsigned int entropylen =drbg_sec_strength (drbg->core->flags);unsigned char entropy[32 ];int ret;
@@ -1103,23 +1101,15 @@ static void drbg_async_seed(struct work_drbg_string_fill (&data, entropy, entropylen);list_add_tail (&data.list, &seedlist); -mutex_lock (&drbg->drbg_mutex); - ret =drbg_get_random_bytes (drbg, entropy, entropylen);if (ret) - goto unlock; - -/* Reset ->seeded so that if __drbg_seed fails the next -* generate call will trigger a reseed. -*/ - drbg->seeded =DRBG_SEED_STATE_UNSEEDED ; + goto out; -__drbg_seed (drbg, &seedlist, true,DRBG_SEED_STATE_FULL ); - -unlock: -mutex_unlock (&drbg->drbg_mutex); + ret =__drbg_seed (drbg, &seedlist, true,DRBG_SEED_STATE_FULL ); +out:memzero_explicit (entropy, entropylen); +return ret; }/*
@@ -1420,6 +1410,11 @@ static int drbg_generate(struct drbg_sta goto err;/* 9.3.1 step 7.4 */ addtl =NULL ; + }else if (rng_is_initialized () && + drbg->seeded ==DRBG_SEED_STATE_PARTIAL ) { + len =drbg_seed_from_random (drbg); +if (len) + goto err; }if (addtl &&0 < addtl->len)
@@ -1512,44 +1507,15 @@ static int drbg_generate_long(struct drbreturn 0 ; } -static int drbg_schedule_async_seed (struct notifier_block *nb,unsigned long action,void *data) -{ - struct drbg_state *drbg = container_of(nb, struct drbg_state, - random_ready); - -schedule_work (&drbg->seed_work); -return 0 ; -} -static int drbg_prepare_hrng (struct drbg_state *drbg) { -int err; -/* We do not need an HRNG in test mode. */ if (list_empty (&drbg->test_data.list))return 0 ; drbg->jent =crypto_alloc_rng ("jitterentropy_rng" ,0 ,0 ); -INIT_WORK (&drbg->seed_work, drbg_async_seed); - - drbg->random_ready.notifier_call = drbg_schedule_async_seed; - err =register_random_ready_notifier (&drbg->random_ready); - -switch (err) { -case 0 : -break ; - -case -EALREADY : - err =0 ; -/* fall through */ - -default : - drbg->random_ready.notifier_call =NULL ; -return err; - } - -return err; +return 0 ; }/*
@@ -1643,11 +1609,6 @@ free_everything:*/ static int drbg_uninstantiate (struct drbg_state *drbg) { -if (drbg->random_ready.notifier_call) { -unregister_random_ready_notifier (&drbg->random_ready); -cancel_work_sync (&drbg->seed_work); - } -if (!IS_ERR_OR_NULL (drbg->jent))crypto_free_rng (drbg->jent); drbg->jent =NULL ;
drivers/char/random.c +0 -2
@@ -158,7 +158,6 @@ int __cold register_random_ready_notifiespin_unlock_irqrestore (&random_ready_chain_lock, flags);return ret; } -EXPORT_SYMBOL (register_random_ready_notifier);/* * Delete a previously registered readiness callback function.
@@ -173,7 +172,6 @@ int __cold unregister_random_ready_notifspin_unlock_irqrestore (&random_ready_chain_lock, flags);return ret; } -EXPORT_SYMBOL (unregister_random_ready_notifier);static void __cold process_random_ready_list (void ) {
include/crypto/drbg.h +0 -2
@@ -139,12 +139,10 @@ struct drbg_state {bool pr;/* Prediction resistance enabled? */ bool fips_primed;/* Continuous test primed? */ unsigned char *prev;/* FIPS 140-2 continuous test value */ -struct work_struct seed_work;/* asynchronous seeding support */ struct crypto_rng *jent;const struct drbg_state_ops *d_ops;const struct drbg_core *core;struct drbg_string test_data; -struct notifier_block random_ready; };static inline __u8 drbg_statelen (struct drbg_state *drbg)
Greg Kroah-Hartman
maintainerPATCH 222/264 random: avoid checking crng_ready() twice in random_init()
In reply to Greg Kroah-HartmanFrom: "Jason A. Donenfeld" <[email protected]>
commit 9b29b6b20376ab64e1b043df6301d8a92378e631 upstream.
The current flow expands to:
if (crng_ready())
...
else if (...)
if (!crng_ready())
...The second crng_ready() call is redundant, but can't so easily be optimized out by the compiler.
This commit simplifies that to:
if (crng_ready()
...
else if (...)
...--- drivers/char/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/random.c +1 -1
@@ -835,7 +835,7 @@ int __init random_init(const char *commaif (crng_ready ())crng_reseed ();else if (trust_cpu) -credit_init_bits (arch_bytes *8 ); +_credit_init_bits (arch_bytes *8 );return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 223/264 random: mark bootloader randomness code as __init
In reply to Greg Kroah-HartmanFrom: "Jason A. Donenfeld" <[email protected]>
commit 39e0f991a62ed5efabd20711a7b6e7da92603170 upstream.
add_bootloader_randomness() and the variables it touches are only used during __init and not after, so mark these as __init. At the same time, unexport this, since it's only called by other __init code that's built-in.
--- drivers/char/random.c | 7 +++---- include/linux/random.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/char/random.c +3 -4
@@ -786,8 +786,8 @@ static void __cold _credit_init_bits(siz* **********************************************************************/ -static bool trust_cpu__ro_after_init =IS_ENABLED (CONFIG_RANDOM_TRUST_CPU ); -static bool trust_bootloader__ro_after_init =IS_ENABLED (CONFIG_RANDOM_TRUST_BOOTLOADER ); +static bool trust_cpu__initdata =IS_ENABLED (CONFIG_RANDOM_TRUST_CPU ); +static bool trust_bootloader__initdata =IS_ENABLED (CONFIG_RANDOM_TRUST_BOOTLOADER );static int __init parse_trust_cpu (char *arg) {return kstrtobool (arg, &trust_cpu);
@@ -883,13 +883,12 @@ EXPORT_SYMBOL_GPL(add_hwgenerator_random* Handle random seed passed by bootloader, and credit it if * CONFIG_RANDOM_TRUST_BOOTLOADER is set. */ -void __cold add_bootloader_randomness (const void *buf,size_t len) +void __init add_bootloader_randomness (const void *buf,size_t len) {mix_pool_bytes (buf, len);if (trust_bootloader)credit_init_bits (len *8 ); } -EXPORT_SYMBOL_GPL (add_bootloader_randomness);struct fast_pool {struct work_struct mix;
include/linux/random.h +1 -1
@@ -13,7 +13,7 @@struct notifier_block ;void add_device_randomness (const void *buf,size_t len); -void add_bootloader_randomness (const void *buf,size_t len); +void __init add_bootloader_randomness (const void *buf,size_t len); void add_input_randomness(unsigned int type, unsigned int code, unsigned int value) __latent_entropy; void add_interrupt_randomness(int irq) __latent_entropy;
Greg Kroah-Hartman
maintainerPATCH 224/264 random: account for arch randomness in bits
In reply to Greg Kroah-HartmanFrom: "Jason A. Donenfeld" <[email protected]>
commit 77fc95f8c0dc9e1f8e620ec14d2fb65028fb7adc upstream.
Rather than accounting in bytes and multiplying (shifting), we can just account in bits and avoid the shift. The main motivation for this is there are other patches in flux that expand this code a bit, and avoiding the duplication of "* 8" everywhere makes things a bit clearer.
--- drivers/char/random.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/char/random.c +4 -4
@@ -810,7 +810,7 @@ early_param("random.trust_bootloader", pint __init random_init (const char *command_line) {ktime_t now =ktime_get_real (); -unsigned int i, arch_bytes; +unsigned int i, arch_bits;unsigned long entropy;#if defined(LATENT_ENTROPY_PLUGIN )
@@ -818,12 +818,12 @@ int __init random_init(const char *comma_mix_pool_bytes (compiletime_seed,sizeof (compiletime_seed));#endif -for (i =0 , arch_bytes =BLAKE2S_BLOCK_SIZE ; +for (i =0 , arch_bits =BLAKE2S_BLOCK_SIZE *8 ; i <BLAKE2S_BLOCK_SIZE ; i +=sizeof (entropy)) {if (!arch_get_random_seed_long_early (&entropy) && !arch_get_random_long_early (&entropy)) { entropy =random_get_entropy (); - arch_bytes -=sizeof (entropy); + arch_bits -=sizeof (entropy) *8 ; }_mix_pool_bytes (&entropy,sizeof (entropy)); }
@@ -835,7 +835,7 @@ int __init random_init(const char *commaif (crng_ready ())crng_reseed ();else if (trust_cpu) -_credit_init_bits (arch_bytes *8 ); +_credit_init_bits (arch_bits);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 225/264 ASoC: cs42l52: Fix TLV scales for mixer controls
In reply to Greg Kroah-HartmanFrom: Charles Keepax <[email protected]>
[ Upstream commit 8bf5aabf524eec61013e506f764a0b2652dc5665 ]
The datasheet specifies the range of the mixer volumes as between -51.5dB and 12dB with a 0.5dB step. Update the TLVs for this.
--- sound/soc/codecs/cs42l52.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/cs42l52.c +2 -2
@@ -141,7 +141,7 @@ static DECLARE_TLV_DB_SCALE(mic_tlv, 1600, 100, 0); static DECLARE_TLV_DB_SCALE(pga_tlv, -600, 50, 0); -static DECLARE_TLV_DB_SCALE(mix_tlv, -50, 50, 0); +static DECLARE_TLV_DB_SCALE(mix_tlv, -5150, 50, 0); static DECLARE_TLV_DB_SCALE(beep_tlv, -56, 200, 0);
@@ -368,7 +368,7 @@ static const struct snd_kcontrol_new cs42l52_snd_controls[] = { CS42L52_ADCB_VOL, 0, 0xA0, 0x78, ipd_tlv),SOC_DOUBLE_R_SX_TLV ("ADC Mixer Volume" ,CS42L52_ADCA_MIXER_VOL ,CS42L52_ADCB_MIXER_VOL , -0 ,0x19 ,0x7F , ipd_tlv), +0 ,0x19 ,0x7F , mix_tlv), SOC_DOUBLE("ADC Switch", CS42L52_ADC_MISC_CTL, 0, 1, 1, 0),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 226/264 ASoC: cs53l30: Correct number of volume levels on SX controls
In reply to Greg Kroah-HartmanFrom: Charles Keepax <[email protected]>
[ Upstream commit 7fbd6dd68127927e844912a16741016d432a0737 ]
This driver specified the maximum value rather than the number of volume levels on the SX controls, this is incorrect, so correct them.
--- sound/soc/codecs/cs53l30.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/codecs/cs53l30.c +8 -8
@@ -351,22 +351,22 @@ static const struct snd_kcontrol_new cs53l30_snd_controls[] = {SOC_ENUM ("ADC2 NG Delay" , adc2_ng_delay_enum),SOC_SINGLE_SX_TLV ("ADC1A PGA Volume" , -CS53L30_ADC1A_AFE_CTL ,0 ,0x34 ,0x18 , pga_tlv), +CS53L30_ADC1A_AFE_CTL ,0 ,0x34 ,0x24 , pga_tlv),SOC_SINGLE_SX_TLV ("ADC1B PGA Volume" , -CS53L30_ADC1B_AFE_CTL ,0 ,0x34 ,0x18 , pga_tlv), +CS53L30_ADC1B_AFE_CTL ,0 ,0x34 ,0x24 , pga_tlv),SOC_SINGLE_SX_TLV ("ADC2A PGA Volume" , -CS53L30_ADC2A_AFE_CTL ,0 ,0x34 ,0x18 , pga_tlv), +CS53L30_ADC2A_AFE_CTL ,0 ,0x34 ,0x24 , pga_tlv),SOC_SINGLE_SX_TLV ("ADC2B PGA Volume" , -CS53L30_ADC2B_AFE_CTL ,0 ,0x34 ,0x18 , pga_tlv), +CS53L30_ADC2B_AFE_CTL ,0 ,0x34 ,0x24 , pga_tlv),SOC_SINGLE_SX_TLV ("ADC1A Digital Volume" , -CS53L30_ADC1A_DIG_VOL ,0 ,0xA0 ,0x0C , dig_tlv), +CS53L30_ADC1A_DIG_VOL ,0 ,0xA0 ,0x6C , dig_tlv),SOC_SINGLE_SX_TLV ("ADC1B Digital Volume" , -CS53L30_ADC1B_DIG_VOL ,0 ,0xA0 ,0x0C , dig_tlv), +CS53L30_ADC1B_DIG_VOL ,0 ,0xA0 ,0x6C , dig_tlv),SOC_SINGLE_SX_TLV ("ADC2A Digital Volume" , -CS53L30_ADC2A_DIG_VOL ,0 ,0xA0 ,0x0C , dig_tlv), +CS53L30_ADC2A_DIG_VOL ,0 ,0xA0 ,0x6C , dig_tlv),SOC_SINGLE_SX_TLV ("ADC2B Digital Volume" , - CS53L30_ADC2B_DIG_VOL, 0, 0xA0, 0x0C, dig_tlv), + CS53L30_ADC2B_DIG_VOL, 0, 0xA0, 0x6C, dig_tlv), }; static const struct snd_soc_dapm_widget cs53l30_dapm_widgets[] = {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 227/264 ASoC: cs42l52: Correct TLV for Bypass Volume
In reply to Greg Kroah-HartmanFrom: Charles Keepax <[email protected]>
[ Upstream commit 91e90c712fade0b69cdff7cc6512f6099bd18ae5 ]
The Bypass Volume is accidentally using a -6dB minimum TLV rather than the correct -60dB minimum. Add a new TLV to correct this.
--- sound/soc/codecs/cs42l52.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/codecs/cs42l52.c +3 -1
@@ -141,6 +141,8 @@ static DECLARE_TLV_DB_SCALE(mic_tlv, 1600, 100, 0); static DECLARE_TLV_DB_SCALE(pga_tlv, -600, 50, 0); +static DECLARE_TLV_DB_SCALE(pass_tlv, -6000, 50, 0); + static DECLARE_TLV_DB_SCALE(mix_tlv, -5150, 50, 0); static DECLARE_TLV_DB_SCALE(beep_tlv, -56, 200, 0);
@@ -355,7 +357,7 @@ static const struct snd_kcontrol_new cs42l52_snd_controls[] = { CS42L52_SPKB_VOL, 0, 0x40, 0xC0, hl_tlv),SOC_DOUBLE_R_SX_TLV ("Bypass Volume" ,CS42L52_PASSTHRUA_VOL , -CS42L52_PASSTHRUB_VOL ,0 ,0x88 ,0x90 , pga_tlv), +CS42L52_PASSTHRUB_VOL ,0 ,0x88 ,0x90 , pass_tlv), SOC_DOUBLE("Bypass Mute", CS42L52_MISC_CTL, 4, 5, 1, 0),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 228/264 ASoC: cs42l56: Correct typo in minimum level for SX volume controls
In reply to Greg Kroah-HartmanFrom: Charles Keepax <[email protected]>
[ Upstream commit a8928ada9b96944cadd8b65d191e33199fd38782 ]
A couple of the SX volume controls specify 0x84 as the lowest volume value, however the correct value from the datasheet is 0x44. The datasheet don't include spaces in the value it displays as binary so this was almost certainly just a typo reading 1000100.
--- sound/soc/codecs/cs42l56.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/cs42l56.c +2 -2
@@ -405,9 +405,9 @@ static const struct snd_kcontrol_new cs42l56_snd_controls[] = {SOC_DOUBLE ("ADC Boost Switch" ,CS42L56_GAIN_BIAS_CTL ,3 ,2 ,1 ,1 ),SOC_DOUBLE_R_SX_TLV ("Headphone Volume" ,CS42L56_HPA_VOLUME , -CS42L56_HPB_VOLUME ,0 ,0x84 ,0x48 , hl_tlv), +CS42L56_HPB_VOLUME ,0 ,0x44 ,0x48 , hl_tlv),SOC_DOUBLE_R_SX_TLV ("LineOut Volume" ,CS42L56_LOA_VOLUME , -CS42L56_LOB_VOLUME ,0 ,0x84 ,0x48 , hl_tlv), +CS42L56_LOB_VOLUME ,0 ,0x44 ,0x48 , hl_tlv),SOC_SINGLE_TLV ("Bass Shelving Volume" ,CS42L56_TONE_CTL , 0, 0x00, 1, tone_tlv),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 229/264 ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo()
In reply to Greg Kroah-HartmanFrom: Sergey Shtylyov <[email protected]>
[ Upstream commit bf476fe22aa1851bab4728e0c49025a6a0bea307 ]
In an unlikely (and probably wrong?) case that the 'ppi' parameter of ata_host_alloc_pinfo() points to an array starting with a NULL pointer, there's going to be a kernel oops as the 'pi' local variable won't get reassigned from the initial value of NULL. Initialize 'pi' instead to '&ata_dummy_port_info' to fix the possible kernel oops for good...
Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.
--- drivers/ata/libata-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ata/libata-core.c +2 -2
@@ -6051,7 +6051,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, const struct ata_port_info * const * ppi, int n_ports) { -const struct ata_port_info *pi; +const struct ata_port_info *pi = &ata_dummy_port_info;struct ata_host *host;int i, j;
@@ -6059,7 +6059,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev,if (!host)return NULL ; -for (i =0 , j =0 , pi =NULL ; i < host->n_ports; i++) { +for (i =0 , j =0 ; i < host->n_ports; i++) {struct ata_port *ap = host->ports[i];if (ppi[j])
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 230/264 ASoC: wm8962: Fix suspend while playing music
In reply to Greg Kroah-HartmanFrom: Adam Ford <[email protected]>
[ Upstream commit d1f5272c0f7d2e53c6f2480f46725442776f5f78 ]
If the audio CODEC is playing sound when the system is suspended, it can be left in a state which throws the following error:
wm8962 3-001a: ASoC: error at soc_component_read_no_lock on wm8962.3-001a: -16
Once this error has occurred, the audio will not work again until rebooted.
Fix this by configuring SET_SYSTEM_SLEEP_PM_OPS.
--- sound/soc/codecs/wm8962.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/codecs/wm8962.c +1 -0
@@ -3861,6 +3861,7 @@ static int wm8962_runtime_suspend(struct device *dev)#endif static const struct dev_pm_ops wm8962_pm = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)SET_RUNTIME_PM_OPS (wm8962_runtime_suspend, wm8962_runtime_resume,NULL ) };
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 231/264 scsi: vmw_pvscsi: Expand vcpuHint to 16 bits
In reply to Greg Kroah-HartmanFrom: Wentao Wang <[email protected]>
[ Upstream commit cf71d59c2eceadfcde0fb52e237990a0909880d7 ]
vcpuHint has been expanded to 16 bit on host to enable routing to more CPUs. Guest side should align with the change. This change has been tested with hosts with 8-bit and 16-bit vcpuHint, on both platforms host side can get correct value.
--- drivers/scsi/vmw_pvscsi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/vmw_pvscsi.h +2 -2
@@ -333,8 +333,8 @@ struct PVSCSIRingReqDesc {u8 tag;u8 bus;u8 target; -u8 vcpuHint; -u8 unused[59 ]; +u16 vcpuHint; +u8 unused[58 ]; } __packed;/*
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 232/264 scsi: lpfc: Fix port stuck in bypassed state after LIP in PT2PT topology
In reply to Greg Kroah-HartmanFrom: James Smart <[email protected]>
[ Upstream commit 336d63615466b4c06b9401c987813fd19bdde39b ]
After issuing a LIP, a specific target vendor does not ACC the FLOGI that lpfc sends. However, it does send its own FLOGI that lpfc ACCs. The target then establishes the port IDs by sending a PLOGI. lpfc PLOGI_ACCs and starts the RPI registration for DID 0x000001. The target then sends a LOGO to the fabric DID. lpfc is currently treating the LOGO from the fabric DID as a link down and cleans up all the ndlps. The ndlp for DID 0x000001 is put back into NPR and discovery stops, leaving the port in stuck in bypassed mode.
Change lpfc behavior such that if a LOGO is received for the fabric DID in PT2PT topology skip the lpfc_linkdown_port() routine and just move the fabric DID back to NPR.
--- drivers/scsi/lpfc/lpfc_nportdisc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/lpfc/lpfc_nportdisc.c +2 -1
@@ -633,7 +633,8 @@ lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,else lpfc_els_rsp_acc (vport,ELS_CMD_ACC , cmdiocb, ndlp,NULL );if (ndlp->nlp_DID == Fabric_DID) { -if (vport->port_state <=LPFC_FDISC ) +if (vport->port_state <=LPFC_FDISC || + vport->fc_flag &FC_PT2PT ) goto out;lpfc_linkdown_port (vport);spin_lock_irq (shost->host_lock);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 233/264 virtio-mmio: fix missing put_device() when vm_cmdline_parent registration failed
In reply to Greg Kroah-HartmanFrom: chengkaitao <[email protected]>
[ Upstream commit a58a7f97ba11391d2d0d408e0b24f38d86ae748e ]
The reference must be released when device_register(&vm_cmdline_parent) failed. Add the corresponding 'put_device()' in the error handling path.
Message-Id: <[email protected]>
--- drivers/virtio/virtio_mmio.c | 1 + 1 file changed, 1 insertion(+)
drivers/virtio/virtio_mmio.c +1 -0
@@ -630,6 +630,7 @@ static int vm_cmdline_set(const char *device,if (!vm_cmdline_parent_registered) { err =device_register (&vm_cmdline_parent);if (err) { +put_device (&vm_cmdline_parent);pr_err ("Failed to register parent device!\n" );return err; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 234/264 nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred
In reply to Greg Kroah-HartmanFrom: Xiaohui Zhang <[email protected]>
[ Upstream commit 8a4d480702b71184fabcf379b80bf7539716752e ]
Similar to the handling of play_deferred in commit 19cfe912c37b ("Bluetooth: btusb: Fix memory leak in play_deferred"), we thought a patch might be needed here as well.
Currently usb_submit_urb is called directly to submit deferred tx urbs after unanchor them.
So the usb_giveback_urb_bh would failed to unref it in usb_unanchor_urb and cause memory leak.
Put those urbs in tx_anchor to avoid the leak, and also fix the error handling.
--- drivers/nfc/nfcmrvl/usb.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/nfc/nfcmrvl/usb.c +14 -2
@@ -401,13 +401,25 @@ static void nfcmrvl_play_deferred(struct nfcmrvl_usb_drv_data *drv_data)int err;while ((urb =usb_get_from_anchor (&drv_data->deferred))) { +usb_anchor_urb (urb, &drv_data->tx_anchor); + err =usb_submit_urb (urb,GFP_ATOMIC ); -if (err) +if (err) { +kfree (urb->setup_packet); +usb_unanchor_urb (urb); +usb_free_urb (urb);break ; + } drv_data->tx_in_flight++; +usb_free_urb (urb); + } + +/* Cleanup the rest deferred urbs. */ +while ((urb =usb_get_from_anchor (&drv_data->deferred))) { +kfree (urb->setup_packet); +usb_free_urb (urb); } -usb_scuttle_anchored_urbs (&drv_data->deferred); }static int nfcmrvl_resume (struct usb_interface *intf)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 235/264 ipv6: Fix signed integer overflow in l2tp_ip6_sendmsg
In reply to Greg Kroah-HartmanFrom: Wang Yufen <[email protected]>
[ Upstream commit f638a84afef3dfe10554c51820c16e39a278c915 ]
When len >= INT_MAX - transhdrlen, ulen = len + transhdrlen will be overflow. To fix, we can follow what udpv6 does and subtract the transhdrlen from the max.
--- net/l2tp/l2tp_ip6.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/l2tp/l2tp_ip6.c +3 -2
@@ -518,14 +518,15 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)struct ipcm6_cookie ipc6;int addr_len = msg->msg_namelen;int transhdrlen =4 ;/* zero session-id */ -int ulen = len + transhdrlen; +int ulen;int err;/* Rough check on arithmetic overflow, better check is made in ip6_append_data(). */ -if (len >INT_MAX ) +if (len >INT_MAX - transhdrlen)return -EMSGSIZE ; + ulen = len + transhdrlen;/* Mirror BSD error message compatibility */ if (msg->msg_flags &MSG_OOB )
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 236/264 net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface netdev[napi]_alloc_frag
In reply to Greg Kroah-HartmanFrom: Chen Lin <[email protected]>
[ Upstream commit 2f2c0d2919a14002760f89f4e02960c735a316d2 ]
When rx_flag == MTK_RX_FLAGS_HWLRO,rx_data_len = MTK_MAX_LRO_RX_LENGTH(4096 * 3) > PAGE_SIZE. netdev_alloc_frag is for alloction of page fragment only. Reference to other drivers and Documentation/vm/page_frags.rst
Branch to use __get_free_pages when ring->frag_size > PAGE_SIZE.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +19 -2
@@ -527,6 +527,17 @@ static inline void mtk_rx_get_desc(struct mtk_rx_dma *rxd, rxd->rxd4 =READ_ONCE (dma_rxd->rxd4); } +static void *mtk_max_lro_buf_alloc (gfp_t gfp_mask) +{ +unsigned int size =mtk_max_frag_size (MTK_MAX_LRO_RX_LENGTH ); +unsigned long data; + + data =__get_free_pages (gfp_mask | __GFP_COMP | __GFP_NOWARN, +get_order (size)); + +return (void *)data; +} +/* the qdma core needs scratch memory to be setup */ static int mtk_init_fq_dma (struct mtk_eth *eth) {
@@ -928,7 +939,10 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, goto release_desc;/* alloc new buffer */ - new_data =napi_alloc_frag (ring->frag_size); +if (ring->frag_size <=PAGE_SIZE ) + new_data =napi_alloc_frag (ring->frag_size); +else + new_data =mtk_max_lro_buf_alloc (GFP_ATOMIC );if (unlikely (!new_data)) { netdev->stats.rx_dropped++; goto release_desc;
@@ -1231,7 +1245,10 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)return -ENOMEM ;for (i =0 ; i < rx_dma_size; i++) { - ring->data[i] =netdev_alloc_frag (ring->frag_size); +if (ring->frag_size <=PAGE_SIZE ) + ring->data[i] =netdev_alloc_frag (ring->frag_size); +else + ring->data[i] =mtk_max_lro_buf_alloc (GFP_KERNEL );if (!ring->data[i])return -ENOMEM ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 237/264 random: credit cpu and bootloader seeds by default
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
[ Upstream commit 846bb97e131d7938847963cca00657c995b1fce1 ]
This commit changes the default Kconfig values of RANDOM_TRUST_CPU and RANDOM_TRUST_BOOTLOADER to be Y by default. It does not change any existing configs or change any kernel behavior. The reason for this is several fold.
As background, I recently had an email thread with the kernel maintainers of Fedora/RHEL, Debian, Ubuntu, Gentoo, Arch, NixOS, Alpine, SUSE, and Void as recipients. I noted that some distros trust RDRAND, some trust EFI, and some trust both, and I asked why or why not. There wasn't really much of a "debate" but rather an interesting discussion of what the historical reasons have been for this, and it came up that some distros just missed the introduction of the bootloader Kconfig knob, while another didn't want to enable it until there was a boot time switch to turn it off for more concerned users (which has since been added). The result of the rather uneventful discussion is that every major Linux distro enables these two options by default.
While I didn't have really too strong of an opinion going into this thread -- and I mostly wanted to learn what the distros' thinking was one way or another -- ultimately I think their choice was a decent enough one for a default option (which can be disabled at boot time). I'll try to summarize the pros and cons:
Pros:
- The RNG machinery gets initialized super quickly, and there's no messing around with subsequent blocking behavior.
- The bootloader mechanism is used by kexec in order for the prior kernel to initialize the RNG of the next kernel, which increases the entropy available to early boot daemons of the next kernel.
- Previous objections related to backdoors centered around Dual_EC_DRBG-like kleptographic systems, in which observing some amount of the output stream enables an adversary holding the right key to determine the entire output stream.
This used to be a partially justified concern, because RDRAND output was mixed into the output stream in varying ways, some of which may have lacked pre-image resistance (e.g. XOR or an LFSR).
But this is no longer the case. Now, all usage of RDRAND and bootloader seeds go through a cryptographic hash function. This means that the CPU would have to compute a hash pre-image, which is not considered to be feasible (otherwise the hash function would be terribly broken).
- More generally, if the CPU is backdoored, the RNG is probably not the realistic vector of choice for an attacker.
- These CPU or bootloader seeds are far from being the only source of entropy. Rather, there is generally a pretty huge amount of entropy, not all of which is credited, especially on CPUs that support instructions like RDRAND. In other words, assuming RDRAND outputs all zeros, an attacker would *still* have to accurately model every single other entropy source also in use.
- The RNG now reseeds itself quite rapidly during boot, starting at 2 seconds, then 4, then 8, then 16, and so forth, so that other sources of entropy get used without much delay.
- Paranoid users can set random.trust_{cpu,bootloader}=no in the kernel command line, and paranoid system builders can set the Kconfig options to N, so there's no reduction or restriction of optionality.
- It's a practical default.
- All the distros have it set this way. Microsoft and Apple trust it too. Bandwagon.
Cons:
- RDRAND *could* still be backdoored with something like a fixed key or limited space serial number seed or another indexable scheme like that. (However, it's hard to imagine threat models where the CPU is backdoored like this, yet people are still okay making *any* computations with it or connecting it to networks, etc.)
- RDRAND *could* be defective, rather than backdoored, and produce garbage that is in one way or another insufficient for crypto.
- Suggesting a *reduction* in paranoia, as this commit effectively does, may cause some to question my personal integrity as a "security person".
- Bootloader seeds and RDRAND are generally very difficult if not all together impossible to audit.
Keep in mind that this doesn't actually change any behavior. This is just a change in the default Kconfig value. The distros already are shipping kernels that set things this way.
Ard made an additional argument in [1]:
We're at the mercy of firmware and micro-architecture anyway, given that we are also relying on it to ensure that every instruction in the kernel's executable image has been faithfully copied to memory, and that the CPU implements those instructions as documented. So I don't think firmware or ISA bugs related to RNGs deserve special treatment - if they are broken, we should quirk around them like we usually do. So enabling these by default is a step in the right direction IMHO.
In [2], Phil pointed out that having this disabled masked a bug that CI otherwise would have caught:
A clean 5.15.45 boots cleanly, whereas a downstream kernel shows the static key warning (but it does go on to boot). The significant difference is that our defconfigs set CONFIG_RANDOM_TRUST_BOOTLOADER=y defining that on top of multi_v7_defconfig demonstrates the issue on a clean 5.15.45. Conversely, not setting that option in a downstream kernel build avoids the warning
[1] https://lore.kernel.org/lkml/CAMj1kXGi+ieviFjXv9zQBSaGyyzeGW_VpMpTLJK8PJb2QHEQ-w@mail.gmail.com/
[2] https://lore.kernel.org/lkml/[email protected]/
--- drivers/char/Kconfig | 54 +++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 21 deletions(-)
drivers/char/Kconfig +33 -21
@@ -593,29 +593,41 @@ config TILE_SROM source "drivers/char/xillybus/Kconfig" -endmenu - config RANDOM_TRUST_CPU - bool "Trust the CPU manufacturer to initialize Linux's CRNG" - depends on X86 || S390 || PPC - default n + bool "Initialize RNG using CPU RNG instructions" + default y + depends on ARCH_RANDOM help - Assume that CPU manufacturer (e.g., Intel or AMD for RDSEED or - RDRAND, IBM for the S390 and Power PC architectures) is trustworthy - for the purposes of initializing Linux's CRNG. Since this is not - something that can be independently audited, this amounts to trusting - that CPU manufacturer (perhaps with the insistence or mandate - of a Nation State's intelligence or law enforcement agencies) - has not installed a hidden back door to compromise the CPU's - random number generation facilities. This can also be configured - at boot with "random.trust_cpu=on/off". + Initialize the RNG using random numbers supplied by the CPU's + RNG instructions (e.g. RDRAND), if supported and available. These + random numbers are never used directly, but are rather hashed into + the main input pool, and this happens regardless of whether or not + this option is enabled. Instead, this option controls whether the + they are credited and hence can initialize the RNG. Additionally, + other sources of randomness are always used, regardless of this + setting. Enabling this implies trusting that the CPU can supply high + quality and non-backdoored random numbers. + + Say Y here unless you have reason to mistrust your CPU or believe + its RNG facilities may be faulty. This may also be configured at + boot time with "random.trust_cpu=on/off". config RANDOM_TRUST_BOOTLOADER - bool "Trust the bootloader to initialize Linux's CRNG" + bool "Initialize RNG using bootloader-supplied seed" + default y help - Some bootloaders can provide entropy to increase the kernel's initial - device randomness. Say Y here to assume the entropy provided by the - booloader is trustworthy so it will be added to the kernel's entropy - pool. Otherwise, say N here so it will be regarded as device input that - only mixes the entropy pool. This can also be configured at boot with - "random.trust_bootloader=on/off". + Initialize the RNG using a seed supplied by the bootloader or boot + environment (e.g. EFI or a bootloader-generated device tree). This + seed is not used directly, but is rather hashed into the main input + pool, and this happens regardless of whether or not this option is + enabled. Instead, this option controls whether the seed is credited + and hence can initialize the RNG. Additionally, other sources of + randomness are always used, regardless of this setting. Enabling + this implies trusting that the bootloader can supply high quality and + non-backdoored seeds. + + Say Y here unless you have reason to mistrust your bootloader or + believe its RNG facilities may be faulty. This may also be configured + at boot time with "random.trust_bootloader=on/off". + +endmenu
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 238/264 pNFS: Dont keep retrying if the server replied NFS4ERR_LAYOUTUNAVAILABLE
In reply to Greg Kroah-HartmanFrom: Trond Myklebust <[email protected]>
[ Upstream commit fe44fb23d6ccde4c914c44ef74ab8d9d9ba02bea ]
If the server tells us that a pNFS layout is not available for a specific file, then we should not keep pounding it with further layoutget requests.
--- fs/nfs/pnfs.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/nfs/pnfs.c +6 -0
@@ -1753,6 +1753,12 @@ pnfs_update_layout(struct inode *ino,/* Fallthrough */ case -EAGAIN :break ; +case -ENODATA : +/* The server returned NFS4ERR_LAYOUTUNAVAILABLE */ +pnfs_layout_set_fail_bit ( + lo,pnfs_iomode_to_fail_bit (iomode)); + lseg =NULL ; + goto out_put_layout_hdr;default :if (!nfs_error_is_fatal (PTR_ERR (lseg))) {pnfs_layout_clear_fail_bit (lo,pnfs_iomode_to_fail_bit (iomode));
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 239/264 misc: atmel-ssc: Fix IRQ check in ssc_probe
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
[ Upstream commit 1c245358ce0b13669f6d1625f7a4e05c41f28980 ]
platform_get_irq() returns negative error number instead 0 on failure. And the doc of platform_get_irq() provides a usage example:
int irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;Fix the check of return value to catch errors correctly.
--- drivers/misc/atmel-ssc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/atmel-ssc.c +2 -2
@@ -190,9 +190,9 @@ static int ssc_probe(struct platform_device *pdev)clk_disable_unprepare (ssc->clk); ssc->irq =platform_get_irq (pdev,0 ); -if (!ssc->irq) { +if (ssc->irq <0 ) {dev_dbg (&pdev->dev,"could not get irq\n" ); -return -ENXIO ; +return ssc->irq; }mutex_lock (&user_lock);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 240/264 irqchip/gic/realview: Fix refcount leak in realview_gic_of_init
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
[ Upstream commit f4b98e314888cc51486421bcf6d52852452ea48b ]
of_find_matching_node_and_match() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.
--- drivers/irqchip/irq-gic-realview.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-realview.c +1 -0
@@ -56,6 +56,7 @@ realview_gic_of_init(struct device_node *node, struct device_node *parent)/* The PB11MPCore GIC needs to be configured in the syscon */ map =syscon_node_to_regmap (np); +of_node_put (np);if (!IS_ERR (map)) {/* new irq mode with no DCC */ regmap_write(map, REALVIEW_SYS_LOCK_OFFSET,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 241/264 irqchip/gic-v3: Iterate over possible CPUs by for_each_possible_cpu()
In reply to Greg Kroah-HartmanFrom: zijun_hu <[email protected]>
[ Upstream commit 3fad4cdac235c5b13227d0c09854c689ae62c70b ]
get_cpu_number() doesn't use existing helper to iterate over possible CPUs, It will cause an error in case of discontinuous @cpu_possible_mask such as 0b11110001, which can result from a core having failed to come up on a SMP machine.
Fixed by using existing helper for_each_possible_cpu().
--- drivers/irqchip/irq-gic-v3.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/irqchip/irq-gic-v3.c +4 -4
@@ -982,7 +982,7 @@ static int get_cpu_number(struct device_node *dn) {const __be32 *cell;u64 hwid; -int i; +int cpu; cell =of_get_property (dn,"reg" ,NULL );if (!cell)
@@ -996,9 +996,9 @@ static int get_cpu_number(struct device_node *dn)if (hwid & ~MPIDR_HWID_BITMASK )return -1 ; -for (i =0 ; i <num_possible_cpus (); i++) -if (cpu_logical_map (i) == hwid) -return i; +for_each_possible_cpu (cpu) +if (cpu_logical_map (cpu) == hwid) +return cpu;return -1 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 242/264 comedi: vmk80xx: fix expression for tx buffer size
In reply to Greg Kroah-HartmanFrom: Ian Abbott <[email protected]>
commit 242439f7e279d86b3f73b5de724bc67b2f8aeb07 upstream.
The expression for setting the size of the allocated bulk TX buffer (devpriv->usb_tx_buf) is calling usb_endpoint_maxp(devpriv->ep_rx), which is using the wrong endpoint (should be devpriv->ep_tx). Fix it.
--- drivers/staging/comedi/drivers/vmk80xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/comedi/drivers/vmk80xx.c +1 -1
@@ -694,7 +694,7 @@ static int vmk80xx_alloc_usb_buffers(strif (!devpriv->usb_rx_buf)return -ENOMEM ; - size =max (usb_endpoint_maxp (devpriv->ep_rx),MIN_BUF_SIZE ); + size =max (usb_endpoint_maxp (devpriv->ep_tx),MIN_BUF_SIZE ); devpriv->usb_tx_buf =kzalloc (size,GFP_KERNEL );if (!devpriv->usb_tx_buf)return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 243/264 USB: serial: option: add support for Cinterion MV31 with new baseline
In reply to Greg Kroah-HartmanFrom: Slark Xiao <[email protected]>
commit 158f7585bfcea4aae0ad4128d032a80fec550df1 upstream.
Adding support for Cinterion device MV31 with Qualcomm new baseline. Use different PIDs to separate it from previous base line products.
All interfaces settings keep same as previous.
Below is test evidence:
T: Bus=03 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 6 Spd=480 MxCh= 0 D: Ver= 2.10 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=1e2d ProdID=00b8 Rev=04.14 S: Manufacturer=Cinterion S: Product=Cinterion PID 0x00B8 USB Mobile Broadband S: SerialNumber=90418e79 C: #Ifs= 6 Cfg#= 1 Atr=a0 MxPwr=500mA I: If#=0x0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=0e Prot=00 Driver=cdc_mbim I: If#=0x1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim I: If#=0x2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option I: If#=0x3 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none) I: If#=0x4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=60 Driver=option I: If#=0x5 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option
T: Bus=03 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 7 Spd=480 MxCh= 0 D: Ver= 2.10 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=1e2d ProdID=00b9 Rev=04.14 S: Manufacturer=Cinterion S: Product=Cinterion PID 0x00B9 USB Mobile Broadband S: SerialNumber=90418e79 C: #Ifs= 4 Cfg#= 1 Atr=a0 MxPwr=500mA I: If#=0x0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=50 Driver=qmi_wwan I: If#=0x1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option I: If#=0x2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=60 Driver=option I: If#=0x3 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option
For PID 00b8, interface 3 is GNSS port which don't use serial driver.
--- drivers/usb/serial/option.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/usb/serial/option.c +6 -0
@@ -430,6 +430,8 @@ static void option_instat_callback(struc#define CINTERION_PRODUCT_CLS8 0x00b0#define CINTERION_PRODUCT_MV31_MBIM 0x00b3#define CINTERION_PRODUCT_MV31_RMNET 0x00b7 +#define CINTERION_PRODUCT_MV31_2_MBIM 0x00b8 +#define CINTERION_PRODUCT_MV31_2_RMNET 0x00b9#define CINTERION_PRODUCT_MV32_WA 0x00f1#define CINTERION_PRODUCT_MV32_WB 0x00f2
@@ -1953,6 +1955,10 @@ static const struct usb_device_id option .driver_info = RSVD(3)}, { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV31_RMNET, 0xff), .driver_info = RSVD(0)}, + { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV31_2_MBIM, 0xff), + .driver_info = RSVD(3)}, + { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV31_2_RMNET, 0xff), + .driver_info = RSVD(0)}, { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV32_WA, 0xff), .driver_info = RSVD(3)}, { USB_DEVICE_INTERFACE_CLASS(CINTERION_VENDOR_ID, CINTERION_PRODUCT_MV32_WB, 0xff),
Greg Kroah-Hartman
maintainerPATCH 244/264 USB: serial: io_ti: add Agilent E5805A support
In reply to Greg Kroah-HartmanFrom: Robert Eckelmann <[email protected]>
commit 908e698f2149c3d6a67d9ae15c75545a3f392559 upstream.
Add support for Agilent E5805A (rebranded ION Edgeport/4) to io_ti.
--- drivers/usb/serial/io_ti.c | 2 ++ drivers/usb/serial/io_usbvend.h | 1 + 2 files changed, 3 insertions(+)
drivers/usb/serial/io_ti.c +2 -0
@@ -172,6 +172,7 @@ static const struct usb_device_id edgepo { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) }, { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) }, { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) }, + { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_E5805A) }, { } };
@@ -210,6 +211,7 @@ static const struct usb_device_id id_tab { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_8S) }, { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416) }, { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_416B) }, + { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_E5805A) }, { } };
drivers/usb/serial/io_usbvend.h +1 -0
@@ -215,6 +215,7 @@// // Definitions for other product IDs #define ION_DEVICE_ID_MT4X56USB 0x1403 // OEM device +#define ION_DEVICE_ID_E5805A 0x1A01 // OEM device (rebranded Edgeport/4)#define GENERATION_ID_FROM_USB_PRODUCT_ID (ProductId) \
Greg Kroah-Hartman
maintainerPATCH 245/264 usb: gadget: lpc32xx_udc: Fix refcount leak in lpc32xx_udc_probe
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
commit 4757c9ade34178b351580133771f510b5ffcf9c8 upstream.
of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak. of_node_put() will check NULL pointer.
--- drivers/usb/gadget/udc/lpc32xx_udc.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/gadget/udc/lpc32xx_udc.c +1 -0
@@ -3034,6 +3034,7 @@ static int lpc32xx_udc_probe(struct plat } udc->isp1301_i2c_client =isp1301_get_client (isp1301_node); +of_node_put (isp1301_node);if (!udc->isp1301_i2c_client) { retval = -EPROBE_DEFER ; goto phy_fail;
Greg Kroah-Hartman
maintainerPATCH 246/264 serial: 8250: Store to lsr_save_flags after lsr read
In reply to Greg Kroah-HartmanFrom: Ilpo Järvinen <[email protected]>
commit be03b0651ffd8bab69dfd574c6818b446c0753ce upstream.
Not all LSR register flags are preserved across reads. Therefore, LSR readers must store the non-preserved bits into lsr_save_flags.
This fix was initially mixed into feature commit f6f586102add ("serial:
8250: Handle UART without interrupt on TEMT using em485"). However, that feature change had a flaw and it was reverted to make room for simpler approach providing the same feature. The embedded fix got reverted with the feature change.
Re-add the lsr_save_flags fix and properly mark it's a fix.
--- drivers/tty/serial/8250/8250_port.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/serial/8250/8250_port.c +2 -0
@@ -1473,6 +1473,8 @@ static inline void __stop_tx(struct uartif (em485) {unsigned char lsr =serial_in (p,UART_LSR ); + p->lsr_saved_flags |= lsr &LSR_SAVE_FLAGS ; +/* * To provide required timeing and allow FIFO transfer, * __stop_tx_rs485() must be called only when both FIFO and
Greg Kroah-Hartman
maintainerPATCH 247/264 ext4: fix bug_on ext4_mb_use_inode_pa
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit a08f789d2ab5242c07e716baf9a835725046be89 upstream.
Hulk Robot reported a BUG_ON:
==================================================================
kernel BUG at fs/ext4/mballoc.c:3211!
[...]
RIP: 0010:ext4_mb_mark_diskspace_used.cold+0x85/0x136f [...] Call Trace: ext4_mb_new_blocks+0x9df/0x5d30 ext4_ext_map_blocks+0x1803/0x4d80 ext4_map_blocks+0x3a4/0x1a10 ext4_writepages+0x126d/0x2c30 do_writepages+0x7f/0x1b0 __filemap_fdatawrite_range+0x285/0x3b0 file_write_and_wait_range+0xb1/0x140 ext4_sync_file+0x1aa/0xca0 vfs_fsync_range+0xfb/0x260 do_fsync+0x48/0xa0
[...]
==================================================================
Above issue may happen as follows:
-------------------------------------do_fsync
vfs_fsync_range
ext4_sync_file
file_write_and_wait_range
__filemap_fdatawrite_range
do_writepages
ext4_writepages
mpage_map_and_submit_extent
mpage_map_one_extent
ext4_map_blocks
ext4_mb_new_blocks
ext4_mb_normalize_request
>>> start + size <= ac->ac_o_ex.fe_logical
ext4_mb_regular_allocator
ext4_mb_simple_scan_group
ext4_mb_use_best_found
ext4_mb_new_preallocation
ext4_mb_new_inode_pa
ext4_mb_use_inode_pa
>>> set ac->ac_b_ex.fe_len <= 0
ext4_mb_mark_diskspace_used
>>> BUG_ON(ac->ac_b_ex.fe_len <= 0);we can easily reproduce this problem with the following commands:
`fallocate -l100M disk` `mkfs.ext4 -b 1024 -g 256 disk` `mount disk /mnt` `fsstress -d /mnt -l 0 -n 1000 -p 1`
The size must be smaller than or equal to EXT4_BLOCKS_PER_GROUP. Therefore, "start + size <= ac->ac_o_ex.fe_logical" may occur when the size is truncated. So start should be the start position of the group where ac_o_ex.fe_logical is located after alignment. In addition, when the value of fe_logical or EXT4_BLOCKS_PER_GROUP is very large, the value calculated by start_off is more accurate.
--- fs/ext4/mballoc.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/ext4/mballoc.c +9 -0
@@ -3142,6 +3142,15 @@ ext4_mb_normalize_request(struct ext4_al size = size >> bsbits; start = start_off >> bsbits; +/* +* For tiny groups (smaller than 8MB) the chosen allocation +* alignment may be larger than group size. Make sure the +* alignment does not move allocation to a different group which +* makes mballoc fail assertions later. +*/ + start =max (start,rounddown (ac->ac_o_ex.fe_logical, + (ext4_lblk_t )EXT4_BLOCKS_PER_GROUP (ac->ac_sb))); +/* don't cover already allocated blocks in selected range */ if (ar->pleft && start <= ar->lleft) { size -= ar->lleft +1 - start;
Greg Kroah-Hartman
maintainerPATCH 248/264 ext4: make variable "count" signed
In reply to Greg Kroah-HartmanFrom: Ding Xiang <[email protected]>
commit bc75a6eb856cb1507fa907bf6c1eda91b3fef52f upstream.
Since dx_make_map() may return -EFSCORRUPTED now, so change "count" to be a signed integer so we can correctly check for an error code returned by dx_make_map().
--- fs/ext4/namei.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/namei.c +2 -1
@@ -1726,7 +1726,8 @@ static struct ext4_dir_entry_2 *do_split struct dx_hash_info *hinfo) {unsigned blocksize = dir->i_sb->s_blocksize; -unsigned count, continued; +unsigned continued; +int count;struct buffer_head *bh2;ext4_lblk_t newblock;u32 hash2;
Greg Kroah-Hartman
maintainerPATCH 249/264 ext4: add reserved GDT blocks check
In reply to Greg Kroah-HartmanFrom: Zhang Yi <[email protected]>
commit b55c3cd102a6f48b90e61c44f7f3dda8c290c694 upstream.
We capture a NULL pointer issue when resizing a corrupt ext4 image which is freshly clear resize_inode feature (not run e2fsck). It could be simply reproduced by following steps. The problem is because of the resize_inode feature was cleared, and it will convert the filesystem to meta_bg mode in ext4_resize_fs(), but the es->s_reserved_gdt_blocks was not reduced to zero, so could we mistakenly call reserve_backup_gdb() and passing an uninitialized resize_inode to it when adding new group descriptors.
mkfs.ext4 /dev/sda 3G
tune2fs -O ^resize_inode /dev/sda #forget to run requested e2fsck mount /dev/sda /mnt
resize2fs /dev/sda 8G
========
BUG: kernel NULL pointer dereference, address: 0000000000000028 CPU: 19 PID: 3243 Comm: resize2fs Not tainted 5.18.0-rc7-00001-gfde086c5ebfd #748 ... RIP: 0010:ext4_flex_group_add+0xe08/0x2570 ... Call Trace: <TASK> ext4_resize_fs+0xbec/0x1660 __ext4_ioctl+0x1749/0x24e0 ext4_ioctl+0x12/0x20 __x64_sys_ioctl+0xa6/0x110 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xae RIP: 0033:0x7f2dd739617b ========
The fix is simple, add a check in ext4_resize_begin() to make sure that the es->s_reserved_gdt_blocks is zero when the resize_inode feature is disabled.
--- fs/ext4/resize.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/ext4/resize.c +10 -0
@@ -52,6 +52,16 @@ int ext4_resize_begin(struct super_blockreturn -EPERM ;/* +* If the reserved GDT blocks is non-zero, the resize_inode feature +* should always be set. +*/ +if (EXT4_SB (sb)->s_es->s_reserved_gdt_blocks && + !ext4_has_feature_resize_inode (sb)) { +ext4_error (sb,"resize_inode disabled but reserved GDT blocks non-zero" ); +return -EFSCORRUPTED ; + } + +/* * If we are not using the primary superblock/GDT copy don't resize, * because the user tools have no way of handling this. Probably a * bad time to do it anyways.
Greg Kroah-Hartman
maintainerPATCH 250/264 l2tp: dont use inet_shutdown on ppp session destroy
In reply to Greg Kroah-HartmanFrom: James Chapman <[email protected]>
commit 225eb26489d05c679a4c4197ffcb81c81e9dcaf4 upstream.
Previously, if a ppp session was closed, we called inet_shutdown to mark the socket as unconnected such that userspace would get errors and then close the socket. This could race with userspace closing the socket. Instead, leave userspace to close the socket in its own time (our session will be detached anyway).
BUG: KASAN: use-after-free in inet_shutdown+0x5d/0x1c0 Read of size 4 at addr ffff880010ea3ac0 by task syzbot_347bd5ac/8296 CPU: 3 PID: 8296 Comm: syzbot_347bd5ac Not tainted 4.16.0-rc1+ #91 Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 Call Trace: dump_stack+0x101/0x157 ? inet_shutdown+0x5d/0x1c0 print_address_description+0x78/0x260 ? inet_shutdown+0x5d/0x1c0 kasan_report+0x240/0x360 __asan_load4+0x78/0x80 inet_shutdown+0x5d/0x1c0 ? pppol2tp_show+0x80/0x80 pppol2tp_session_close+0x68/0xb0 l2tp_tunnel_closeall+0x199/0x210 ? udp_v6_flush_pending_frames+0x90/0x90 l2tp_udp_encap_destroy+0x6b/0xc0 ? l2tp_tunnel_del_work+0x2e0/0x2e0 udpv6_destroy_sock+0x8c/0x90 sk_common_release+0x47/0x190 udp_lib_close+0x15/0x20 inet_release+0x85/0xd0 inet6_release+0x43/0x60 sock_release+0x53/0x100 ? sock_alloc_file+0x260/0x260 sock_close+0x1b/0x20 __fput+0x19f/0x380 ____fput+0x1a/0x20 task_work_run+0xd2/0x110 exit_to_usermode_loop+0x18d/0x190 do_syscall_64+0x389/0x3b0 entry_SYSCALL_64_after_hwframe+0x26/0x9b RIP: 0033:0x7fe240a45259 RSP: 002b:00007fe241132df8 EFLAGS: 00000297 ORIG_RAX: 0000000000000003 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00007fe240a45259 RDX: 00007fe240a45259 RSI: 0000000000000000 RDI: 00000000000000a5 RBP: 00007fe241132e20 R08: 00007fe241133700 R09: 0000000000000000 R10: 00007fe241133700 R11: 0000000000000297 R12: 0000000000000000 R13: 00007ffc49aff84f R14: 0000000000000000 R15: 00007fe241141040 Allocated by task 8331: save_stack+0x43/0xd0 kasan_kmalloc+0xad/0xe0 kasan_slab_alloc+0x12/0x20 kmem_cache_alloc+0x144/0x3e0 sock_alloc_inode+0x22/0x130 alloc_inode+0x3d/0xf0 new_inode_pseudo+0x1c/0x90 sock_alloc+0x30/0x110 __sock_create+0xaa/0x4c0 SyS_socket+0xbe/0x130 do_syscall_64+0x128/0x3b0 entry_SYSCALL_64_after_hwframe+0x26/0x9b Freed by task 8314: save_stack+0x43/0xd0 __kasan_slab_free+0x11a/0x170 kasan_slab_free+0xe/0x10 kmem_cache_free+0x88/0x2b0 sock_destroy_inode+0x49/0x50 destroy_inode+0x77/0xb0 evict+0x285/0x340 iput+0x429/0x530 dentry_unlink_inode+0x28c/0x2c0 __dentry_kill+0x1e3/0x2f0 dput.part.21+0x500/0x560 dput+0x24/0x30 __fput+0x2aa/0x380 ____fput+0x1a/0x20 task_work_run+0xd2/0x110 exit_to_usermode_loop+0x18d/0x190 do_syscall_64+0x389/0x3b0 entry_SYSCALL_64_after_hwframe+0x26/0x9b
--- net/l2tp/l2tp_ppp.c | 10 ---------- 1 file changed, 10 deletions(-)
net/l2tp/l2tp_ppp.c +0 -10
@@ -439,16 +439,6 @@ abort:*/ static void pppol2tp_session_close (struct l2tp_session *session) { -struct sock *sk; - -BUG_ON (session->magic !=L2TP_SESSION_MAGIC ); - - sk =pppol2tp_session_get_sock (session); -if (sk) { -if (sk->sk_socket) -inet_shutdown (sk->sk_socket,SEND_SHUTDOWN ); -sock_put (sk); - } }/* Really kill the session socket. (Called from sock_put() if
Greg Kroah-Hartman
maintainerPATCH 251/264 l2tp: fix race in pppol2tp_release with session object destroy
In reply to Greg Kroah-HartmanFrom: James Chapman <[email protected]>
commit d02ba2a6110c530a32926af8ad441111774d2893 upstream.
pppol2tp_release uses call_rcu to put the final ref on its socket. But the session object doesn't hold a ref on the session socket so may be freed while the pppol2tp_put_sk RCU callback is scheduled. Fix this by having the session hold a ref on its socket until the session is destroyed. It is this ref that is dropped via call_rcu.
Sessions are also deleted via l2tp_tunnel_closeall. This must now also put the final ref via call_rcu. So move the call_rcu call site into pppol2tp_session_close so that this happens in both destroy paths. A common destroy path should really be implemented, perhaps with l2tp_tunnel_closeall calling l2tp_session_delete like pppol2tp_release does, but this will be looked at later.
ODEBUG: activate active (active state 1) object type: rcu_head hint: (null)
WARNING: CPU: 3 PID: 13407 at lib/debugobjects.c:291 debug_print_object+0x166/0x220 Modules linked in: CPU: 3 PID: 13407 Comm: syzbot_19c09769 Not tainted 4.16.0-rc2+ #38 Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 RIP: 0010:debug_print_object+0x166/0x220 RSP: 0018:ffff880013647a00 EFLAGS: 00010082 RAX: dffffc0000000008 RBX: 0000000000000003 RCX: ffffffff814d3333 RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffff88001a59f6d0 RBP: ffff880013647a40 R08: 0000000000000000 R09: 0000000000000001 R10: ffff8800136479a8 R11: 0000000000000000 R12: 0000000000000001 R13: ffffffff86161420 R14: ffffffff85648b60 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff88001a580000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000020e77000 CR3: 0000000006022000 CR4: 00000000000006e0 Call Trace: debug_object_activate+0x38b/0x530 ? debug_object_assert_init+0x3b0/0x3b0 ? __mutex_unlock_slowpath+0x85/0x8b0 ? pppol2tp_session_destruct+0x110/0x110 __call_rcu.constprop.66+0x39/0x890 ? __call_rcu.constprop.66+0x39/0x890 call_rcu_sched+0x17/0x20 pppol2tp_release+0x2c7/0x440 ? fcntl_setlk+0xca0/0xca0 ? sock_alloc_file+0x340/0x340 sock_release+0x92/0x1e0 sock_close+0x1b/0x20 __fput+0x296/0x6e0 ____fput+0x1a/0x20 task_work_run+0x127/0x1a0 do_exit+0x7f9/0x2ce0 ? SYSC_connect+0x212/0x310 ? mm_update_next_owner+0x690/0x690 ? up_read+0x1f/0x40 ? __do_page_fault+0x3c8/0xca0 do_group_exit+0x10d/0x330 ? do_group_exit+0x330/0x330 SyS_exit_group+0x22/0x30 do_syscall_64+0x1e0/0x730 ? trace_hardirqs_off_thunk+0x1a/0x1c entry_SYSCALL_64_after_hwframe+0x42/0xb7 RIP: 0033:0x7f362e471259 RSP: 002b:00007ffe389abe08 EFLAGS: 00000202 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f362e471259 RDX: 00007f362e471259 RSI: 000000000000002e RDI: 0000000000000000 RBP: 00007ffe389abe30 R08: 0000000000000000 R09: 00007f362e944270 R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000400b60 R13: 00007ffe389abf50 R14: 0000000000000000 R15: 0000000000000000 Code: 8d 3c dd a0 8f 64 85 48 89 fa 48 c1 ea 03 80 3c 02 00 75 7b 48 8b 14 dd a0 8f 64 85 4c 89 f6 48 c7 c7 20 85 64 85 e
8 2a 55 14 ff <0f> 0b 83 05 ad 2a 68 04 01 48 83 c4 18 5b 41 5c 41 5d 41 5e 41
--- net/l2tp/l2tp_ppp.c | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-)
net/l2tp/l2tp_ppp.c +27 -25
@@ -435,10 +435,28 @@ abort:* Session (and tunnel control) socket create/destroy. *****************************************************************************/ +static void pppol2tp_put_sk (struct rcu_head *head) +{ +struct pppol2tp_session *ps; + + ps =container_of (head,typeof (*ps), rcu); +sock_put (ps->__sk); +} +/* Called by l2tp_core when a session socket is being closed. */ static void pppol2tp_session_close (struct l2tp_session *session) { +struct pppol2tp_session *ps; + + ps =l2tp_session_priv (session); +mutex_lock (&ps->sk_lock); + ps->__sk =rcu_dereference_protected (ps->sk, +lockdep_is_held (&ps->sk_lock)); +RCU_INIT_POINTER (ps->sk,NULL ); +if (ps->__sk) +call_rcu (&ps->rcu, pppol2tp_put_sk); +mutex_unlock (&ps->sk_lock); }/* Really kill the session socket. (Called from sock_put() if
@@ -458,14 +476,6 @@ static void pppol2tp_session_destruct(st } } -static void pppol2tp_put_sk (struct rcu_head *head) -{ -struct pppol2tp_session *ps; - - ps =container_of (head,typeof (*ps), rcu); -sock_put (ps->__sk); -} -/* Called when the PPPoX socket (session) is closed. */ static int pppol2tp_release (struct socket *sock)
@@ -489,26 +499,17 @@ static int pppol2tp_release(struct sockesock_orphan (sk); sock->sk =NULL ; +/* If the socket is associated with a session, +* l2tp_session_delete will call pppol2tp_session_close which +* will drop the session's ref on the socket. +*/ session =pppol2tp_sock_to_session (sk); - -if (session !=NULL ) { -struct pppol2tp_session *ps; - +if (session) {l2tp_session_delete (session); - - ps =l2tp_session_priv (session); -mutex_lock (&ps->sk_lock); - ps->__sk =rcu_dereference_protected (ps->sk, -lockdep_is_held (&ps->sk_lock)); -RCU_INIT_POINTER (ps->sk,NULL ); -mutex_unlock (&ps->sk_lock); -call_rcu (&ps->rcu, pppol2tp_put_sk); - -/* Rely on the sock_put() call at the end of the function for -* dropping the reference held by pppol2tp_sock_to_session(). -* The last reference will be dropped by pppol2tp_put_sk(). -*/ +/* drop the ref obtained by pppol2tp_sock_to_session */ +sock_put (sk); } +release_sock (sk);/* This will delete the session context via
@@ -817,6 +818,7 @@ static int pppol2tp_connect(struct socke out_no_ppp:/* This is how we get the session context from the socket. */ +sock_hold (sk); sk->sk_user_data = session;rcu_assign_pointer (ps->sk, sk);mutex_unlock (&ps->sk_lock);
Greg Kroah-Hartman
maintainerPATCH 252/264 s390/mm: use non-quiescing sske for KVM switch to keyed guest
In reply to Greg Kroah-HartmanFrom: Christian Borntraeger <[email protected]>
commit 3ae11dbcfac906a8c3a480e98660a823130dc16a upstream.
The switch to a keyed guest does not require a classic sske as the other guest CPUs are not accessing the key before the switch is complete. By using the NQ SSKE things are faster especially with multiple guests.
--- arch/s390/mm/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/mm/pgtable.c +1 -1
@@ -595,7 +595,7 @@ void ptep_zap_key(struct mm_struct *mm, PGSTE_GR_BIT | PGSTE_GC_BIT); ptev =pte_val (*ptep);if (!(ptev & _PAGE_INVALID) && (ptev & _PAGE_WRITE)) -page_set_storage_key (ptev &PAGE_MASK ,PAGE_DEFAULT_KEY ,1 ); +page_set_storage_key (ptev &PAGE_MASK ,PAGE_DEFAULT_KEY ,0 );pgste_set_unlock (ptep, pgste);preempt_enable (); }
Greg Kroah-Hartman
maintainerPATCH 253/264 xprtrdma: fix incorrect header size calculations
In reply to Greg Kroah-HartmanFrom: Colin Ian King <[email protected]>
commit 912288442cb2f431bf3c8cb097a5de83bc6dbac1 upstream.
Currently the header size calculations are using an assignment operator instead of a += operator when accumulating the header size leading to incorrect sizes. Fix this by using the correct operator.
Addresses-Coverity: ("Unused value")
--- net/sunrpc/xprtrdma/rpc_rdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/sunrpc/xprtrdma/rpc_rdma.c +2 -2
@@ -75,7 +75,7 @@ static unsigned int rpcrdma_max_call_hea/* Maximum Read list size */ maxsegs +=2 ;/* segment for head and tail buffers */ - size = maxsegs *sizeof (struct rpcrdma_read_chunk ); + size += maxsegs *sizeof (struct rpcrdma_read_chunk );/* Minimal Read chunk size */ size +=sizeof (__be32);/* segment count */
@@ -101,7 +101,7 @@ static unsigned int rpcrdma_max_reply_he/* Maximum Write list size */ maxsegs +=2 ;/* segment for head and tail buffers */ - size =sizeof (__be32);/* segment count */ + size +=sizeof (__be32);/* segment count */ size += maxsegs *sizeof (struct rpcrdma_segment ); size +=sizeof (__be32);/* list discriminator */
Greg Kroah-Hartman
maintainerPATCH 254/264 swiotlb: fix info leak with DMA_FROM_DEVICE
In reply to Greg Kroah-HartmanFrom: Halil Pasic <[email protected]>
commit ddbd89deb7d32b1fbb879f48d68fda1a8ac58e8e upstream.
The problem I'm addressing was discovered by the LTP test covering cve-2018-1000204.
A short description of what happens follows:
1) The test case issues a command code 00 (TEST UNIT READY) via the SG_IO interface with: dxfer_len == 524288, dxdfer_dir == SG_DXFER_FROM_DEV and a corresponding dxferp. The peculiar thing about this is that TUR is not reading from the device.
2) In sg_start_req() the invocation of blk_rq_map_user() effectively bounces the user-space buffer. As if the device was to transfer into it. Since commit a45b599ad808 ("scsi: sg: allocate with __GFP_ZERO in sg_build_indirect()") we make sure this first bounce buffer is allocated with GFP_ZERO.
3) For the rest of the story we keep ignoring that we have a TUR, so the device won't touch the buffer we prepare as if the we had a DMA_FROM_DEVICE type of situation. My setup uses a virtio-scsi device and the buffer allocated by SG is mapped by the function virtqueue_add_split() which uses DMA_FROM_DEVICE for the "in" sgs (here scatter-gather and not scsi generics). This mapping involves bouncing via the swiotlb (we need swiotlb to do virtio in protected guest like s390 Secure Execution, or AMD SEV).
4) When the SCSI TUR is done, we first copy back the content of the second (that is swiotlb) bounce buffer (which most likely contains some previous IO data), to the first bounce buffer, which contains all zeros. Then we copy back the content of the first bounce buffer to the user-space buffer.
5) The test case detects that the buffer, which it zero-initialized, ain't all zeros and fails.
One can argue that this is an swiotlb problem, because without swiotlb we leak all zeros, and the swiotlb should be transparent in a sense that it does not affect the outcome (if all other participants are well behaved).
Copying the content of the original buffer into the swiotlb buffer is the only way I can think of to make swiotlb transparent in such scenarios. So let's do just that if in doubt, but allow the driver to tell us that the whole mapped buffer is going to be overwritten, in which case we can preserve the old behavior and avoid the performance impact of the extra bounce.
--- Documentation/DMA-attributes.txt | 10 ++++++++++ include/linux/dma-mapping.h | 7 +++++++ lib/swiotlb.c | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-)
Documentation/DMA-attributes.txt +10 -0
@@ -143,3 +143,13 @@ So, this provides a way for drivers to a where allocation failures are not a problem, and shouldn't bother the logs. NOTE: At the moment DMA_ATTR_NO_WARN is only implemented on PowerPC. + +DMA_ATTR_PRIVILEGED +------------------- + +Some advanced peripherals such as remote processors and GPUs perform +accesses to DMA buffers in both privileged "supervisor" and unprivileged +"user" modes. This attribute is used to indicate to the DMA-mapping +subsystem that the buffer is fully accessible at the elevated privilege +level (and ideally inaccessible or at least read-only at the +lesser-privileged levels).
include/linux/dma-mapping.h +7 -0
@@ -61,6 +61,13 @@* allocation failure reports (similarly to __GFP_NOWARN). */ #define DMA_ATTR_NO_WARN (1UL << 8) +/* +* This is a hint to the DMA-mapping subsystem that the device is expected +* to overwrite the entire mapped size, thus the caller does not require any +* of the previous buffer contents to be preserved. This allows +* bounce-buffering implementations to optimise DMA_FROM_DEVICE transfers. +*/ +#define DMA_ATTR_OVERWRITE (1UL << 10)/* * A dma_addr_t can hold any valid DMA or bus address for the platform.
lib/swiotlb.c +2 -1
@@ -532,7 +532,8 @@ found:*/ for (i =0 ; i < nslots; i++) io_tlb_orig_addr[index+i] = orig_addr + (i <<IO_TLB_SHIFT ); -if (dir ==DMA_TO_DEVICE || dir ==DMA_BIDIRECTIONAL ) +if (!(attrs &DMA_ATTR_OVERWRITE ) || dir ==DMA_TO_DEVICE || + dir ==DMA_BIDIRECTIONAL )swiotlb_bounce (orig_addr, tlb_addr, size,DMA_TO_DEVICE );return tlb_addr;
Greg Kroah-Hartman
maintainerPATCH 255/264 Reinstate some of "swiotlb: rework "fix info leak with DMA_FROM_DEVICE""
In reply to Greg Kroah-HartmanFrom: Linus Torvalds <[email protected]>
commit 901c7280ca0d5e2b4a8929fbe0bfb007ac2a6544 upstream.
Halil Pasic points out [1] that the full revert of that commit (revert in bddac7c1e02b), and that a partial revert that only reverts the problematic case, but still keeps some of the cleanups is probably better. 
And that partial revert [2] had already been verified by Oleksandr Natalenko to also fix the issue, I had just missed that in the long discussion.
So let's reinstate the cleanups from commit aa6f8dcbab47 ("swiotlb:
rework "fix info leak with DMA_FROM_DEVICE""), and effectively only revert the part that caused problems.
--- Documentation/DMA-attributes.txt | 10 ---------- include/linux/dma-mapping.h | 7 ------- lib/swiotlb.c | 12 ++++++++---- 3 files changed, 8 insertions(+), 21 deletions(-)
Documentation/DMA-attributes.txt +0 -10
@@ -143,13 +143,3 @@ So, this provides a way for drivers to a where allocation failures are not a problem, and shouldn't bother the logs. NOTE: At the moment DMA_ATTR_NO_WARN is only implemented on PowerPC. - -DMA_ATTR_PRIVILEGED -------------------- - -Some advanced peripherals such as remote processors and GPUs perform -accesses to DMA buffers in both privileged "supervisor" and unprivileged -"user" modes. This attribute is used to indicate to the DMA-mapping -subsystem that the buffer is fully accessible at the elevated privilege -level (and ideally inaccessible or at least read-only at the -lesser-privileged levels).
include/linux/dma-mapping.h +0 -7
@@ -61,13 +61,6 @@* allocation failure reports (similarly to __GFP_NOWARN). */ #define DMA_ATTR_NO_WARN (1UL << 8) -/* -* This is a hint to the DMA-mapping subsystem that the device is expected -* to overwrite the entire mapped size, thus the caller does not require any -* of the previous buffer contents to be preserved. This allows -* bounce-buffering implementations to optimise DMA_FROM_DEVICE transfers. -*/ -#define DMA_ATTR_OVERWRITE (1UL << 10)/* * A dma_addr_t can hold any valid DMA or bus address for the platform.
lib/swiotlb.c +8 -4
@@ -532,10 +532,14 @@ found:*/ for (i =0 ; i < nslots; i++) io_tlb_orig_addr[index+i] = orig_addr + (i <<IO_TLB_SHIFT ); -if (!(attrs &DMA_ATTR_OVERWRITE ) || dir ==DMA_TO_DEVICE || - dir ==DMA_BIDIRECTIONAL ) -swiotlb_bounce (orig_addr, tlb_addr, size,DMA_TO_DEVICE ); - +/* +* When dir == DMA_FROM_DEVICE we could omit the copy from the orig +* to the tlb buffer, if we knew for sure the device will +* overwirte the entire current content. But we don't. Thus +* unconditional bounce may prevent leaking swiotlb content (i.e. +* kernel memory) to user-space. +*/ +swiotlb_bounce (orig_addr, tlb_addr, size,DMA_TO_DEVICE );return tlb_addr; }EXPORT_SYMBOL_GPL (swiotlb_tbl_map_single);
Greg Kroah-Hartman
maintainerPATCH 256/264 fuse: fix pipe buffer lifetime for direct_io
In reply to Greg Kroah-HartmanFrom: Miklos Szeredi <[email protected]>
commit 0c4bcfdecb1ac0967619ee7ff44871d93c08c909 upstream.
In FOPEN_DIRECT_IO mode, fuse_file_write_iter() calls fuse_direct_write_iter(), which normally calls fuse_direct_io(), which then imports the write buffer with fuse_get_user_pages(), which uses iov_iter_get_pages() to grab references to userspace pages instead of actually copying memory.
On the filesystem device side, these pages can then either be read to userspace (via fuse_dev_read()), or splice()d over into a pipe using fuse_dev_splice_read() as pipe buffers with &nosteal_pipe_buf_ops.
This is wrong because after fuse_dev_do_read() unlocks the FUSE request, the userspace filesystem can mark the request as completed, causing write() to return. At that point, the userspace filesystem should no longer have access to the pipe buffer.
Fix by copying pages coming from the user address space to new pipe buffers.
--- fs/fuse/dev.c | 12 +++++++++++- fs/fuse/file.c | 1 + fs/fuse/fuse_i.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-)
fs/fuse/dev.c +11 -1
@@ -992,7 +992,17 @@ static int fuse_copy_page(struct fuse_cowhile (count) {if (cs->write && cs->pipebufs && page) { -return fuse_ref_page (cs, page, offset, count); +/* +* Can't control lifetime of pipe buffers, so always +* copy user pages. +*/ +if (cs->req->user_pages) { + err =fuse_copy_fill (cs); +if (err) +return err; + }else { +return fuse_ref_page (cs, page, offset, count); + } }else if (!cs->len) {if (cs->move_pages && page && offset ==0 && count ==PAGE_SIZE ) {
fs/fuse/file.c +1 -0
@@ -1319,6 +1319,7 @@ static int fuse_get_user_pages(struct fu (PAGE_SIZE - ret) & (PAGE_SIZE -1 ); } + req->user_pages = true;if (write) req->in.argpages =1 ;else
fs/fuse/fuse_i.h +2 -0
@@ -310,6 +310,8 @@ struct fuse_req {/** refcount */ atomic_t count; +bool user_pages; +/** Unique ID for the interrupt request */ u64 intr_unique;
Greg Kroah-Hartman
maintainerPATCH 257/264 tcp: change source port randomizarion at connect() time
In reply to Greg Kroah-HartmanFrom: Eric Dumazet <[email protected]>
commit 190cc82489f46f9d88e73c81a47e14f80a791e1a upstream.
RFC 6056 (Recommendations for Transport-Protocol Port Randomization) provides good summary of why source selection needs extra care.
David Dworken reminded us that linux implements Algorithm 3 as described in RFC 6056 3.3.3
Quoting David :
In the context of the web, this creates an interesting info leak where websites can count how many TCP connections a user's computer is establishing over time. For example, this allows a website to count exactly how many subresources a third party website loaded. This also allows:
- Distinguishing between different users behind a VPN based on distinct source port ranges.
- Tracking users over time across multiple networks.
- Covert communication channels between different browsers/browser profiles running on the same computer
- Tracking what applications are running on a computer based on the pattern of how fast source ports are getting incremented.
Section 3.3.4 describes an enhancement, that reduces attackers ability to use the basic information currently stored into the shared 'u32 hint'.
This change also decreases collision rate when
multiple applications need to connect() to
different destinations.
--- net/ipv4/inet_hashtables.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
net/ipv4/inet_hashtables.c +17 -3
@@ -537,6 +537,17 @@ void inet_unhash(struct sock *sk) }EXPORT_SYMBOL_GPL (inet_unhash); +/* RFC 6056 3.3.4. Algorithm 4: Double-Hash Port Selection Algorithm +* Note that we use 32bit integers (vs RFC 'short integers') +* because 2^16 is not a multiple of num_ephemeral and this +* property might be used by clever attacker. +* RFC claims using TABLE_LENGTH=10 buckets gives an improvement, +* we use 256 instead to really give more isolation and +* privacy, this only consumes 1 KB of kernel memory. +*/ +#define INET_TABLE_PERTURB_SHIFT 8 +static u32 table_perturb[1 <<INET_TABLE_PERTURB_SHIFT ]; + int __inet_hash_connect(struct inet_timewait_death_row *death_row, struct sock *sk, u32 port_offset, int (*check_established)(struct inet_timewait_death_row *,
@@ -550,7 +561,7 @@ int __inet_hash_connect(struct inet_timestruct inet_bind_bucket *tb;u32 remaining, offset;int ret, i, low, high; -static u32 hint; +u32 index;if (port) { head = &hinfo->bhash[inet_bhashfn(net, port,
@@ -575,7 +586,10 @@ int __inet_hash_connect(struct inet_timeif (likely (remaining >1 )) remaining &= ~1U ; - offset = (hint + port_offset) % remaining; +net_get_random_once (table_perturb,sizeof (table_perturb)); + index =hash_32 (port_offset,INET_TABLE_PERTURB_SHIFT ); + + offset = (READ_ONCE (table_perturb[index]) + port_offset) % remaining;/* In first pass we try ports of @low parity. * inet_csk_get_port() does the opposite choice. */
@@ -628,7 +642,7 @@ next_port:return -EADDRNOTAVAIL ; ok: - hint += i +2 ; +WRITE_ONCE (table_perturb[index],READ_ONCE (table_perturb[index]) + i +2 );/* Head lock still held and bh's disabled */ inet_bind_hash (sk, tb, port);
Greg Kroah-Hartman
maintainerPATCH 258/264 tcp: add some entropy in __inet_hash_connect()
In reply to Greg Kroah-HartmanFrom: Eric Dumazet <[email protected]>
commit c579bd1b4021c42ae247108f1e6f73dd3f08600c upstream.
Even when implementing RFC 6056 3.3.4 (Algorithm 4: Double-Hash Port Selection Algorithm), a patient attacker could still be able to collect enough state from an otherwise idle host.
Idea of this patch is to inject some noise, in the cases __inet_hash_connect() found a candidate in the first attempt.
This noise should not significantly reduce the collision avoidance, and should be zero if connection table is already well used.
Note that this is not implementing RFC 6056 3.3.5
because we think Algorithm 5 could hurt typical
workloads.
--- net/ipv4/inet_hashtables.c | 5 +++++ 1 file changed, 5 insertions(+)
net/ipv4/inet_hashtables.c +5 -0
@@ -642,6 +642,11 @@ next_port:return -EADDRNOTAVAIL ; ok: +/* If our first attempt found a candidate, skip next candidate +* in 1/16 of cases to add some noise. +*/ +if (!i && !(prandom_u32 () %16 )) + i =2 ;WRITE_ONCE (table_perturb[index],READ_ONCE (table_perturb[index]) + i +2 );/* Head lock still held and bh's disabled */
Greg Kroah-Hartman
maintainerPATCH 259/264 secure_seq: use the 64 bits of the siphash for port offset calculation
In reply to Greg Kroah-HartmanFrom: Willy Tarreau <[email protected]>
commit b2d057560b8107c633b39aabe517ff9d93f285e3 upstream.
SipHash replaced MD5 in secure_ipv{4,6}_port_ephemeral() via commit 7cd23e5300c1 ("secure_seq: use SipHash in place of MD5"), but the output remained truncated to 32-bit only. In order to exploit more bits from the hash, let's make the functions return the full 64-bit of siphash_3u32(). We also make sure the port offset calculation in __inet_hash_connect() remains done on 32-bit to avoid the need for div_u64_rem() and an extra cost on 32-bit systems.
--- include/net/inet_hashtables.h | 2 +- include/net/secure_seq.h | 4 ++-- net/core/secure_seq.c | 4 ++-- net/ipv4/inet_hashtables.c | 10 ++++++---- net/ipv6/inet6_hashtables.c | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-)
include/net/inet_hashtables.h +1 -1
@@ -382,7 +382,7 @@ static inline void sk_rcv_saddr_set(stru }int __inet_hash_connect (struct inet_timewait_death_row *death_row, -struct sock *sk,u32 port_offset, +struct sock *sk,u64 port_offset,int (*check_established)(struct inet_timewait_death_row *,struct sock *,__u16 ,struct inet_timewait_sock **));
include/net/secure_seq.h +2 -2
@@ -3,8 +3,8 @@#include <linux/types.h> -u32 secure_ipv4_port_ephemeral (__be32 saddr,__be32 daddr,__be16 dport); -u32 secure_ipv6_port_ephemeral (const __be32 *saddr,const __be32 *daddr, +u64 secure_ipv4_port_ephemeral (__be32 saddr,__be32 daddr,__be16 dport); +u64 secure_ipv6_port_ephemeral (const __be32 *saddr,const __be32 *daddr,__be16 dport);__u32 secure_tcp_sequence_number (__be32 saddr,__be32 daddr,__be16 sport,__be16 dport);
net/core/secure_seq.c +2 -2
@@ -62,7 +62,7 @@ __u32 secure_tcpv6_sequence_number(const }EXPORT_SYMBOL (secure_tcpv6_sequence_number); -u32 secure_ipv6_port_ephemeral (const __be32 *saddr,const __be32 *daddr, +u64 secure_ipv6_port_ephemeral (const __be32 *saddr,const __be32 *daddr,__be16 dport) {u32 secret[MD5_MESSAGE_BYTES /4 ];
@@ -102,7 +102,7 @@ __u32 secure_tcp_sequence_number(__be32return seq_scale (hash[0 ]); } -u32 secure_ipv4_port_ephemeral (__be32 saddr,__be32 daddr,__be16 dport) +u64 secure_ipv4_port_ephemeral (__be32 saddr,__be32 daddr,__be16 dport) {u32 hash[MD5_DIGEST_WORDS ];
net/ipv4/inet_hashtables.c +6 -4
@@ -382,7 +382,7 @@ not_unique:return -EADDRNOTAVAIL ; } -static u32 inet_sk_port_offset (const struct sock *sk) +static u64 inet_sk_port_offset (const struct sock *sk) {const struct inet_sock *inet =inet_sk (sk);
@@ -549,7 +549,7 @@ EXPORT_SYMBOL_GPL(inet_unhash);static u32 table_perturb[1 <<INET_TABLE_PERTURB_SHIFT ];int __inet_hash_connect (struct inet_timewait_death_row *death_row, -struct sock *sk,u32 port_offset, +struct sock *sk,u64 port_offset,int (*check_established)(struct inet_timewait_death_row *,struct sock *,__u16 ,struct inet_timewait_sock **)) {
@@ -589,7 +589,9 @@ int __inet_hash_connect(struct inet_timenet_get_random_once (table_perturb,sizeof (table_perturb)); index =hash_32 (port_offset,INET_TABLE_PERTURB_SHIFT ); - offset = (READ_ONCE (table_perturb[index]) + port_offset) % remaining; + offset =READ_ONCE (table_perturb[index]) + port_offset; + offset %= remaining; +/* In first pass we try ports of @low parity. * inet_csk_get_port() does the opposite choice. */
@@ -670,7 +672,7 @@ ok:int inet_hash_connect (struct inet_timewait_death_row *death_row,struct sock *sk) { -u32 port_offset =0 ; +u64 port_offset =0 ;if (!inet_sk (sk)->inet_num) port_offset =inet_sk_port_offset (sk);
net/ipv6/inet6_hashtables.c +2 -2
@@ -242,7 +242,7 @@ not_unique:return -EADDRNOTAVAIL ; } -static u32 inet6_sk_port_offset (const struct sock *sk) +static u64 inet6_sk_port_offset (const struct sock *sk) {const struct inet_sock *inet =inet_sk (sk);
@@ -254,7 +254,7 @@ static u32 inet6_sk_port_offset(const stint inet6_hash_connect (struct inet_timewait_death_row *death_row,struct sock *sk) { -u32 port_offset =0 ; +u64 port_offset =0 ;if (!inet_sk (sk)->inet_num) port_offset =inet6_sk_port_offset (sk);
Greg Kroah-Hartman
maintainerPATCH 260/264 tcp: use different parts of the port_offset for index and offset
In reply to Greg Kroah-HartmanFrom: Willy Tarreau <[email protected]>
commit 9e9b70ae923baf2b5e8a0ea4fd0c8451801ac526 upstream.
Amit Klein suggests that we use different parts of port_offset for the table's index and the port offset so that there is no direct relation between them.
--- net/ipv4/inet_hashtables.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_hashtables.c +1 -1
@@ -589,7 +589,7 @@ int __inet_hash_connect(struct inet_timenet_get_random_once (table_perturb,sizeof (table_perturb)); index =hash_32 (port_offset,INET_TABLE_PERTURB_SHIFT ); - offset =READ_ONCE (table_perturb[index]) + port_offset; + offset =READ_ONCE (table_perturb[index]) + (port_offset >>32 ); offset %= remaining;/* In first pass we try ports of @low parity.
Greg Kroah-Hartman
maintainerPATCH 261/264 tcp: add small random increments to the source port
In reply to Greg Kroah-HartmanFrom: Willy Tarreau <[email protected]>
commit ca7af0402550f9a0b3316d5f1c30904e42ed257d upstream.
Here we're randomly adding between 0 and 7 random increments to the selected source port in order to add some noise in the source port selection that will make the next port less predictable.
With the default port range of 32768-60999 this means a worst case reuse scenario of 14116/8=1764 connections between two consecutive uses of the same port, with an average of 14116/4.5=3137. This code was stressed at more than 800000 connections per second to a fixed target with all connections closed by the client using RSTs (worst condition) and only 2 connections failed among 13 billion, despite the hash being reseeded every 10 seconds, indicating a perfectly safe situation.
--- net/ipv4/inet_hashtables.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/ipv4/inet_hashtables.c +5 -4
@@ -644,11 +644,12 @@ next_port:return -EADDRNOTAVAIL ; ok: -/* If our first attempt found a candidate, skip next candidate -* in 1/16 of cases to add some noise. +/* Here we want to add a little bit of randomness to the next source +* port that will be chosen. We use a max() with a random here so that +* on low contention the randomness is maximal and on high contention +* it may be inexistent. */ -if (!i && !(prandom_u32 () %16 )) - i =2 ; + i =max_t (int, i, (prandom_u32 () &7 ) *2 );WRITE_ONCE (table_perturb[index],READ_ONCE (table_perturb[index]) + i +2 );/* Head lock still held and bh's disabled */
Greg Kroah-Hartman
maintainerPATCH 262/264 tcp: dynamically allocate the perturb table used by source ports
In reply to Greg Kroah-HartmanFrom: Willy Tarreau <[email protected]>
commit e9261476184be1abd486c9434164b2acbe0ed6c2 upstream.
We'll need to further increase the size of this table and it's likely that at some point its size will not be suitable anymore for a static table. Let's allocate it on boot from inet_hashinfo2_init(), which is called from tcp_init().
[bwh: Backported to 4.9:
- There is no inet_hashinfo2_init(), so allocate the table in inet_hashinfo_init() when called by TCP
- Adjust context]
--- net/ipv4/inet_hashtables.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
net/ipv4/inet_hashtables.c +13 -2
@@ -546,7 +546,8 @@ EXPORT_SYMBOL_GPL(inet_unhash);* privacy, this only consumes 1 KB of kernel memory. */ #define INET_TABLE_PERTURB_SHIFT 8 -static u32 table_perturb[1 <<INET_TABLE_PERTURB_SHIFT ]; +#define INET_TABLE_PERTURB_SIZE (1 << INET_TABLE_PERTURB_SHIFT) +static u32 *table_perturb; int __inet_hash_connect(struct inet_timewait_death_row *death_row, struct sock *sk, u64 port_offset,
@@ -586,7 +587,8 @@ int __inet_hash_connect(struct inet_timeif (likely (remaining >1 )) remaining &= ~1U ; -net_get_random_once (table_perturb,sizeof (table_perturb)); +net_get_random_once (table_perturb, +INET_TABLE_PERTURB_SIZE *sizeof (*table_perturb)); index =hash_32 (port_offset,INET_TABLE_PERTURB_SHIFT ); offset =READ_ONCE (table_perturb[index]) + (port_offset >>32 );
@@ -691,6 +693,15 @@ void inet_hashinfo_init(struct inet_hashINIT_HLIST_NULLS_HEAD (&h->listening_hash[i].nulls_head, i +LISTENING_NULLS_BASE ); } + +if (h != &tcp_hashinfo) +return ; + +/* this one is used for source ports of outgoing connections */ + table_perturb =kmalloc_array (INET_TABLE_PERTURB_SIZE , +sizeof (*table_perturb),GFP_KERNEL ); +if (!table_perturb) +panic ("TCP: failed to alloc table_perturb" ); }EXPORT_SYMBOL_GPL (inet_hashinfo_init);
Greg Kroah-Hartman
maintainerPATCH 263/264 tcp: increase source port perturb table to 2^16
In reply to Greg Kroah-HartmanFrom: Willy Tarreau <[email protected]>
commit 4c2c8f03a5ab7cb04ec64724d7d176d00bcc91e5 upstream.
Moshe Kol, Amit Klein, and Yossi Gilad reported being able to accurately identify a client by forcing it to emit only 40 times more connections than there are entries in the table_perturb[] table. The previous two improvements consisting in resalting the secret every 10s and adding randomness to each port selection only slightly improved the situation, and the current value of 2^8 was too small as it's not very difficult to make a client emit 10k connections in less than 10 seconds.
Thus we're increasing the perturb table from 2^8 to 2^16 so that the same precision now requires 2.6M connections, which is more difficult in this time frame and harder to hide as a background activity. The impact is that the table now uses 256 kB instead of 1 kB, which could mostly affect devices making frequent outgoing connections. However such components usually target a small set of destinations (load balancers, database clients, perf assessment tools), and in practice only a few entries will be visited, like before.
A live test at 1 million connections per second showed no performance difference from the previous value.
--- net/ipv4/inet_hashtables.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/ipv4/inet_hashtables.c +5 -4
@@ -541,11 +541,12 @@ EXPORT_SYMBOL_GPL(inet_unhash);* Note that we use 32bit integers (vs RFC 'short integers') * because 2^16 is not a multiple of num_ephemeral and this * property might be used by clever attacker. -* RFC claims using TABLE_LENGTH=10 buckets gives an improvement, -* we use 256 instead to really give more isolation and -* privacy, this only consumes 1 KB of kernel memory. +* RFC claims using TABLE_LENGTH=10 buckets gives an improvement, though +* attacks were since demonstrated, thus we use 65536 instead to really +* give more isolation and privacy, at the expense of 256kB of kernel +* memory. */ -#define INET_TABLE_PERTURB_SHIFT 8 +#define INET_TABLE_PERTURB_SHIFT 16#define INET_TABLE_PERTURB_SIZE (1 << INET_TABLE_PERTURB_SHIFT)static u32 *table_perturb;
Greg Kroah-Hartman
maintainerPATCH 264/264 tcp: drop the hash_32() part from the index calculation
In reply to Greg Kroah-HartmanFrom: Willy Tarreau <[email protected]>
commit e8161345ddbb66e449abde10d2fdce93f867eba9 upstream.
In commit 190cc82489f4 ("tcp: change source port randomizarion at connect() time"), the table_perturb[] array was introduced and an index was taken from the port_offset via hash_32(). But it turns out that hash_32() performs a multiplication while the input here comes from the output of SipHash in secure_seq, that is well distributed enough to avoid the need for yet another hash.
--- net/ipv4/inet_hashtables.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_hashtables.c +1 -1
@@ -590,7 +590,7 @@ int __inet_hash_connect(struct inet_timenet_get_random_once (table_perturb,INET_TABLE_PERTURB_SIZE *sizeof (*table_perturb)); - index =hash_32 (port_offset,INET_TABLE_PERTURB_SHIFT ); + index = port_offset & (INET_TABLE_PERTURB_SIZE -1 ); offset =READ_ONCE (table_perturb[index]) + (port_offset >>32 ); offset %= remaining;
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.9.320 release. There are 264 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat, 25 Jun 2022 16:43:11 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.320-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-4.9.y
and the diffstat can be found below.thanks,
greg k-h
On ARCH_BRCMSTB using 32-bit and 64-bit ARM kernels:
Signature · 1 line
Florian
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 4.9.320 release. There are 264 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
CIP testing did not find any problems here:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/tree/linux-4.9.y
Best regards,
Pavel
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.9.320 release. There are 264 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat, 25 Jun 2022 16:43:11 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
https://www.kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.320-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-4.9.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.9.320 release. There are 264 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat, 25 Jun 2022 16:43:11 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.320-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-4.9.y
and the diffstat can be found below.thanks,
greg k-h
All tests passing for Tegra ...
Test results for stable-v4.9:
8 builds: 8 pass, 0 fail
16 boots: 16 pass, 0 fail
32 tests: 32 pass, 0 failLinux version: 4.9.320-rc1-g00d9858d20e4
Boards tested: tegra124-jetson-tk1, tegra20-ventana,
tegra210-p2371-2180, tegra30-cardhu-a04
Jon
Quoted 8 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.9.320 release. There are 264 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat, 25 Jun 2022 16:43:11 +0000. Anything received after that time might be too late.
Build results:
total: 164 pass: 164 fail: 0 Qemu test results: total: 397 pass: 397 fail: 0
Guenter
Quoted 10 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.9.320 release. There are 264 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat, 25 Jun 2022 16:43:11 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.320-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-4.9.y
and the diffstat can be found below.thanks,
greg k-h
Results from Linaro’s test farm.
No regressions on arm64, arm, x86_64, and i386.
## Build
* kernel: 4.9.320-rc1
* git: https://gitlab.com/Linaro/lkft/mirrors/stable/linux-stable-rc
* git branch: linux-4.9.y
* git commit: 00d9858d20e4c4b5988b85df09c79010e037e456
* git describe: v4.9.319-265-g00d9858d20e4
* test details:
https://qa-reports.linaro.org/lkft/linux-stable-rc-linux-4.9.y/build/v4.9.319-265-g00d9858d20e4
## Test Regressions (compared to v4.9.319-251-g5de156af25f6) No test regressions found.
## Metric Regressions (compared to v4.9.319-251-g5de156af25f6) No metric regressions found.
## Test Fixes (compared to v4.9.319-251-g5de156af25f6) No test fixes found.
## Metric Fixes (compared to v4.9.319-251-g5de156af25f6) No metric fixes found.
## Test result summary
total: 104551, pass: 91428, fail: 204, skip: 11519, xfail: 1400
## Build Summary
* arc: 10 total, 10 passed, 0 failed
* arm: 261 total, 255 passed, 6 failed
* arm64: 50 total, 39 passed, 11 failed
* i386: 27 total, 23 passed, 4 failed
* mips: 22 total, 22 passed, 0 failed
* parisc: 12 total, 0 passed, 12 failed
* powerpc: 36 total, 16 passed, 20 failed
* s390: 12 total, 9 passed, 3 failed
* sh: 24 total, 24 passed, 0 failed
* sparc: 12 total, 12 passed, 0 failed
* x86_64: 46 total, 44 passed, 2 failed
## Test suites summary
* fwts
* igt-gpu-tools
* kunit
* kvm-unit-tests
* libhugetlbfs
* log-parser-boot
* log-parser-test
* ltp-cap_bounds
* ltp-cap_bounds-tests
* ltp-commands
* ltp-commands-tests
* ltp-containers
* ltp-containers-tests
* ltp-controllers-tests
* ltp-cpuhotplug-tests
* ltp-crypto
* ltp-crypto-tests
* ltp-cve-tests
* ltp-dio-tests
* ltp-fcntl-locktests
* ltp-fcntl-locktests-tests
* ltp-filecaps
* ltp-filecaps-tests
* ltp-fs
* ltp-fs-tests
* ltp-fs_bind
* ltp-fs_bind-tests
* ltp-fs_perms_simple
* ltp-fs_perms_simple-tests
* ltp-fsx
* ltp-fsx-tests
* ltp-hugetlb
* ltp-hugetlb-tests
* ltp-io
* ltp-io-tests
* ltp-ipc
* ltp-ipc-tests
* ltp-math-tests
* ltp-mm-tests
* ltp-nptl
* ltp-nptl-tests
* ltp-open-posix-tests
* ltp-pty
* ltp-pty-tests
* ltp-sched
* ltp-sched-tests
* ltp-securebits
* ltp-securebits-tests
* ltp-smoke
* ltp-syscalls-tests
* ltp-tracing-tests
* network-basic-tests
* packetdrill
* rcutorture
* ssuite
* v4l2-compliance
* vdso
--
Linaro LKFT
https://lkft.linaro.org