Merge pull request #12965 from keszybz/auto-erase
_cleanup_(erase_and_freep)
This commit is contained in:
+13
-16
@@ -718,7 +718,7 @@ int config_parse_macsec_key(
|
||||
|
||||
_cleanup_(macsec_transmit_association_free_or_set_invalidp) TransmitAssociation *a = NULL;
|
||||
_cleanup_(macsec_receive_association_free_or_set_invalidp) ReceiveAssociation *b = NULL;
|
||||
_cleanup_free_ void *p;
|
||||
_cleanup_(erase_and_freep) void *p = NULL;
|
||||
MACsec *s = userdata;
|
||||
SecurityAssociation *dest;
|
||||
size_t l;
|
||||
@@ -743,18 +743,17 @@ int config_parse_macsec_key(
|
||||
|
||||
r = unhexmem_full(rvalue, strlen(rvalue), true, &p, &l);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r,
|
||||
"Failed to parse key. Ignoring assignment: %m");
|
||||
return 0;
|
||||
}
|
||||
if (l != 16) {
|
||||
/* See DEFAULT_SAK_LEN in drivers/net/macsec.c */
|
||||
explicit_bzero_safe(p, l);
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0,
|
||||
"Invalid key length (%zu). Ignoring assignment", l);
|
||||
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse key. Ignoring assignment: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (l != 16) {
|
||||
/* See DEFAULT_SAK_LEN in drivers/net/macsec.c */
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid key length (%zu). Ignoring assignment", l);
|
||||
return 0;
|
||||
}
|
||||
|
||||
explicit_bzero_safe(dest->key, dest->key_len);
|
||||
free_and_replace(dest->key, p);
|
||||
dest->key_len = l;
|
||||
|
||||
@@ -972,7 +971,7 @@ int config_parse_macsec_use_for_encoding(
|
||||
}
|
||||
|
||||
static int macsec_read_key_file(NetDev *netdev, SecurityAssociation *sa) {
|
||||
_cleanup_free_ uint8_t *key = NULL;
|
||||
_cleanup_(erase_and_freep) uint8_t *key = NULL;
|
||||
size_t key_len;
|
||||
int r;
|
||||
|
||||
@@ -987,12 +986,10 @@ static int macsec_read_key_file(NetDev *netdev, SecurityAssociation *sa) {
|
||||
return log_netdev_error_errno(netdev, r,
|
||||
"Failed to read key from '%s', ignoring: %m",
|
||||
sa->key_file);
|
||||
if (key_len != 16) {
|
||||
explicit_bzero_safe(key, key_len);
|
||||
|
||||
if (key_len != 16)
|
||||
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
|
||||
"Invalid key length (%zu bytes), ignoring: %m",
|
||||
key_len);
|
||||
}
|
||||
"Invalid key length (%zu bytes), ignoring: %m", key_len);
|
||||
|
||||
explicit_bzero_safe(sa->key, sa->key_len);
|
||||
free_and_replace(sa->key, key);
|
||||
|
||||
@@ -480,7 +480,7 @@ static int wireguard_decode_key_and_warn(
|
||||
unsigned line,
|
||||
const char *lvalue) {
|
||||
|
||||
_cleanup_free_ void *key = NULL;
|
||||
_cleanup_(erase_and_freep) void *key = NULL;
|
||||
size_t len;
|
||||
int r;
|
||||
|
||||
@@ -501,12 +501,10 @@ static int wireguard_decode_key_and_warn(
|
||||
if (r < 0)
|
||||
return log_syntax(unit, LOG_ERR, filename, line, r,
|
||||
"Failed to decode wireguard key provided by %s=, ignoring assignment: %m", lvalue);
|
||||
if (len != WG_KEY_LEN) {
|
||||
explicit_bzero_safe(key, len);
|
||||
if (len != WG_KEY_LEN)
|
||||
return log_syntax(unit, LOG_ERR, filename, line, 0,
|
||||
"Wireguard key provided by %s= has invalid length (%zu bytes), ignoring assignment.",
|
||||
lvalue, len);
|
||||
}
|
||||
|
||||
memcpy(ret, key, WG_KEY_LEN);
|
||||
return 0;
|
||||
@@ -894,7 +892,7 @@ static void wireguard_done(NetDev *netdev) {
|
||||
}
|
||||
|
||||
static int wireguard_read_key_file(const char *filename, uint8_t dest[static WG_KEY_LEN]) {
|
||||
_cleanup_free_ char *key = NULL;
|
||||
_cleanup_(erase_and_freep) char *key = NULL;
|
||||
size_t key_len;
|
||||
int r;
|
||||
|
||||
@@ -905,17 +903,11 @@ static int wireguard_read_key_file(const char *filename, uint8_t dest[static WG_
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (key_len != WG_KEY_LEN) {
|
||||
r = -EINVAL;
|
||||
goto finalize;
|
||||
}
|
||||
if (key_len != WG_KEY_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
memcpy(dest, key, WG_KEY_LEN);
|
||||
r = 0;
|
||||
|
||||
finalize:
|
||||
explicit_bzero_safe(key, key_len);
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wireguard_peer_verify(WireguardPeer *peer) {
|
||||
|
||||
Reference in New Issue
Block a user