scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61
Subsystems (2)
Rob Herring
maintainerPATCH 1/1 scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61
It's been a while since the last sync and Lee needs commit 73590342fc85 ("libfdt: prevent integer overflow in fdt_next_tag").
This adds the following commits from upstream:
55778a03df61 libfdt: tests: add get_next_tag_invalid_prop_len 73590342fc85 libfdt: prevent integer overflow in fdt_next_tag 035fb90d5375 libfdt: add fdt_get_property_by_offset_w helper 98a07006c48d Makefile: fix infinite recursion by dropping non-existent %.output a036cc7b0c10 Makefile: limit make re-execution to avoid infinite spin c6e92108bcd9 libdtc: remove duplicate judgmentse37c25677dc9 Don't generate erroneous fixups from reference to path 50454658f2b5 libfdt: Don't mask fdt_get_name() returned error e64a204196c9 manual.txt: Follow README.md and remove Jon f508c83fe6f0 Update README in MANIFEST.in and setup.py to README.md c2ccf8a77dd2 Add description of Signed-off-by lines90b9d9de42ca Split out information for contributors to CONTRIBUTING.md 0ee1d479b23a Remove Jon Loeliger from maintainers listb33a73c62c1c Convert README to README.md7ad60734b1c1 Allow static building with mesonfd9b8c96c780 Allow static building with makefda71da26e7f libfdt: Handle failed get_name() on BEGIN_NODE c7c7f17a83d5 Fix test script to run also on dash shell01f23ffe1679 Add missing relref_merge test to meson test list ed310803ea89 pylibfdt: add FdtRo.get_path()c001fc01a43e pylibfdt: fix swig build in install26c54f840d23 tests: add test cases for label-relative path references ec7986e682cf dtc: introduce label relative path references 651410e54cb9 util: introduce xstrndup helper4048aed12b81 setup.py: fix out of tree buildff5afb96d0c0 Handle integer overflow in check_property_phandle_args() ca7294434309 README: Explain how to add a new API function c0c2e115f82e Fix a UB when fdt_get_string return nullcd5f69cbc0d4 tests: setprop_inplace: use xstrdup instead of unchecked strdup a04f69025003 pylibfdt: add Property.as_*int*_array()83102717d7c4 pylibfdt: add Property.as_stringlist()d152126bb029 Fix Python crash on getprop deallocation17739b7ef510 Support 'r' format for printing raw bytes with fdtget 45f3d1a095dd libfdt: overlay: make overlay_get_target() public c19a4bafa514 libfdt: fix an incorrect integer promotion1cc41b1c969f pylibfdt: Add packaging metadatadb72398cd437 README: Update pylibfdt install instructions 383e148b70a4 pylibfdt: fix with Python 3.1023b56cb7e189 pylibfdt: Move setup.py to the top level69a760747d8d pylibfdt: Split setup.py author name and email 0b106a77dbdc pylibfdt: Use setuptools_scm for the version c691776ddb26 pylibfdt: Use setuptools instead of distutils 5216f3f1bbb7 libfdt: Add static lib to meson build4eda2590f481 CI: Cirrus: bump used FreeBSD from 12.1 to 13.0
--- scripts/dtc/checks.c | 15 +++++++----- scripts/dtc/dtc-lexer.l | 2 +- scripts/dtc/dtc-parser.y | 13 ++++++++++ scripts/dtc/libfdt/fdt.c | 20 +++++++++------ scripts/dtc/libfdt/fdt.h | 4 +-- scripts/dtc/libfdt/fdt_addresses.c | 2 +- scripts/dtc/libfdt/fdt_overlay.c | 29 ++++++---------------- scripts/dtc/libfdt/fdt_ro.c | 2 +- scripts/dtc/libfdt/libfdt.h | 25 +++++++++++++++++++ scripts/dtc/livetree.c | 39 +++++++++++++++++++++++++++--- scripts/dtc/util.c | 15 ++++++++++-- scripts/dtc/util.h | 4 ++- scripts/dtc/version_gen.h | 2 +- 13 files changed, 124 insertions(+), 48 deletions(-)
scripts/dtc/checks.c +9 -6
@@ -1382,10 +1382,10 @@ struct provider { };static void check_property_phandle_args (struct check *c, -struct dt_info *dti, -struct node *node, -struct property *prop, -const struct provider *provider) +struct dt_info *dti, +struct node *node, +struct property *prop, +const struct provider *provider) {struct node *root = dti->dt;unsigned int cell, cellsize =0 ;
@@ -1401,6 +1401,7 @@ static void check_property_phandle_args(struct check *c,struct node *provider_node;struct property *cellprop;cell_t phandle; +unsigned int expected; phandle =propval_cell_n (prop, cell);/*
@@ -1450,10 +1451,12 @@ static void check_property_phandle_args(struct check *c,break ; } -if (prop->val.len < ((cell + cellsize +1 ) *sizeof (cell_t))) { + expected = (cell + cellsize +1 ) *sizeof (cell_t); +if ((expected <= cell) || prop->val.len < expected) {FAIL_PROP (c, dti, node, prop, -"property size (%d) too small for cell size %d" , +"property size (%d) too small for cell size %u" , prop->val.len, cellsize); +break ; } } }
scripts/dtc/dtc-lexer.l +1 -1
@@ -200,7 +200,7 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...); return DT_LABEL_REF; } -<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */ +<*>"&{"{PATHCHAR}*\} { /* new-style path reference */ yytext[yyleng-1] = '\0'; DPRINT("Ref: %s\n", yytext+2); yylval.labelref = xstrdup(yytext+2);
scripts/dtc/dtc-parser.y +13 -0
@@ -23,6 +23,12 @@ extern void yyerror(char const *s); extern struct dt_info *parser_output; extern bool treesource_error; + +static bool is_ref_relative(const char *ref) +{ + return ref[0] != '/' && strchr(&ref[1], '/'); +} + %} %union {
@@ -169,6 +175,8 @@ devicetree: */ if (!($<flags>-1 & DTSF_PLUGIN)) ERROR(&@2, "Label or path %s not found", $1); + else if (is_ref_relative($1)) + ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); $$ = add_orphan_node( name_node(build_node(NULL, NULL, NULL), ""),
@@ -178,6 +186,9 @@ devicetree: { struct node *target = get_node_by_ref($1, $3); + if (($<flags>-1 & DTSF_PLUGIN) && is_ref_relative($3)) + ERROR(&@2, "Label-relative reference %s not supported in plugin", $3); + if (target) { add_label(&target->labels, $2); merge_nodes(target, $4);
@@ -193,6 +204,8 @@ devicetree: * so $-1 is what we want (plugindecl) */ if ($<flags>-1 & DTSF_PLUGIN) { + if (is_ref_relative($2)) + ERROR(&@2, "Label-relative reference %s not supported in plugin", $2); add_orphan_node($1, $3, $2); } else { struct node *target = get_node_by_ref($1, $2);
scripts/dtc/libfdt/fdt.c +12 -8
@@ -106,7 +106,6 @@ int fdt_check_header(const void *fdt) } hdrsize =fdt_header_size (fdt);if (!can_assume (VALID_DTB )) { -if ((fdt_totalsize (fdt) < hdrsize) || (fdt_totalsize (fdt) >INT_MAX ))return -FDT_ERR_TRUNCATED ;
@@ -115,9 +114,7 @@ int fdt_check_header(const void *fdt)if (!check_off_ (hdrsize,fdt_totalsize (fdt),fdt_off_mem_rsvmap (fdt)))return -FDT_ERR_TRUNCATED ; - } - if (!can_assume(VALID_DTB)) {/* Bounds check structure block */ if (!can_assume(LATEST) && fdt_version(fdt) < 17) { if (!check_off_(hdrsize, fdt_totalsize(fdt),
@@ -165,7 +162,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)uint32_t fdt_next_tag (const void *fdt,int startoffset,int *nextoffset) {const fdt32_t *tagp, *lenp; -uint32_t tag; +uint32_t tag, len, sum;int offset = startoffset;const char *p;
@@ -191,12 +188,19 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) lenp =fdt_offset_ptr (fdt, offset,sizeof (*lenp));if (!can_assume (VALID_DTB ) && !lenp)return FDT_END ;/* premature end */ + + len =fdt32_to_cpu (*lenp); + sum = len + offset; +if (!can_assume (VALID_DTB ) && + (INT_MAX <= sum || sum < (uint32_t ) offset)) +return FDT_END ;/* premature end */ +/* skip-name offset, length and value */ - offset +=sizeof (struct fdt_property ) -FDT_TAGSIZE - +fdt32_to_cpu (*lenp); + offset +=sizeof (struct fdt_property ) -FDT_TAGSIZE + len; +if (!can_assume (LATEST ) && -fdt_version (fdt) <0x10 &&fdt32_to_cpu (*lenp) >=8 && - ((offset -fdt32_to_cpu (*lenp)) %8 ) !=0 ) +fdt_version (fdt) <0x10 && len >=8 && + ((offset - len) %8 ) !=0 ) offset +=4 ;break ;
scripts/dtc/libfdt/fdt.h +2 -2
@@ -35,14 +35,14 @@ struct fdt_reserve_entry {struct fdt_node_header {fdt32_t tag; -char name[]; +char name[0 ]; };struct fdt_property {fdt32_t tag;fdt32_t len;fdt32_t nameoff; -char data[]; +char data[0 ]; };#endif /* !__ASSEMBLY */
scripts/dtc/libfdt/fdt_addresses.c +1 -1
@@ -73,7 +73,7 @@ int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,/* check validity of address */ prop = data;if (addr_cells ==1 ) { -if ((addr >UINT32_MAX ) || ((UINT32_MAX +1 - addr) < size)) +if ((addr >UINT32_MAX ) || (((uint64_t )UINT32_MAX +1 - addr) < size))return -FDT_ERR_BADVALUE ;fdt32_st (prop, (uint32_t )addr);
scripts/dtc/libfdt/fdt_overlay.c +7 -22
@@ -40,37 +40,22 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)return fdt32_to_cpu (*val); } -/** -* overlay_get_target - retrieves the offset of a fragment's target -* @fdt: Base device tree blob -* @fdto: Device tree overlay blob -* @fragment: node offset of the fragment in the overlay -* @pathp: pointer which receives the path of the target (or NULL) -* -* overlay_get_target() retrieves the target offset in the base -* device tree of a fragment, no matter how the actual targeting is -* done (through a phandle or a path) -* -* returns: -* the targeted node offset in the base device tree -* Negative error code on error -*/ -static int overlay_get_target (const void *fdt,const void *fdto, -int fragment,char const **pathp) +int fdt_overlay_target_offset (const void *fdt,const void *fdto, +int fragment_offset,char const **pathp) {uint32_t phandle;const char *path =NULL ;int path_len =0 , ret;/* Try first to do a phandle based lookup */ - phandle =overlay_get_target_phandle (fdto, fragment); + phandle =overlay_get_target_phandle (fdto, fragment_offset);if (phandle == (uint32_t )-1 )return -FDT_ERR_BADPHANDLE ;/* no phandle, try path */ if (!phandle) {/* And then a path based lookup */ - path =fdt_getprop (fdto, fragment,"target-path" , &path_len); + path =fdt_getprop (fdto, fragment_offset,"target-path" , &path_len);if (path) ret =fdt_path_offset (fdt, path);else
@@ -636,7 +621,7 @@ static int overlay_merge(void *fdt, void *fdto)if (overlay <0 )return overlay; - target =overlay_get_target (fdt, fdto, fragment,NULL ); + target =fdt_overlay_target_offset (fdt, fdto, fragment,NULL );if (target <0 )return target;
@@ -779,7 +764,7 @@ static int overlay_symbol_update(void *fdt, void *fdto)return -FDT_ERR_BADOVERLAY ;/* get the target of the fragment */ - ret =overlay_get_target (fdt, fdto, fragment, &target_path); + ret =fdt_overlay_target_offset (fdt, fdto, fragment, &target_path);if (ret <0 )return ret; target = ret;
@@ -801,7 +786,7 @@ static int overlay_symbol_update(void *fdt, void *fdto)if (!target_path) {/* again in case setprop_placeholder changed it */ - ret =overlay_get_target (fdt, fdto, fragment, &target_path); + ret =fdt_overlay_target_offset (fdt, fdto, fragment, &target_path);if (ret <0 )return ret; target = ret;
scripts/dtc/libfdt/fdt_ro.c +1 -1
@@ -481,12 +481,12 @@ const void *fdt_getprop_by_offset(const void *fdt, int offset,if (!can_assume (VALID_INPUT )) { name =fdt_get_string (fdt,fdt32_ld_ (&prop->nameoff), &namelen); + *namep = name;if (!name) {if (lenp) *lenp = namelen;return NULL ; } - *namep = name; }else { *namep =fdt_string (fdt,fdt32_ld_ (&prop->nameoff)); }
scripts/dtc/libfdt/libfdt.h +25 -0
@@ -660,6 +660,13 @@ int fdt_next_property_offset(const void *fdt, int offset);const struct fdt_property *fdt_get_property_by_offset (const void *fdt,int offset,int *lenp); +static inline struct fdt_property *fdt_get_property_by_offset_w (void *fdt, +int offset, +int *lenp) +{ +return (struct fdt_property *)(uintptr_t ) +fdt_get_property_by_offset (fdt, offset, lenp); +}/** * fdt_get_property_namelen - find a property based on substring
@@ -2116,6 +2123,24 @@ int fdt_del_node(void *fdt, int nodeoffset);*/ int fdt_overlay_apply (void *fdt,void *fdto); +/** +* fdt_overlay_target_offset - retrieves the offset of a fragment's target +* @fdt: Base device tree blob +* @fdto: Device tree overlay blob +* @fragment_offset: node offset of the fragment in the overlay +* @pathp: pointer which receives the path of the target (or NULL) +* +* fdt_overlay_target_offset() retrieves the target offset in the base +* device tree of a fragment, no matter how the actual targeting is +* done (through a phandle or a path) +* +* returns: +* the targeted node offset in the base device tree +* Negative error code on error +*/ +int fdt_overlay_target_offset (const void *fdt,const void *fdto, +int fragment_offset,char const **pathp); +/**********************************************************************/ /* Debugging / informational functions */ /**********************************************************************/
scripts/dtc/livetree.c +36 -3
@@ -581,12 +581,39 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle)struct node *get_node_by_ref (struct node *tree,const char *ref) { +struct node *target = tree; +const char *label =NULL , *path =NULL ; +if (streq (ref,"/" ))return tree; -else if (ref[0 ] =='/' ) -return get_node_by_path (tree, ref); + +if (ref[0 ] =='/' ) + path = ref;else -return get_node_by_label (tree, ref); + label = ref; + +if (label) { +const char *slash =strchr (label,'/' ); +char *buf =NULL ; + +if (slash) { + buf =xstrndup (label, slash - label); + label = buf; + path = slash +1 ; + } + + target =get_node_by_label (tree, label); + +free (buf); + +if (!target) +return NULL ; + } + +if (path) + target =get_node_by_path (target, path); + +return target; }cell_t get_node_phandle (struct node *root,struct node *node)
@@ -892,6 +919,12 @@ static void add_fixup_entry(struct dt_info *dti, struct node *fn,/* m->ref can only be a REF_PHANDLE, but check anyway */ assert (m->type ==REF_PHANDLE ); +/* The format only permits fixups for references to label, not +* references to path */ +if (strchr (m->ref,'/' )) +die ("Can't generate fixup for reference to path &{%s}\n" , + m->ref); +/* there shouldn't be any ':' in the arguments */ if (strchr (node->fullpath,':' ) ||strchr (prop->name,':' ))die ("arguments should not contain ':'\n" );
scripts/dtc/util.c +13 -2
@@ -33,6 +33,17 @@ char *xstrdup(const char *s)return d; } +char *xstrndup (const char *s,size_t n) +{ +size_t len =strnlen (s, n) +1 ; +char *d =xmalloc (len); + +memcpy (d, s, len -1 ); + d[len -1 ] ='\0' ; + +return d; +} +int xavsprintf_append (char **strp,const char *fmt,va_list ap) {int n, size =0 ;/* start with 128 bytes */
@@ -353,11 +364,11 @@ int utilfdt_decode_type(const char *fmt, int *type, int *size) }/* we should now have a type */ -if ((*fmt =='\0' ) || !strchr ("iuxs" , *fmt)) +if ((*fmt =='\0' ) || !strchr ("iuxsr" , *fmt))return -1 ;/* convert qualifier (bhL) to byte size */ -if (*fmt !='s' ) +if (*fmt !='s' && *fmt !='r' ) *size = qualifier =='b' ?1 : qualifier =='h' ?2 : qualifier =='l' ?4 :-1 ;
scripts/dtc/util.h +3 -1
@@ -61,6 +61,7 @@ static inline void *xrealloc(void *p, size_t len) }extern char *xstrdup (const char *s); +extern char *xstrndup (const char *s,size_t len); extern int PRINTF(2, 3) xasprintf(char **strp, const char *fmt, ...); extern int PRINTF(2, 3) xasprintf_append(char **strp, const char *fmt, ...);
@@ -143,6 +144,7 @@ int utilfdt_write_err(const char *filename, const void *blob);* i signed integer * u unsigned integer * x hex +* r raw * * TODO: Implement ll modifier (8 bytes) * TODO: Implement o type (octal)
@@ -160,7 +162,7 @@ int utilfdt_decode_type(const char *fmt, int *type, int *size);*/ #define USAGE_TYPE_MSG \ - "<type>\ts=string, i=int, u=unsigned, x=hex\n" \ + "<type>\ts=string, i=int, u=unsigned, x=hex, r=raw\n" \ "\tOptional modifier prefix:\n" \ "\t\thh or b=byte, h=2 byte, l=4 byte (default)";
scripts/dtc/version_gen.h +1 -1
@@ -1 +1 @@ -#define DTC_VERSION "DTC 1.6.1-g0a3a9d34" +#define DTC_VERSION "DTC 1.6.1-g55778a03"
Signature · 1 line
2.35.1
Quoted 41 lines · Rob Herring
It's been a while since the last sync and Lee needs commit
73590342fc85("libfdt: prevent integer overflow infdt_next_tag").This adds the following commits from upstream:
55778a03df61libfdt: tests: addget_next_tag_invalid_prop_len73590342fc85libfdt: prevent integer overflow infdt_next_tag035fb90d5375libfdt: addfdt_get_property_by_offset_whelper98a07006c48dMakefile: fix infinite recursion by dropping non-existent%.outputa036cc7b0c10Makefile: limit make re-execution to avoid infinite spinc6e92108bcd9libdtc: remove duplicate judgmentse37c25677dc9Don't generate erroneous fixups from reference to path50454658f2b5libfdt: Don't maskfdt_get_name()returned errore64a204196c9manual.txt: Follow README.md and remove Jonf508c83fe6f0Update README in MANIFEST.in andsetup.pyto README.mdc2ccf8a77dd2Add description of Signed-off-by lines90b9d9de42caSplit out information for contributors to CONTRIBUTING.md0ee1d479b23aRemove Jon Loeliger from maintainers listb33a73c62c1cConvert README to README.md7ad60734b1c1Allow static building with mesonfd9b8c96c780Allow static building with makefda71da26e7flibfdt: Handle failedget_name()onBEGIN_NODEc7c7f17a83d5Fix test script to run also on dash shell01f23ffe1679Add missingrelref_mergetest to meson test listed310803ea89pylibfdt: addFdtRo.get_path()c001fc01a43epylibfdt: fix swig build in install26c54f840d23tests: add test cases for label-relative path referencesec7986e682cfdtc: introduce label relative path references651410e54cb9util: introduce xstrndup helper4048aed12b81setup.py: fix out of tree buildff5afb96d0c0Handle integer overflow incheck_property_phandle_args()ca7294434309README: Explain how to add a new API functionc0c2e115f82eFix a UB whenfdt_get_stringreturn nullcd5f69cbc0d4tests:setprop_inplace: use xstrdup instead of unchecked strdupa04f69025003pylibfdt: add Property.as_*int*_array()83102717d7c4pylibfdt: addProperty.as_stringlist()d152126bb029Fix Python crash on getprop deallocation17739b7ef510Support 'r' format for printing raw bytes with fdtget45f3d1a095ddlibfdt: overlay: makeoverlay_get_target()publicc19a4bafa514libfdt: fix an incorrect integer promotion1cc41b1c969fpylibfdt: Add packaging metadata
Quoted 8 lines
db72398cd437README: Update pylibfdt install instructions383e148b70a4pylibfdt: fix with Python 3.1023b56cb7e189pylibfdt: Movesetup.pyto the top level69a760747d8dpylibfdt: Splitsetup.pyauthor name and email0b106a77dbdcpylibfdt: Usesetuptools_scmfor the versionc691776ddb26pylibfdt: Use setuptools instead of distutils5216f3f1bbb7libfdt: Add static lib to meson build4eda2590f481CI: Cirrus: bump used FreeBSD from 12.1 to 13.0
At least one of these patches fixes security concerns.
Could we also have this in Stable please?
Quoted 16 lines
Signed-off-by Rob Herring <[email protected]>--- scripts/dtc/checks.c | 15 +++++++----- scripts/dtc/dtc-lexer.l | 2 +- scripts/dtc/dtc-parser.y | 13 ++++++++++ scripts/dtc/libfdt/fdt.c | 20 +++++++++------ scripts/dtc/libfdt/fdt.h | 4 +-- scripts/dtc/libfdt/fdt_addresses.c | 2 +- scripts/dtc/libfdt/fdt_overlay.c | 29 ++++++---------------- scripts/dtc/libfdt/fdt_ro.c | 2 +- scripts/dtc/libfdt/libfdt.h | 25 +++++++++++++++++++ scripts/dtc/livetree.c | 39 +++++++++++++++++++++++++++--- scripts/dtc/util.c | 15 ++++++++++-- scripts/dtc/util.h | 4 ++- scripts/dtc/version_gen.h | 2 +- 13 files changed, 124 insertions(+), 48 deletions(-)
Signature · 1 line
Lee Jones [李琼斯]