summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-10-02 03:28:55 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-10-02 03:36:43 +0200
commit4ed95fafad06473da7b3275461dd439e2af7d191 (patch)
treeb3074f3c5a5bdd2659a8c1f86625247312c88a69 /src/network
parentfileio: make read_full_file_full() usable with size and READ_FULL_FILE_UNBASE64 (diff)
downloadsystemd-4ed95fafad06473da7b3275461dd439e2af7d191.tar.xz
systemd-4ed95fafad06473da7b3275461dd439e2af7d191.zip
network: set maximum length to be read by read_full_file_full()
Fixes #29264 and oss-fuzz#62556 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=62556).
Diffstat (limited to 'src/network')
-rw-r--r--src/network/netdev/macsec.c10
-rw-r--r--src/network/netdev/wireguard.c8
2 files changed, 13 insertions, 5 deletions
diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c
index 6d17d45059..98927b168d 100644
--- a/src/network/netdev/macsec.c
+++ b/src/network/netdev/macsec.c
@@ -959,15 +959,19 @@ static int macsec_read_key_file(NetDev *netdev, SecurityAssociation *sa) {
return 0;
r = read_full_file_full(
- AT_FDCWD, sa->key_file, UINT64_MAX, SIZE_MAX,
- READ_FULL_FILE_SECURE | READ_FULL_FILE_UNHEX | READ_FULL_FILE_WARN_WORLD_READABLE | READ_FULL_FILE_CONNECT_SOCKET,
+ AT_FDCWD, sa->key_file, UINT64_MAX, MACSEC_KEYID_LEN,
+ READ_FULL_FILE_SECURE |
+ READ_FULL_FILE_UNHEX |
+ READ_FULL_FILE_WARN_WORLD_READABLE |
+ READ_FULL_FILE_CONNECT_SOCKET |
+ READ_FULL_FILE_FAIL_WHEN_LARGER,
NULL, (char **) &key, &key_len);
if (r < 0)
return log_netdev_error_errno(netdev, r,
"Failed to read key from '%s', ignoring: %m",
sa->key_file);
- if (key_len != 16)
+ if (key_len != MACSEC_KEYID_LEN)
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
"Invalid key length (%zu bytes), ignoring: %m", key_len);
diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c
index c89577609d..4c7d837c41 100644
--- a/src/network/netdev/wireguard.c
+++ b/src/network/netdev/wireguard.c
@@ -1037,8 +1037,12 @@ static int wireguard_read_key_file(const char *filename, uint8_t dest[static WG_
assert(dest);
r = read_full_file_full(
- AT_FDCWD, filename, UINT64_MAX, SIZE_MAX,
- READ_FULL_FILE_SECURE | READ_FULL_FILE_UNBASE64 | READ_FULL_FILE_WARN_WORLD_READABLE | READ_FULL_FILE_CONNECT_SOCKET,
+ AT_FDCWD, filename, UINT64_MAX, WG_KEY_LEN,
+ READ_FULL_FILE_SECURE |
+ READ_FULL_FILE_UNBASE64 |
+ READ_FULL_FILE_WARN_WORLD_READABLE |
+ READ_FULL_FILE_CONNECT_SOCKET |
+ READ_FULL_FILE_FAIL_WHEN_LARGER,
NULL, &key, &key_len);
if (r < 0)
return r;