Skip to content

Commit aeac4ec

Browse files
glebmdavem330
authored andcommitted
tcp: configurable source port perturb table size
On embedded systems with little memory and no relevant security concerns, it is beneficial to reduce the size of the table. Reducing the size from 2^16 to 2^8 saves 255 KiB of kernel RAM. Makes the table size configurable as an expert option. The size was previously increased from 2^8 to 2^16 in commit 4c2c8f0 ("tcp: increase source port perturb table to 2^16"). Signed-off-by: Gleb Mazovetskiy <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b68777d commit aeac4ec

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

net/ipv4/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,16 @@ config INET_IPCOMP
402402

403403
If unsure, say Y.
404404

405+
config INET_TABLE_PERTURB_ORDER
406+
int "INET: Source port perturbation table size (as power of 2)" if EXPERT
407+
default 16
408+
help
409+
Source port perturbation table size (as power of 2) for
410+
RFC 6056 3.3.4. Algorithm 4: Double-Hash Port Selection Algorithm.
411+
412+
The default is almost always what you want.
413+
Only change this if you know what you are doing.
414+
405415
config INET_XFRM_TUNNEL
406416
tristate
407417
select INET_TUNNEL

net/ipv4/inet_hashtables.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -906,13 +906,13 @@ EXPORT_SYMBOL_GPL(inet_bhash2_update_saddr);
906906
* Note that we use 32bit integers (vs RFC 'short integers')
907907
* because 2^16 is not a multiple of num_ephemeral and this
908908
* property might be used by clever attacker.
909+
*
909910
* RFC claims using TABLE_LENGTH=10 buckets gives an improvement, though
910-
* attacks were since demonstrated, thus we use 65536 instead to really
911-
* give more isolation and privacy, at the expense of 256kB of kernel
912-
* memory.
911+
* attacks were since demonstrated, thus we use 65536 by default instead
912+
* to really give more isolation and privacy, at the expense of 256kB
913+
* of kernel memory.
913914
*/
914-
#define INET_TABLE_PERTURB_SHIFT 16
915-
#define INET_TABLE_PERTURB_SIZE (1 << INET_TABLE_PERTURB_SHIFT)
915+
#define INET_TABLE_PERTURB_SIZE (1 << CONFIG_INET_TABLE_PERTURB_ORDER)
916916
static u32 *table_perturb;
917917

918918
int __inet_hash_connect(struct inet_timewait_death_row *death_row,

0 commit comments

Comments
 (0)