Skip to content

Commit f00ff0d

Browse files
xnoxkeszybz
authored andcommitted
network: reject bridge port priorities above kernel's max value. (systemd#5877)
Bridge port priority in the kernel can only be between 0 and 63. Therefore reject values above maximum. Fixes: systemd#5729
1 parent b7674ec commit f00ff0d

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

src/libsystemd-network/network-internal.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,45 @@ int config_parse_iaid(const char *unit,
349349
return 0;
350350
}
351351

352+
int config_parse_bridge_port_priority(
353+
const char *unit,
354+
const char *filename,
355+
unsigned line,
356+
const char *section,
357+
unsigned section_line,
358+
const char *lvalue,
359+
int ltype,
360+
const char *rvalue,
361+
void *data,
362+
void *userdata) {
363+
364+
uint16_t i;
365+
int r;
366+
367+
assert(filename);
368+
assert(lvalue);
369+
assert(rvalue);
370+
assert(data);
371+
372+
r = safe_atou16(rvalue, &i);
373+
if (r < 0) {
374+
log_syntax(unit, LOG_ERR, filename, line, r,
375+
"Failed to parse bridge port priority, ignoring: %s", rvalue);
376+
return 0;
377+
}
378+
379+
if (i > LINK_BRIDGE_PORT_PRIORITY_MAX) {
380+
log_syntax(unit, LOG_ERR, filename, line, r,
381+
"Bridge port priority is larger than maximum %u, ignoring: %s", LINK_BRIDGE_PORT_PRIORITY_MAX, rvalue);
382+
return 0;
383+
}
384+
385+
*((uint16_t *)data) = i;
386+
387+
return 0;
388+
}
389+
390+
352391
void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size) {
353392
unsigned i;
354393

src/libsystemd-network/network-internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#include "condition.h"
2727
#include "udev.h"
2828

29+
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
30+
#define LINK_BRIDGE_PORT_PRIORITY_MAX 63
31+
2932
bool net_match_config(const struct ether_addr *match_mac,
3033
char * const *match_path,
3134
char * const *match_driver,
@@ -62,6 +65,10 @@ int config_parse_iaid(const char *unit, const char *filename, unsigned line,
6265
const char *section, unsigned section_line, const char *lvalue,
6366
int ltype, const char *rvalue, void *data, void *userdata);
6467

68+
int config_parse_bridge_port_priority(const char *unit, const char *filename, unsigned line,
69+
const char *section, unsigned section_line, const char *lvalue,
70+
int ltype, const char *rvalue, void *data, void *userdata);
71+
6572
int net_get_unique_predictable_data(struct udev_device *device, uint64_t *result);
6673
const char *net_get_name(struct udev_device *device);
6774

src/network/networkd-link.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#include "list.h"
3434
#include "set.h"
3535

36-
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
37-
3836
typedef enum LinkState {
3937
LINK_STATE_PENDING,
4038
LINK_STATE_ENSLAVING,

src/network/networkd-network-gperf.gperf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Bridge.HairPin, config_parse_bool,
129129
Bridge.FastLeave, config_parse_bool, 0, offsetof(Network, fast_leave)
130130
Bridge.AllowPortToBeRoot, config_parse_bool, 0, offsetof(Network, allow_port_to_be_root)
131131
Bridge.UnicastFlood, config_parse_bool, 0, offsetof(Network, unicast_flood)
132-
Bridge.Priority, config_parse_uint16, 0, offsetof(Network, priority)
132+
Bridge.Priority, config_parse_bridge_port_priority, 0, offsetof(Network, priority)
133133
BridgeFDB.MACAddress, config_parse_fdb_hwaddr, 0, 0
134134
BridgeFDB.VLANId, config_parse_fdb_vlan_id, 0, 0
135135
BridgeVLAN.PVID, config_parse_brvlan_pvid, 0, 0

0 commit comments

Comments
 (0)