[PATCH netifd] device: restore cleared flags on device down

2023-07-12 Thread erik . r . karlsson
From: Erik Karlsson 

In case flags have been cleared because settings failed to apply,
restore them when the device is brought down so that they will be
re-attempted the next time the device is brought up.

Signed-off-by: Erik Karlsson 
---
 device.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/device.c b/device.c
index 92c814c..720b504 100644
--- a/device.c
+++ b/device.c
@@ -159,6 +159,11 @@ static int set_device_state(struct device *dev, bool state)
} else {
system_if_down(dev);
system_if_apply_settings(dev, &dev->orig_settings, 
dev->orig_settings.flags);
+
+   /* Restore any settings present in UCI which may have
+* failed to apply so that they will be re-attempted
+* the next time the device is brought up */
+   dev->settings.flags |= dev->settings.valid_flags;
}
 
return 0;
@@ -505,6 +510,10 @@ device_init_settings(struct device *dev, struct blob_attr 
**tb)
s->duplex = blobmsg_get_bool(cur);
s->flags |= DEV_OPT_DUPLEX;
}
+
+   /* Remember the settings present in UCI */
+   s->valid_flags = s->flags;
+
device_set_extra_vlans(dev, tb[DEV_ATTR_VLAN]);
device_set_disabled(dev, disabled);
 }
-- 
2.25.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH] file: strengthen exec access control

2023-05-29 Thread erik . r . karlsson
From: Erik Karlsson 

Do not allow setting environment variables if there is a session as
there is no access control for environment variables and allowing
arbitrary data into the environment is unsafe. Do not leak arguments
through unchecked if the size of the buffer for access checking the
whole command line is exceeded. Adjust the maximum number of allowed
arguments so it matches the actual implementation.

Signed-off-by: Erik Karlsson 
---
 file.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/file.c b/file.c
index 07b4d3c..1e5b2f4 100644
--- a/file.c
+++ b/file.c
@@ -809,6 +809,9 @@ rpc_file_exec_run(const char *cmd, const struct blob_attr 
*sid,
 
struct rpc_file_exec_context *c;
 
+   if (sid && env)
+   return UBUS_STATUS_PERMISSION_DENIED;
+
cmd = rpc_file_exec_lookup(cmd);
 
if (!cmd)
@@ -824,7 +827,7 @@ rpc_file_exec_run(const char *cmd, const struct blob_attr 
*sid,
if (arg == NULL || strlen(executable) >= sizeof(cmdstr))
return UBUS_STATUS_PERMISSION_DENIED;
 
-   arglen = 0;
+   arglen = 2;
p = cmdstr + sprintf(cmdstr, "%s", executable);
 
blobmsg_for_each_attr(cur, arg, rem)
@@ -834,7 +837,7 @@ rpc_file_exec_run(const char *cmd, const struct blob_attr 
*sid,
 
if (arglen == 255 ||
p + blobmsg_data_len(cur) >= cmdstr + 
sizeof(cmdstr))
-   break;
+   return UBUS_STATUS_PERMISSION_DENIED;
 
p += sprintf(p, " %s", blobmsg_get_string(cur));
arglen++;
-- 
2.25.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH] ubusd: handle invoke on event object without data

2021-07-02 Thread erik . r . karlsson
From: Erik Karlsson 

When a built-in object is invoked with UBUS_ATTR_DATA absent, recv_msg
will be called with NULL as the msg argument and ubusd_forward_event
and ubusd_alloc_event_pattern need to handle this. Otherwise, a
truncated invoke of "send" or "register" on UBUS_SYSTEM_OBJECT_EVENT
that is missing UBUS_ATTR_DATA will cause ubusd to crash with SIGSEGV.

Signed-off-by: Erik Karlsson 
---
 ubusd_event.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/ubusd_event.c b/ubusd_event.c
index ef433f8..15932a9 100644
--- a/ubusd_event.c
+++ b/ubusd_event.c
@@ -63,6 +63,9 @@ static int ubusd_alloc_event_pattern(struct ubus_client *cl, 
struct blob_attr *m
bool partial = false;
int len;
 
+   if (!msg)
+   return UBUS_STATUS_INVALID_ARGUMENT;
+
blobmsg_parse(evr_policy, EVREG_LAST, attr, blob_data(msg), 
blob_len(msg));
if (!attr[EVREG_OBJECT] || !attr[EVREG_PATTERN])
return UBUS_STATUS_INVALID_ARGUMENT;
@@ -209,6 +212,9 @@ static int ubusd_forward_event(struct ubus_client *cl, 
struct blob_attr *msg)
struct blob_attr *attr[EVMSG_LAST];
const char *id;
 
+   if (!msg)
+   return UBUS_STATUS_INVALID_ARGUMENT;
+
blobmsg_parse(ev_policy, EVMSG_LAST, attr, blob_data(msg), 
blob_len(msg));
if (!attr[EVMSG_ID] || !attr[EVMSG_DATA])
return UBUS_STATUS_INVALID_ARGUMENT;
-- 
2.25.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel