3.16.73-rc1 review
cover 3.16.73-rc1 review
This is the start of the stable review cycle for the 3.16.73 release. There are 4 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Mon Aug 19 20:00:00 UTC 2019. Anything received after that time might be too late.
All the patches have also been committed to the linux-3.16.y-rc branch of
https://git.kernel.org/pub/scm/linux/kernel/git/bwh/linux-stable-rc.git . A shortlog and diffstat can be found below.
Ben.
-------------
Ben Hutchings (1):
tcp: Clear sk_send_head after purging the write queue
[not upstream; fixes bug specific to stable]
Jason A. Donenfeld (1):
siphash: implement HalfSipHash1-3 for hash tables
[1ae2324f732c9c4e2fa4ebd885fa1001b70d52e1]
Zhangyi (2):
ext4: brelse all indirect buffer in ext4_ind_remove_space()
[674a2b27234d1b7afcb0a9162e81b2e53aeef217]
ext4: cleanup bh release code in ext4_ind_remove_space()
[5e86bdda41534e17621d5a071b294943cae4376e]
Documentation/siphash.txt | 75 +++++++++++ Makefile | 4 +- fs/ext4/indirect.c | 43 ++++--- include/linux/siphash.h | 57 +++++++- include/net/tcp.h | 3 + lib/siphash.c | 321 +++++++++++++++++++++++++++++++++++++++++++++- lib/test_siphash.c | 98 +++++++++++++- 7 files changed, 573 insertions(+), 28 deletions(-)
Signature · 4 lines
Ben Hutchings
The obvious mathematical breakthrough [to break modern encryption]
would be development of an easy way to factor large prime numbers.
- Bill GatesPATCH 1/4 tcp: Clear sk_send_head after purging the write queue
3.16.73-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ben Hutchings <[email protected]>
Denis Andzakovic discovered a potential use-after-free in older kernel versions, using syzkaller. tcp_write_queue_purge() frees all skbs in the TCP write queue and can leave sk->sk_send_head pointing to freed memory. tcp_disconnect() clears that pointer after calling tcp_write_queue_purge(), but tcp_connect() does not. It is (surprisingly) possible to add to the write queue between disconnection and reconnection, so this needs to be done in both places.
This bug was introduced by backports of commit 7f582b248d0a ("tcp:
purge write queue in tcp_connect_init()") and does not exist upstream because of earlier changes in commit 75c119afe14f ("tcp: implement rb-tree based retransmit queue"). The latter is a major change that's not suitable for stable.
--- include/net/tcp.h | 3 +++ 1 file changed, 3 insertions(+)
include/net/tcp.h +3 -0
@@ -1352,6 +1352,8 @@ struct tcp_fastopen_context {struct rcu_head rcu; }; +static inline void tcp_init_send_head (struct sock *sk); +/* write queue abstraction */ static inline void tcp_write_queue_purge (struct sock *sk) {
@@ -1359,6 +1361,7 @@ static inline void tcp_write_queue_purgewhile ((skb =__skb_dequeue (&sk->sk_write_queue)) !=NULL )sk_wmem_free_skb (sk, skb); +tcp_init_send_head (sk);sk_mem_reclaim (sk);tcp_clear_all_retrans_hints (tcp_sk (sk)); }
PATCH 2/4 ext4: brelse all indirect buffer in ext4_ind_remove_space()
In reply to Ben Hutchings3.16.73-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "zhangyi (F)" <[email protected]>
commit 674a2b27234d1b7afcb0a9162e81b2e53aeef217 upstream.
All indirect buffers get by ext4_find_shared() should be released no mater the branch should be freed or not. But now, we forget to release the lower depth indirect buffers when removing space from the same higher depth indirect block. It will lead to buffer leak and futher more, it may lead to quota information corruption when using old quota, consider the following case.
- Create and mount an empty ext4 filesystem without extent and quota features,
- quotacheck and enable the user & group quota,
- Create some files and write some data to them, and then punch hole to some files of them, it may trigger the buffer leak problem mentioned above.
- Disable quota and run quotacheck again, it will create two new aquota files and write the checked quota information to them, which probably may reuse the freed indirect block(the buffer and page cache was not freed) as data block.
- Enable quota again, it will invoke vfs_load_quota_inode()->invalidate_bdev() to try to clean unused buffers and pagecache. Unfortunately, because of the buffer of quota data block is still referenced, quota code cannot read the up to date quota info from the device and lead to quota information corruption.
This problem can be reproduced by xfstests generic/231 on ext3 file system or ext4 file system without extent and quota features.
This patch fix this problem by releasing the missing indirect buffers, in ext4_ind_remove_space().
--- fs/ext4/indirect.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/ext4/indirect.c +8 -4
@@ -1481,10 +1481,14 @@ end_range: partial->p +1 , partial2->p, (chain+n-1) - partial); -BUFFER_TRACE (partial->bh,"call brelse" ); -brelse (partial->bh); -BUFFER_TRACE (partial2->bh,"call brelse" ); -brelse (partial2->bh); +while (partial > chain) { +BUFFER_TRACE (partial->bh,"call brelse" ); +brelse (partial->bh); + } +while (partial2 > chain2) { +BUFFER_TRACE (partial2->bh,"call brelse" ); +brelse (partial2->bh); + }return 0 ; }
PATCH 3/4 ext4: cleanup bh release code in ext4_ind_remove_space()
In reply to Ben Hutchings3.16.73-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "zhangyi (F)" <[email protected]>
commit 5e86bdda41534e17621d5a071b294943cae4376e upstream.
Currently, we are releasing the indirect buffer where we are done with it in ext4_ind_remove_space(), so we can see the brelse() and BUFFER_TRACE() everywhere. It seems fragile and hard to read, and we may probably forget to release the buffer some day. This patch cleans up the code by putting of the code which releases the buffers to the end of the function.
--- fs/ext4/indirect.c | 47 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 25 deletions(-)
fs/ext4/indirect.c +22 -25
@@ -1313,6 +1313,7 @@ int ext4_ind_remove_space(handle_t *handext4_lblk_t offsets[4 ], offsets2[4 ];Indirect chain[4 ], chain2[4 ];Indirect *partial, *partial2; +Indirect *p =NULL , *p2 =NULL ;ext4_lblk_t max_block;__le32 nr =0 , nr2 =0 ;int n =0 , n2 =0 ;
@@ -1354,7 +1355,7 @@ int ext4_ind_remove_space(handle_t *hand } - partial =ext4_find_shared (inode, n, offsets, chain, &nr); + partial = p =ext4_find_shared (inode, n, offsets, chain, &nr);if (nr) {if (partial == chain) {/* Shared branch grows from the inode */
@@ -1379,13 +1380,11 @@ int ext4_ind_remove_space(handle_t *hand partial->p +1 , (__le32 *)partial->bh->b_data+addr_per_block, (chain+n-1) - partial); -BUFFER_TRACE (partial->bh,"call brelse" ); -brelse (partial->bh); partial--; } end_range: - partial2 =ext4_find_shared (inode, n2, offsets2, chain2, &nr2); + partial2 = p2 =ext4_find_shared (inode, n2, offsets2, chain2, &nr2);if (nr2) {if (partial2 == chain2) {/*
@@ -1415,16 +1414,14 @@ end_range: (__le32 *)partial2->bh->b_data, partial2->p, (chain2+n2-1) - partial2); -BUFFER_TRACE (partial2->bh,"call brelse" ); -brelse (partial2->bh); partial2--; } goto do_indirects; }/* Punch happened within the same level (n == n2) */ - partial =ext4_find_shared (inode, n, offsets, chain, &nr); - partial2 =ext4_find_shared (inode, n2, offsets2, chain2, &nr2); + partial = p =ext4_find_shared (inode, n, offsets, chain, &nr); + partial2 = p2 =ext4_find_shared (inode, n2, offsets2, chain2, &nr2);/* Free top, but only if partial2 isn't its subtree. */ if (nr) {
@@ -1481,15 +1478,7 @@ end_range: partial->p +1 , partial2->p, (chain+n-1) - partial); -while (partial > chain) { -BUFFER_TRACE (partial->bh,"call brelse" ); -brelse (partial->bh); - } -while (partial2 > chain2) { -BUFFER_TRACE (partial2->bh,"call brelse" ); -brelse (partial2->bh); - } -return 0 ; + goto cleanup; }/*
@@ -1504,8 +1493,6 @@ end_range: partial->p +1 , (__le32 *)partial->bh->b_data+addr_per_block, (chain+n-1) - partial); -BUFFER_TRACE (partial->bh,"call brelse" ); -brelse (partial->bh); partial--; }if (partial2 > chain2 && depth2 <= depth) {
@@ -1513,11 +1500,21 @@ end_range: (__le32 *)partial2->bh->b_data, partial2->p, (chain2+n2-1) - partial2); -BUFFER_TRACE (partial2->bh,"call brelse" ); -brelse (partial2->bh); partial2--; } } + +cleanup: +while (p && p > chain) { +BUFFER_TRACE (p->bh,"call brelse" ); +brelse (p->bh); + p--; + } +while (p2 && p2 > chain2) { +BUFFER_TRACE (p2->bh,"call brelse" ); +brelse (p2->bh); + p2--; + }return 0 ; do_indirects:
@@ -1525,7 +1522,7 @@ do_indirects:switch (offsets[0 ]) {default :if (++n >= n2) -return 0 ; +break ; nr = i_data[EXT4_IND_BLOCK ];if (nr) {ext4_free_branches (handle, inode,NULL , &nr, &nr+1 ,1 );
@@ -1533,7 +1530,7 @@ do_indirects: }case EXT4_IND_BLOCK :if (++n >= n2) -return 0 ; +break ; nr = i_data[EXT4_DIND_BLOCK ];if (nr) {ext4_free_branches (handle, inode,NULL , &nr, &nr+1 ,2 );
@@ -1541,7 +1538,7 @@ do_indirects: }case EXT4_DIND_BLOCK :if (++n >= n2) -return 0 ; +break ; nr = i_data[EXT4_TIND_BLOCK ];if (nr) {ext4_free_branches (handle, inode,NULL , &nr, &nr+1 ,3 );
@@ -1550,5 +1547,5 @@ do_indirects:case EXT4_TIND_BLOCK : ; } -return 0 ; + goto cleanup; }
PATCH 4/4 siphash: implement HalfSipHash1-3 for hash tables
In reply to Ben Hutchings3.16.73-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Jason A. Donenfeld" <[email protected]>
commit 1ae2324f732c9c4e2fa4ebd885fa1001b70d52e1 upstream.
HalfSipHash, or hsiphash, is a shortened version of SipHash, which generates 32-bit outputs using a weaker 64-bit key. It has *much* lower security margins, and shouldn't be used for anything too sensitive, but it could be used as a hashtable key function replacement, if the output is never exposed, and if the security requirement is not too high.
The goal is to make this something that performance-critical jhash users would be willing to use.
On 64-bit machines, HalfSipHash1-3 is slower than SipHash1-3, so we alias SipHash1-3 to HalfSipHash1-3 on those systems.
64-bit x86_64:
[ 0.509409] test_siphash: SipHash2-4 cycles: 4049181 [ 0.510650] test_siphash: SipHash1-3 cycles: 2512884 [ 0.512205] test_siphash: HalfSipHash1-3 cycles: 3429920 [ 0.512904] test_siphash: JenkinsHash cycles: 978267
So, we map hsiphash() -> SipHash1-3
32-bit x86:
[ 0.509868] test_siphash: SipHash2-4 cycles: 14812892 [ 0.513601] test_siphash: SipHash1-3 cycles: 9510710 [ 0.515263] test_siphash: HalfSipHash1-3 cycles: 3856157 [ 0.515952] test_siphash: JenkinsHash cycles: 1148567
So, we map hsiphash() -> HalfSipHash1-3
hsiphash() is roughly 3 times slower than jhash(), but comes with a considerable security improvement.
[bwh: Backported to 3.16 to avoid a build regression for WireGuard with
only part of the siphash API available]
--- Documentation/siphash.txt | 75 +++++++++ include/linux/siphash.h | 57 ++++++- lib/siphash.c | 321 +++++++++++++++++++++++++++++++++++++- lib/test_siphash.c | 98 +++++++++++- 4 files changed, 546 insertions(+), 5 deletions(-)
Documentation/siphash.txt +75 -0
@@ -98,3 +98,78 @@ u64 h = siphash(&combined, offsetofend(t Read the SipHash paper if you're interested in learning more: https://131002.net/siphash/siphash.pdf + + +~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ + +HalfSipHash - SipHash's insecure younger cousin +----------------------------------------------- +Written by Jason A. Donenfeld <[email protected]> + +On the off-chance that SipHash is not fast enough for your needs, you might be +able to justify using HalfSipHash, a terrifying but potentially useful +possibility. HalfSipHash cuts SipHash's rounds down from "2-4" to "1-3" and, +even scarier, uses an easily brute-forcable 64-bit key (with a 32-bit output) +instead of SipHash's 128-bit key. However, this may appeal to some +high-performance `jhash` users. + +Danger! + +Do not ever use HalfSipHash except for as a hashtable key function, and only +then when you can be absolutely certain that the outputs will never be +transmitted out of the kernel. This is only remotely useful over `jhash` as a +means of mitigating hashtable flooding denial of service attacks. + +1. Generating a key + +Keys should always be generated from a cryptographically secure source of +random numbers, either using get_random_bytes or get_random_once: + +hsiphash_key_t key; +get_random_bytes(&key, sizeof(key)); + +If you're not deriving your key from here, you're doing it wrong. + +2. Using the functions + +There are two variants of the function, one that takes a list of integers, and +one that takes a buffer: + +u32 hsiphash(const void *data, size_t len, const hsiphash_key_t *key); + +And: + +u32 hsiphash_1u32(u32, const hsiphash_key_t *key); +u32 hsiphash_2u32(u32, u32, const hsiphash_key_t *key); +u32 hsiphash_3u32(u32, u32, u32, const hsiphash_key_t *key); +u32 hsiphash_4u32(u32, u32, u32, u32, const hsiphash_key_t *key); + +If you pass the generic hsiphash function something of a constant length, it +will constant fold at compile-time and automatically choose one of the +optimized functions. + +3. Hashtable key function usage: + +struct some_hashtable { + DECLARE_HASHTABLE(hashtable, 8); + hsiphash_key_t key; +}; + +void init_hashtable(struct some_hashtable *table) +{ + get_random_bytes(&table->key, sizeof(table->key)); +} + +static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input) +{ + return &table->hashtable[hsiphash(input, sizeof(*input), &table->key) & (HASH_SIZE(table->hashtable) - 1)]; +} + +You may then iterate like usual over the returned hash bucket. + +4. Performance + +HalfSipHash is roughly 3 times slower than JenkinsHash. For many replacements, +this will not be a problem, as the hashtable lookup isn't the bottleneck. And +in general, this is probably a good sacrifice to make for the security and DoS +resistance of HalfSipHash.
include/linux/siphash.h +56 -1
67 lines not on this page · raw message
lib/siphash.c +320 -1
330 lines not on this page · raw message
lib/test_siphash.c +95 -3
128 lines not on this page · raw message
Quoted 8 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.73 release. There are 4 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Mon Aug 19 20:00:00 UTC 2019. Anything received after that time might be too late.
Build results:
total: 136 pass: 136 fail: 0 Qemu test results: total: 229 pass: 229 fail: 0
Guenter
Quoted 6 lines · Guenter Roeck
Quoted 5 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.73 release. There are 4 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Quoted 7 lines
Quoted 3 lines
Responses should be made by Mon Aug 19 20:00:00 UTC 2019. Anything received after that time might be too late.
Build results:
total: 136 pass: 136 fail: 0 Qemu test results: total: 229 pass: 229 fail: 0
Thanks for testing,
Ben.
Signature · 2 lines
Ben Hutchings Larkinson's Law: All laws are basically false.