FS#4118 - "logread" crashes sometimes #9100

2022-08-16 Thread Bastian Bittorf
I just want to mention a longstanding segfault-issue,  
which one can now reproduce with an x86-snapshot-image.  

Maybe somebody has time to look into this core building block:
https://github.com/openwrt/openwrt/issues/9100

thanks && bye,
bastian

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


firmware-imx-8.15.bin blob redistribution [Was: Re: [PATCH] imx: add imx8mplus platform support]

2022-08-16 Thread Petr Štetiar
Piotr Dymacz  [2022-08-16 13:16:23]:

Hi,

> > +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).bin
> > +PKG_SOURCE_URL:=https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/
> > +PKG_HASH:=ef91390da6c8a6a48c8121a5dd667de8
> 
> OK, so a 'firmware-imx-8.15.bin' file, hosted somewhere on NXP servers which
> seems to be a self-extracting package with bunch of proprietary binary blobs
> and almost 700 lines license. And it asks for EULA acceptance when
> extracting:
> 
> "Welcome to NXP firmware-imx-8.15.bin
> 
> You need to read and accept the EULA before you can continue.
> 
> LA_OPT_NXP_Software_License v34 February 2022
> [...]
> "
> I don't think we can accept this (Rafał, Petr, any opinions?).

I second your conclusion. BTW IANAL, but following part in EULA possibly
forbids redistribution in binary form:

 "If you are not expressly granted the distribution license in Section 2.3"

Cheers,

Petr

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


Re: Setting Linux Capabilities

2022-08-16 Thread Etienne Champetier
Hi Ravi,

Le mar. 16 août 2022 à 07:52, Ravi Paluri (QUIC)
 a écrit :
>
> Hi Team,
> We would like to set below capabilities for our process.
> * CAP_NET_ADMIN
> * CAP_NET_RAW
>
> Do we need to use APIs mentioned in https://linux.die.net/man/3/cap_set_flag 
> and https://linux.die.net/man/3/cap_set_proc to get this functionality?
>
> On Systemd, I see that this can be achieved by writing below lines in a 
> service file.
> CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW
> AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW
>
> So, would like to know if there is any thing similar that can be done in 
> procd init scripts?

OpenWrt has procd-ujail, to set capabilities with it:
https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/files/sysntpd#L80
https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/files/ntpd.capabilities

Best
Etienne

> Thanks,
> Ravi

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


[PATCH uci] delta: simplify uci_load_delta() by using a helper

2022-08-16 Thread Rafał Miłecki
From: Rafał Miłecki 

In the commit 3c7f3556b0039 ("Fix delta path handling.")
uci_load_delta() was modified by open coding uci_load_delta_file(). It
seems that reason behind it was to avoid uci_parse_delta(). The same can
be achieved by passing NULL as "struct uci_package *p" argument.

Cc: Yousong Zhou 
Signed-off-by: Rafał Miłecki 
---
 delta.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/delta.c b/delta.c
index d8bd3a6..85ec970 100644
--- a/delta.c
+++ b/delta.c
@@ -293,7 +293,7 @@ error:
 }
 
 /* returns the number of changes that were successfully parsed */
-static int uci_load_delta_file(struct uci_context *ctx, struct uci_package *p, 
char *filename, FILE **f, bool flush)
+static int uci_load_delta_file(struct uci_context *ctx, struct uci_package *p, 
char *filename, FILE *volatile *f, bool flush)
 {
FILE *volatile stream = NULL;
volatile int changes = 0;
@@ -334,9 +334,7 @@ __private int uci_load_delta(struct uci_context *ctx, 
struct uci_package *p, boo
 
if ((asprintf(, "%s/%s", ctx->savedir, p->e.name) < 0) || 
!filename)
UCI_THROW(ctx, UCI_ERR_MEM);
-   UCI_TRAP_SAVE(ctx, done);
-   f = uci_open_stream(ctx, filename, NULL, SEEK_SET, flush, false);
-   UCI_TRAP_RESTORE(ctx);
+   uci_load_delta_file(ctx, NULL, filename, , flush);
 
if (flush && f && (changes > 0)) {
if (ftruncate(fileno(f), 0) < 0) {
@@ -346,7 +344,6 @@ __private int uci_load_delta(struct uci_context *ctx, 
struct uci_package *p, boo
}
}
 
-done:
free(filename);
uci_close_stream(f);
ctx->err = 0;
-- 
2.34.1


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


Setting Linux Capabilities

2022-08-16 Thread Ravi Paluri (QUIC)
Hi Team,
We would like to set below capabilities for our process.
* CAP_NET_ADMIN 
* CAP_NET_RAW

Do we need to use APIs mentioned in https://linux.die.net/man/3/cap_set_flag 
and https://linux.die.net/man/3/cap_set_proc to get this functionality?

On Systemd, I see that this can be achieved by writing below lines in a service 
file.
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW

So, would like to know if there is any thing similar that can be done in procd 
init scripts?

Thanks,
Ravi


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


[PATCH 9/9] uci: macro uci_alloc_element not in uci.h

2022-08-16 Thread Jan Venekamp
The macro uci_alloc_element is in the public header file uci.h. However,
the macros output refers to uci_alloc_generic wich is in uci_internal.h
and not public. Thus, uci_alloc_element should be private as well and
moved to uci_internal.h.

Signed-off-by: Jan Venekamp 
---
 uci.h  | 10 --
 uci_internal.h |  3 +++
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/uci.h b/uci.h
index b385e2b..d0374f2 100644
--- a/uci.h
+++ b/uci.h
@@ -613,16 +613,6 @@ BUILD_CAST(option)
 #define uci_to_option(ptr)  container_of(ptr, struct uci_option, e)
 #endif
 
-/**
- * uci_alloc_element: allocate a generic uci_element, reserve a buffer and 
typecast
- * @ctx: uci context
- * @type: {package,section,option}
- * @name: string containing the name of the element
- * @datasize: additional buffer size to reserve at the end of the struct
- */
-#define uci_alloc_element(ctx, type, name, datasize) \
-   uci_to_ ## type (uci_alloc_generic(ctx, uci_type_ ## type, name, 
sizeof(struct uci_ ## type) + datasize))
-
 #define uci_dataptr(ptr) \
(((char *) ptr) + sizeof(*ptr))
 
diff --git a/uci_internal.h b/uci_internal.h
index 34528f0..ff4ee8c 100644
--- a/uci_internal.h
+++ b/uci_internal.h
@@ -42,6 +42,9 @@ struct uci_parse_context
 #define pctx_char(pctx, i) ((pctx)->buf[(i)])
 #define pctx_cur_char(pctx)pctx_char(pctx, pctx_pos(pctx))
 
+#define uci_alloc_element(ctx, type, name, datasize) \
+   uci_to_ ## type (uci_alloc_generic(ctx, uci_type_ ## type, name, 
sizeof(struct uci_ ## type) + datasize))
+
 extern const char *uci_confdir;
 extern const char *uci_savedir;
 
-- 
2.32.0 (Apple Git-132)


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


[PATCH 8/9] uci: optimize update section in uci_set

2022-08-16 Thread Jan Venekamp
Optimize for the case when there is no need to update the section and
the case there is no need to reallocate memory when updating a section
in uci_set.

Signed-off-by: Jan Venekamp 
---
 list.c| 23 +++
 tests/shunit2/tests.d/090_cli_options |  8 +---
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/list.c b/list.c
index 783836b..89c70f0 100644
--- a/list.c
+++ b/list.c
@@ -727,14 +727,21 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
ptr->last = >o->e;
}
} else if (ptr->s && ptr->section) { /* update section */
-   struct uci_section *old = ptr->s;
-   ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section, 
>e.list);
-   uci_section_transfer_options(ptr->s, old);
-   if (ptr->section == old->e.name)
-   ptr->section = ptr->o->e.name;
-   uci_free_section(old);
-   ptr->s->package->n_section--;
-   ptr->last = >s->e;
+   if (!strcmp(ptr->s->type, ptr->value))
+   return 0;
+
+   if (strlen(ptr->s->type) == strlen(ptr->value)) {
+   strcpy(ptr->s->type, ptr->value);
+   } else {
+   struct uci_section *old = ptr->s;
+   ptr->s = uci_alloc_section(ptr->p, ptr->value, 
ptr->section, >e.list);
+   uci_section_transfer_options(ptr->s, old);
+   if (ptr->section == old->e.name)
+   ptr->section = ptr->o->e.name;
+   uci_free_section(old);
+   ptr->s->package->n_section--;
+   ptr->last = >s->e;
+   }
} else {
UCI_THROW(ctx, UCI_ERR_INVAL);
}
diff --git a/tests/shunit2/tests.d/090_cli_options 
b/tests/shunit2/tests.d/090_cli_options
index 55920a2..aff8316 100644
--- a/tests/shunit2/tests.d/090_cli_options
+++ b/tests/shunit2/tests.d/090_cli_options
@@ -11,8 +11,9 @@ test_add_delta() {
# save new changes in "$new_savedir"
mkdir -p "$new_savedir"
touch "$new_savedir/delta"
-   $UCI -P "$new_savedir" set delta.sec0=sectype
+   $UCI -P "$new_savedir" set delta.sec0=tmptype
$UCI -P "$new_savedir" add_list delta.sec0.li0=1
+   $UCI -P "$new_savedir" set delta.sec0=sectype
 
assertEquals "delta.sec0='sectype'
 delta.sec0.li0+='0'" "$($UCI changes)"
@@ -22,8 +23,9 @@ delta.sec0.li0+='0'" "$($UCI changes)"
assertTrue "$?"
assertEquals "delta.sec0='sectype'
 delta.sec0.li0+='0'
-delta.sec0='sectype'
-delta.sec0.li0+='1'" "$cmdoutput"
+delta.sec0='tmptype'
+delta.sec0.li0+='1'
+delta.sec0='sectype'" "$cmdoutput"
 
# check combined export.  Order matters here.
cmdoutput="$($UCI -P "$new_savedir" export)"
-- 
2.32.0 (Apple Git-132)


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


[PATCH 7/9] uci: fix memory leak uci_set on update section

2022-08-16 Thread Jan Venekamp
If uci_realloc fails when updating a section in uci_set the reference
to the memory allocated by s = uci_strdup() is lost.

Also, if uci_strdup and uci_realloc both succeed it could happen that
ptr->s->type == uci_dataptr(ptr->s) by accident. Then later on in
uci_free_section the allocated ptr->s->type is not freed.

In order to fix this, instead of splitting the allocation of the the
section and the type string, we create a new section with in-section
storage to replace the old one. This also brings the code for updating
a section more in line with the simular code for updating an option.

Signed-off-by: Jan Venekamp 
---
 list.c | 62 +++---
 1 file changed, 20 insertions(+), 42 deletions(-)

diff --git a/list.c b/list.c
index e6d631c..783836b 100644
--- a/list.c
+++ b/list.c
@@ -30,12 +30,6 @@ static bool uci_list_set_pos(struct uci_list *head, struct 
uci_list *ptr, int po
return (old_head != new_head);
 }
 
-static inline void uci_list_fixup(struct uci_list *ptr)
-{
-   ptr->prev->next = ptr;
-   ptr->next->prev = ptr;
-}
-
 /*
  * uci_alloc_generic allocates a new uci_element with payload
  * payload is appended to the struct to save memory and reduce fragmentation
@@ -182,34 +176,26 @@ static void uci_fixup_section(struct uci_context *ctx, 
struct uci_section *s)
s->e.name = uci_strdup(ctx, buf);
 }
 
-/* fix up option list HEAD pointers and pointer to section in options */
-static void uci_section_fixup_options(struct uci_section *s, bool no_options)
+/* transfer options between two sections */
+static void uci_section_transfer_options(struct uci_section *dst, struct 
uci_section *src)
 {
struct uci_element *e;
 
-   if (no_options) {
-   /*
-* enforce empty list pointer state (s->next == s) when original
-* section had no options in the first place
-*/
-   uci_list_init(>options);
-   return;
-   }
-
-   /* fix pointers to HEAD at end/beginning of list */
-   uci_list_fixup(>options);
+   /* transfer the option list by inserting the new list HEAD and removing 
the old */
+   uci_list_insert(>options, >options);
+   uci_list_del(>options);
 
-   /* fix back pointer to section in options */
-   uci_foreach_element(>options, e) {
+   /* update pointer to section in options */
+   uci_foreach_element(>options, e) {
struct uci_option *o;
 
o = uci_to_option(e);
-   o->section = s;
+   o->section = dst;
}
 }
 
 static struct uci_section *
-uci_alloc_section(struct uci_package *p, const char *type, const char *name)
+uci_alloc_section(struct uci_package *p, const char *type, const char *name, 
struct uci_list *after)
 {
struct uci_context *ctx = p->ctx;
struct uci_section *s;
@@ -226,7 +212,7 @@ uci_alloc_section(struct uci_package *p, const char *type, 
const char *name)
s->anonymous = true;
p->n_section++;
 
-   uci_list_add(>sections, >e.list);
+   uci_list_insert(after ? after : p->sections.prev, >e.list);
 
return s;
 }
@@ -551,7 +537,7 @@ int uci_add_section(struct uci_context *ctx, struct 
uci_package *p, const char *
 
UCI_HANDLE_ERR(ctx);
UCI_ASSERT(ctx, p != NULL);
-   s = uci_alloc_section(p, type, NULL);
+   s = uci_alloc_section(p, type, NULL, NULL);
if (s && s->anonymous)
uci_fixup_section(ctx, s);
*res = s;
@@ -724,7 +710,7 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value, 
NULL);
ptr->last = >o->e;
} else if (!ptr->s && ptr->section) { /* new section */
-   ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section);
+   ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section, 
NULL);
ptr->last = >s->e;
} else if (ptr->o && ptr->option) { /* update option */
if (ptr->o->type == UCI_TYPE_STRING && 
!strcmp(ptr->o->v.string, ptr->value))
@@ -741,22 +727,14 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
ptr->last = >o->e;
}
} else if (ptr->s && ptr->section) { /* update section */
-   char *s = uci_strdup(ctx, ptr->value);
-
-   if (ptr->s->type == uci_dataptr(ptr->s)) {
-   /* drop the in-section storage of type name */
-   bool no_options;
-
-   no_options = uci_list_empty(>s->options);
-   ptr->last = NULL;
-   ptr->last = uci_realloc(ctx, ptr->s, sizeof(struct 
uci_section));
-   ptr->s = uci_to_section(ptr->last);
-   uci_list_fixup(>s->e.list);
-   uci_section_fixup_options(ptr->s, 

[PATCH 5/9] uci: fix atomicity of uci_add_list

2022-08-16 Thread Jan Venekamp
The function uci_add_list is not atomic, when an alloc inside
uci_add_element_list fails the option can be left in an indeterminate
state.

Refactor uci_add_list to fix this and make the code flow easier to
read.

Signed-off-by: Jan Venekamp 
---
 list.c | 74 +-
 1 file changed, 37 insertions(+), 37 deletions(-)

diff --git a/list.c b/list.c
index ba099b6..3518967 100644
--- a/list.c
+++ b/list.c
@@ -497,19 +497,6 @@ uci_expand_ptr(struct uci_context *ctx, struct uci_ptr 
*ptr, bool complete)
return NULL;
 }
 
-static void uci_add_element_list(struct uci_context *ctx, struct uci_ptr *ptr, 
bool internal)
-{
-   struct uci_element *e;
-   struct uci_package *p;
-
-   p = ptr->p;
-   if (!internal && p->has_delta)
-   uci_add_delta(ctx, >delta, UCI_CMD_LIST_ADD, ptr->section, 
ptr->option, ptr->value);
-
-   e = uci_alloc_generic(ctx, UCI_TYPE_ITEM, ptr->value, sizeof(struct 
uci_option));
-   uci_list_add(>o->v.list, >list);
-}
-
 int uci_rename(struct uci_context *ctx, struct uci_ptr *ptr)
 {
/* NB: UCI_INTERNAL use means without delta tracking */
@@ -623,8 +610,7 @@ int uci_add_list(struct uci_context *ctx, struct uci_ptr 
*ptr)
 {
/* NB: UCI_INTERNAL use means without delta tracking */
bool internal = ctx && ctx->internal;
-   struct uci_option *volatile prev = NULL;
-   const char *volatile value2 = NULL;
+   struct uci_element *volatile e1 = NULL, *volatile e2 = NULL;
 
UCI_HANDLE_ERR(ctx);
 
@@ -632,34 +618,48 @@ int uci_add_list(struct uci_context *ctx, struct uci_ptr 
*ptr)
UCI_ASSERT(ctx, ptr->s);
UCI_ASSERT(ctx, ptr->value);
 
-   if (ptr->o) {
-   switch (ptr->o->type) {
-   case UCI_TYPE_STRING:
-   /* we already have a string value, convert that to a 
list */
-   prev = ptr->o;
-   value2 = ptr->value;
-   ptr->value = ptr->o->v.string;
-   break;
-   case UCI_TYPE_LIST:
-   uci_add_element_list(ctx, ptr, internal);
-   return 0;
-   default:
-   UCI_THROW(ctx, UCI_ERR_INVAL);
-   break;
-   }
+   if (ptr->o && ptr->o->type != UCI_TYPE_LIST && ptr->o->type != 
UCI_TYPE_STRING) {
+   UCI_THROW(ctx, UCI_ERR_INVAL);
}
 
-   ptr->o = uci_alloc_list(ptr->s, ptr->option);
-   if (prev) {
-   uci_add_element_list(ctx, ptr, true);
-   if (ptr->option == prev->e.name)
+   /* create new item */
+   e1 = uci_alloc_generic(ctx, UCI_TYPE_ITEM, ptr->value, sizeof(struct 
uci_option));
+
+   if (!ptr->o) {
+   /* create new list */
+   UCI_TRAP_SAVE(ctx, error);
+   ptr->o = uci_alloc_list(ptr->s, ptr->option);
+   UCI_TRAP_RESTORE(ctx);
+   ptr->last = >o->e;
+   } else if (ptr->o->type == UCI_TYPE_STRING) {
+   /* create new list and add old string value as item to list */
+   struct uci_option *old = ptr->o;
+   UCI_TRAP_SAVE(ctx, error);
+   e2 = uci_alloc_generic(ctx, UCI_TYPE_ITEM, old->v.string, 
sizeof(struct uci_option));
+   ptr->o = uci_alloc_list(ptr->s, ptr->option);
+   UCI_TRAP_RESTORE(ctx);
+   uci_list_add(>o->v.list, >list);
+
+   /* remove old option */
+   if (ptr->option == old->e.name)
ptr->option = ptr->o->e.name;
-   uci_free_option(prev);
-   ptr->value = value2;
+   uci_free_option(old);
+   ptr->last = >o->e;
}
-   uci_add_element_list(ctx, ptr, internal);
+
+   /* add new item to list */
+   uci_list_add(>o->v.list, >list);
+
+   if (!internal && ptr->p->has_delta)
+   uci_add_delta(ctx, >p->delta, UCI_CMD_LIST_ADD, 
ptr->section, ptr->option, ptr->value);
 
return 0;
+error:
+   if (e1 != NULL)
+   uci_free_element(e1);
+   if (e2 != NULL)
+   uci_free_element(e2);
+   UCI_THROW(ctx, ctx->err);
 }
 
 int uci_del_list(struct uci_context *ctx, struct uci_ptr *ptr)
-- 
2.32.0 (Apple Git-132)


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


[PATCH 6/9] uci: maintain option position in uci_add_list

2022-08-16 Thread Jan Venekamp
Maintain the position of an option in the list when a string option
is converted to a list option in uci_add_list.

Signed-off-by: Jan Venekamp 
---
 list.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/list.c b/list.c
index 3518967..e6d631c 100644
--- a/list.c
+++ b/list.c
@@ -115,7 +115,7 @@ uci_free_option(struct uci_option *o)
 }
 
 static struct uci_option *
-uci_alloc_list(struct uci_section *s, const char *name)
+uci_alloc_list(struct uci_section *s, const char *name, struct uci_list *after)
 {
struct uci_package *p = s->package;
struct uci_context *ctx = p->ctx;
@@ -125,7 +125,7 @@ uci_alloc_list(struct uci_section *s, const char *name)
o->type = UCI_TYPE_LIST;
o->section = s;
uci_list_init(>v.list);
-   uci_list_add(>options, >e.list);
+   uci_list_insert(after ? after : s->options.prev, >e.list);
 
return o;
 }
@@ -628,7 +628,7 @@ int uci_add_list(struct uci_context *ctx, struct uci_ptr 
*ptr)
if (!ptr->o) {
/* create new list */
UCI_TRAP_SAVE(ctx, error);
-   ptr->o = uci_alloc_list(ptr->s, ptr->option);
+   ptr->o = uci_alloc_list(ptr->s, ptr->option, NULL);
UCI_TRAP_RESTORE(ctx);
ptr->last = >o->e;
} else if (ptr->o->type == UCI_TYPE_STRING) {
@@ -636,7 +636,7 @@ int uci_add_list(struct uci_context *ctx, struct uci_ptr 
*ptr)
struct uci_option *old = ptr->o;
UCI_TRAP_SAVE(ctx, error);
e2 = uci_alloc_generic(ctx, UCI_TYPE_ITEM, old->v.string, 
sizeof(struct uci_option));
-   ptr->o = uci_alloc_list(ptr->s, ptr->option);
+   ptr->o = uci_alloc_list(ptr->s, ptr->option, >e.list);
UCI_TRAP_RESTORE(ctx);
uci_list_add(>o->v.list, >list);
 
-- 
2.32.0 (Apple Git-132)


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


[PATCH 2/9] uci: maintain option position in uci_set

2022-08-16 Thread Jan Venekamp
Maintain the position of an option in the list when updating an option
in uci_set.

Signed-off-by: Jan Venekamp 
---
 list.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/list.c b/list.c
index ac3686c..a8f2a2c 100644
--- a/list.c
+++ b/list.c
@@ -76,7 +76,7 @@ uci_free_element(struct uci_element *e)
 }
 
 static struct uci_option *
-uci_alloc_option(struct uci_section *s, const char *name, const char *value)
+uci_alloc_option(struct uci_section *s, const char *name, const char *value, 
struct uci_list *after)
 {
struct uci_package *p = s->package;
struct uci_context *ctx = p->ctx;
@@ -87,7 +87,7 @@ uci_alloc_option(struct uci_section *s, const char *name, 
const char *value)
o->v.string = uci_dataptr(o);
o->section = s;
strcpy(o->v.string, value);
-   uci_list_add(>options, >e.list);
+   uci_list_insert(after ? after : s->options.prev, >e.list);
 
return o;
 }
@@ -719,7 +719,7 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
 
return uci_delete(ctx, ptr);
} else if (!ptr->o && ptr->option) { /* new option */
-   ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value);
+   ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value, 
NULL);
ptr->last = >o->e;
} else if (!ptr->s && ptr->section) { /* new section */
ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section);
@@ -731,7 +731,7 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
!strcmp(ptr->o->v.string, ptr->value))
return 0;
 
-   ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value);
+   ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value, 
>e.list);
if (ptr->option == old->e.name)
ptr->option = ptr->o->e.name;
uci_free_option(old);
-- 
2.32.0 (Apple Git-132)


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


[PATCH 4/9] uci: fix use-after-free uci_add_list

2022-08-16 Thread Jan Venekamp
When uci_add_list is called with ptr->o set and ptr->option = NULL,
then in uci_expand_ptr ptr->option is set to ptr->o->e.name.
If ptr->o->type is UCI_TYPE_STRING then prev is set to ptr->o.
This will result in use-after-free because ptr->option is used in
the call to uci_add_delta in uci_add_element_list after
uci_free_option(prev).

Signed-off-by: Jan Venekamp 
---
 list.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/list.c b/list.c
index 5148dfd..ba099b6 100644
--- a/list.c
+++ b/list.c
@@ -652,6 +652,8 @@ int uci_add_list(struct uci_context *ctx, struct uci_ptr 
*ptr)
ptr->o = uci_alloc_list(ptr->s, ptr->option);
if (prev) {
uci_add_element_list(ctx, ptr, true);
+   if (ptr->option == prev->e.name)
+   ptr->option = ptr->o->e.name;
uci_free_option(prev);
ptr->value = value2;
}
-- 
2.32.0 (Apple Git-132)


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


[PATCH 3/9] uci: optimize update option in uci_set

2022-08-16 Thread Jan Venekamp
Optimize for the case when there is no need to reallocate memory when
updating an option in uci_set.

Signed-off-by: Jan Venekamp 
---
 list.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/list.c b/list.c
index a8f2a2c..5148dfd 100644
--- a/list.c
+++ b/list.c
@@ -725,17 +725,19 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section);
ptr->last = >s->e;
} else if (ptr->o && ptr->option) { /* update option */
-   struct uci_option *old = ptr->o;
-
-   if ((ptr->o->type == UCI_TYPE_STRING) &&
-   !strcmp(ptr->o->v.string, ptr->value))
+   if (ptr->o->type == UCI_TYPE_STRING && 
!strcmp(ptr->o->v.string, ptr->value))
return 0;
 
-   ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value, 
>e.list);
-   if (ptr->option == old->e.name)
-   ptr->option = ptr->o->e.name;
-   uci_free_option(old);
-   ptr->last = >o->e;
+   if (ptr->o->type == UCI_TYPE_STRING && strlen(ptr->o->v.string) 
== strlen(ptr->value)) {
+   strcpy(ptr->o->v.string, ptr->value);
+   } else {
+   struct uci_option *old = ptr->o;
+   ptr->o = uci_alloc_option(ptr->s, ptr->option, 
ptr->value, >e.list);
+   if (ptr->option == old->e.name)
+   ptr->option = ptr->o->e.name;
+   uci_free_option(old);
+   ptr->last = >o->e;
+   }
} else if (ptr->s && ptr->section) { /* update section */
char *s = uci_strdup(ctx, ptr->value);
 
-- 
2.32.0 (Apple Git-132)


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


[PATCH 1/9] uci: fix use-after-free uci_set on update option

2022-08-16 Thread Jan Venekamp
When uci_set is called with ptr->o set and ptr->option = NULL,
then in uci_expand_ptr ptr->option is set to ptr->o->e.name.
This will result in use-after-free because ptr->option is used in
the call to uci_add_delta after uci_free_option(ptr->o).

Signed-off-by: Jan Venekamp 
---
 list.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/list.c b/list.c
index 24ed2ee..ac3686c 100644
--- a/list.c
+++ b/list.c
@@ -725,15 +725,16 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section);
ptr->last = >s->e;
} else if (ptr->o && ptr->option) { /* update option */
-   struct uci_option *o;
+   struct uci_option *old = ptr->o;
 
if ((ptr->o->type == UCI_TYPE_STRING) &&
!strcmp(ptr->o->v.string, ptr->value))
return 0;
 
-   o = ptr->o;
ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value);
-   uci_free_option(o);
+   if (ptr->option == old->e.name)
+   ptr->option = ptr->o->e.name;
+   uci_free_option(old);
ptr->last = >o->e;
} else if (ptr->s && ptr->section) { /* update section */
char *s = uci_strdup(ctx, ptr->value);
-- 
2.32.0 (Apple Git-132)


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


[PATCH 0/9] uci: fixes for uci_set and uci_add_list

2022-08-16 Thread Jan Venekamp
When developing a C application that updates options with uci_set I
noticed that config files were not getting these updates. I found
that this was due to a use-after-free bug in uci_set.

Looking further at the code I also noticed some other issues. This
patch series contains fixes to these issues as well as some other
improvements.

Jan Venekamp (9):
  uci: fix use-after-free uci_set on update option
  uci: maintain option position in uci_set
  uci: optimize update option in uci_set
  uci: fix use-after-free uci_add_list
  uci: fix atomicity of uci_add_list
  uci: maintain option position in uci_add_list
  uci: fix memory leak uci_set on update section
  uci: optimize update section in uci_set
  uci: macro uci_alloc_element not in uci.h

 list.c| 168 --
 tests/shunit2/tests.d/090_cli_options |   8 +-
 uci.h |  10 --
 uci_internal.h|   3 +
 4 files changed, 87 insertions(+), 102 deletions(-)

-- 
2.32.0 (Apple Git-132)


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


Re: [PATCH] imx: add imx8mplus platform support

2022-08-16 Thread Piotr Dymacz

Hi Andy,

Sorry for late reply. Please, see my comments inline below.

Rafał, Petr, it would be great if you could give your thoughts regarding 
my concerns about the 'firmware-imx' package.


On 04.07.2022 09:24, Yuantian Tang wrote:

Imx8mplus_evk device is built to meet the needs of Smart Home,
Building, City and Industry 4.0, 5G gateway and router  applications.

Hardware specifications:
CPU: 4x or 2x Cortex-A53 up to 1.8 GHz
DRAM: 32-bit DDR4 & LPDDR4 up to 4.0GT/s
Board: imx8mp_evk
SoC: imx8mplus
On-board WiFi/Bluetooth chip: NXP 88W8997
Ethernet: 2x Gigabit Ethernet with AVB, IEEE 1588, EEE and 1x w/ TSN

Signed-off-by: Yuantian Tang 
---
  package/boot/atf-imx/Makefile |   51 +
  package/boot/uboot-imx/Makefile   |   48 +-
  .../uboot-imx/files/imx8mp-sdboot-uEnv.txt|   12 +
  package/firmware/imx/Makefile |   47 +
  package/utils/imx-mkimage/Makefile|   38 +
  target/linux/imx/Makefile |5 +-
  target/linux/imx/config-5.15  |  443 ---
  target/linux/imx/cortexa7/config-default  |  441 +++
  target/linux/imx/cortexa7/target.mk   |2 +
  target/linux/imx/cortexa9/config-default  |  441 +++
  target/linux/imx/cortexa9/target.mk   |2 +
  target/linux/imx/image/gen_sdcard_head_img.sh |   21 +
  target/linux/imx/image/imx8.mk|   98 +
  .../linux/imx/image/mkits-multiple-config.sh  |  600 
  target/linux/imx/imx8/config-5.15 | 2661 +
  target/linux/imx/imx8/target.mk   |   11 +
  .../0001-fix-the-compiling-error.patch|   39 +
  17 files changed, 4508 insertions(+), 452 deletions(-)
  create mode 100644 package/boot/atf-imx/Makefile
  create mode 100644 package/boot/uboot-imx/files/imx8mp-sdboot-uEnv.txt
  create mode 100644 package/firmware/imx/Makefile
  create mode 100644 package/utils/imx-mkimage/Makefile
  delete mode 100644 target/linux/imx/config-5.15
  create mode 100755 target/linux/imx/image/gen_sdcard_head_img.sh
  create mode 100644 target/linux/imx/image/imx8.mk
  create mode 100755 target/linux/imx/image/mkits-multiple-config.sh
  create mode 100644 target/linux/imx/imx8/config-5.15
  create mode 100644 target/linux/imx/imx8/target.mk
  create mode 100644 
target/linux/imx/patches-5.15/0001-fix-the-compiling-error.patch

diff --git a/package/boot/atf-imx/Makefile b/package/boot/atf-imx/Makefile
new file mode 100644
index 00..e76393d1e9
--- /dev/null
+++ b/package/boot/atf-imx/Makefile


We already have bunch of arm-trusted-firmware-* packages for other 
targets and also 'include/trusted-firmware-a.mk' template.


Is there any reason to use custom approach here?

[snip]


diff --git a/package/boot/uboot-imx/Makefile b/package/boot/uboot-imx/Makefile
index 305d127557..f323f92dce 100644
--- a/package/boot/uboot-imx/Makefile
+++ b/package/boot/uboot-imx/Makefile
@@ -7,10 +7,14 @@
  
  include $(TOPDIR)/rules.mk
  
-PKG_VERSION:=2022.01

+PKG_NAME:=uboot-imx
+PKG_VERSION:=lf-5.15.5-1.0.0
 PKG_RELEASE:=$(AUTORELEASE)
  
-PKG_HASH:=81b4543227db228c03f8a1bf5ddbc813b0bb8f6555ce46064ef721a6fc680413

+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://source.codeaurora.org/external/imx/uboot-imx


Please, use the upstream U-Boot. The 'imx8mp_evk' is supported since 
U-Boot ~2020.01 if I'm right.


Are there any specific changes in your U-Boot fork required by this 
board/platform?


[snip]


diff --git a/package/firmware/imx/Makefile b/package/firmware/imx/Makefile
new file mode 100644
index 00..880a882aa2
--- /dev/null
+++ b/package/firmware/imx/Makefile
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Copyright 2022 NXP
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=firmware-imx
+PKG_VERSION:=8.15
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).bin
+PKG_SOURCE_URL:=https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/
+PKG_HASH:=ef91390da6c8a6a48c8121a5dd667de8


OK, so a 'firmware-imx-8.15.bin' file, hosted somewhere on NXP servers 
which seems to be a self-extracting package with bunch of proprietary 
binary blobs and almost 700 lines license. And it asks for EULA 
acceptance when extracting:


"Welcome to NXP firmware-imx-8.15.bin

You need to read and accept the EULA before you can continue.

LA_OPT_NXP_Software_License v34 February 2022
[...]
"
I don't think we can accept this (Rafał, Petr, any opinions?). Looking 
at other open source projects, e.g. Barebox requires users to manually 
obtain and extract the firmware [1]. U-Boot documentation for this board 
mentions only the DDR training and ATF firmware [2].


Are all the blobs really required by this platform? Is there any other, 
more open source friendly way to get these binary blobs?



+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/firmware-imx
+  SECTION:=firmware
+  CATEGORY:=Firmware
+  TITLE:=NXP firmware for imx soc
+  MKIMG_DIR:=`find $(STAGING_DIR_IMAGE) -name imx-mkimage*  | xargs 
basename`/iMX8M
+  

[PATCH uci] cli: drop redundant uci_add_delta_path() call for -P

2022-08-16 Thread Rafał Miłecki
From: Rafał Miłecki 

savedir is always present in the list of delta paths. It's guaranteed by
1. uci_alloc_context() which sets defaults
2. uci_set_savedir() which allows changing savedir

Calling uci_add_delta_path() with ctx->savedir argument seems to always
return UCI_ERR_DUPLICATE.

Fixes: 2b4872345ab2b ("make use of the history path feature in the cli")
Cc: Felix Fietkau 
Signed-off-by: Rafał Miłecki 
---
 cli.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/cli.c b/cli.c
index 2fce39d..b4c4f95 100644
--- a/cli.c
+++ b/cli.c
@@ -748,7 +748,6 @@ int main(int argc, char **argv)
uci_add_delta_path(ctx, optarg);
break;
case 'P':
-   uci_add_delta_path(ctx, ctx->savedir);
uci_set_savedir(ctx, optarg);
flags |= CLI_FLAG_NOCOMMIT;
break;
-- 
2.34.1


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