[astro] 8.20220713.2.219 u-boot source GitOrigin-RevId: 70fefe660f7044e5984dccdcb53b16d9a9de020b Change-Id: If4d26c2a9f3d983def6da7a34e9495a51c738538 Reviewed-on: https://turquoise-internal-review.googlesource.com/c/third_party/u-boot/+/619913 Reviewed-by: David Pursell <dpursell@google.com>
diff --git a/fs/fs.c b/fs/fs.c index a0a5266..ac146f3 100644 --- a/fs/fs.c +++ b/fs/fs.c
@@ -278,13 +278,57 @@ return ret; } -int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, - loff_t *actread) +#ifdef CONFIG_LMB +/* Check if a file may be read to the given address */ +static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset, + loff_t len, struct fstype_info *info) +{ + struct lmb lmb; + int ret; + loff_t size; + loff_t read_len; + + /* get the actual size of the file */ + ret = info->size(filename, &size); + if (ret) + return ret; + if (offset >= size) { + /* offset >= EOF, no bytes will be written */ + return 0; + } + read_len = size - offset; + + /* limit to 'len' if it is smaller */ + if (len && len < read_len) + read_len = len; + + lmb_init_and_reserve(&lmb, gd->bd->bi_dram[0].start, + gd->bd->bi_dram[0].size, (void *)gd->fdt_blob); + lmb_dump_all(&lmb); + + if (lmb_alloc_addr(&lmb, addr, read_len) == addr) + return 0; + + printf("** Reading file would overwrite reserved memory **\n"); + return -ENOSPC; +} +#endif + +static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, + int do_lmb_check, loff_t *actread) { struct fstype_info *info = fs_get_info(fs_type); void *buf; int ret; +#ifdef CONFIG_LMB + if (do_lmb_check) { + ret = fs_read_lmb_check(filename, addr, offset, len, info); + if (ret) + return ret; + } +#endif + /* * We don't actually know how many bytes are being read, since len==0 * means read the whole file. @@ -303,6 +347,12 @@ return ret; } +int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, + loff_t *actread) +{ + return _fs_read(filename, addr, offset, len, 0, actread); +} + int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, loff_t *actwrite) { @@ -393,7 +443,7 @@ pos = 0; time = get_timer(0); - ret = fs_read(filename, addr, pos, bytes, &len_read); + ret = _fs_read(filename, addr, pos, bytes, 1, &len_read); time = get_timer(time); if (ret < 0) return 1;
diff --git a/include/lmb.h b/include/lmb.h index 6b6959f..ef33ee2 100644 --- a/include/lmb.h +++ b/include/lmb.h
@@ -32,6 +32,8 @@ extern struct lmb lmb; extern void lmb_init(struct lmb *lmb); +extern void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base, + phys_size_t size, void *fdt_blob); extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size); extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align); @@ -53,6 +55,8 @@ void board_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve(struct lmb *lmb); +phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, phys_size_t size); + #endif /* __KERNEL__ */ #endif /* _LINUX_LMB_H */
diff --git a/lib/lmb.c b/lib/lmb.c index 031f0e1..03bb9bb 100644 --- a/lib/lmb.c +++ b/lib/lmb.c
@@ -105,6 +105,19 @@ lmb->reserved.size = 0; } +/* Initialize the struct, add memory and call arch/board reserve functions */ +void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size, + void *fdt_blob) +{ + lmb_init(lmb); + lmb_add(lmb, base, size); + arch_lmb_reserve(lmb); + board_lmb_reserve(lmb); + + if (IMAGE_ENABLE_OF_LIBFDT && fdt_blob) + boot_fdt_add_mem_rsv_regions(lmb, fdt_blob); +} + /* This routine called with relocation disabled. */ static long lmb_add_region(struct lmb_region *rgn, phys_addr_t base, phys_size_t size) { @@ -344,3 +357,29 @@ { /* please define platform specific arch_lmb_reserve() */ } + +/* + * Try to allocate a specific address range: must be in defined memory but not + * reserved + */ +phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, phys_size_t size) +{ + long rgn; + + /* Check if the requested address is in one of the memory regions */ + rgn = lmb_overlaps_region(&lmb->memory, base, size); + if (rgn >= 0) { + /* + * Check if the requested end address is in the same memory + * region we found. + */ + if (lmb_addrs_overlap(lmb->memory.region[rgn].base, + lmb->memory.region[rgn].size, + base + size - 1, 1)) { + /* ok, reserve the memory */ + if (lmb_reserve(lmb, base, size) >= 0) + return base; + } + } + return 0; +}
diff --git a/lib/uuid.c b/lib/uuid.c index 1d0593a..3087d9c 100644 --- a/lib/uuid.c +++ b/lib/uuid.c
@@ -247,6 +247,8 @@ unsigned int *ptr = (unsigned int *)&uuid; int i; + srand(get_ticks() + rand()); + /* Set all fields randomly */ for (i = 0; i < sizeof(struct uuid) / sizeof(*ptr); i++) *(ptr + i) = cpu_to_be32(rand());
diff --git a/net/net.c b/net/net.c index 2bea07b..015068d 100644 --- a/net/net.c +++ b/net/net.c
@@ -1136,6 +1136,9 @@ return; } + if (ntohs(ip->udp_len) < UDP_HDR_SIZE || ntohs(ip->udp_len) > ntohs(ip->ip_len)) + return; + debug_cond(DEBUG_DEV_PKT, "received UDP (to=%pI4, from=%pI4, len=%d)\n", &dst_ip, &src_ip, len);
diff --git a/net/nfs.c b/net/nfs.c index 381b75f..8d7de85 100644 --- a/net/nfs.c +++ b/net/nfs.c
@@ -604,7 +604,10 @@ debug("%s\n", __func__); - if (dest != NfsOurPort) + if (len > sizeof(struct rpc_t)) + return; + + if (dest != nfs_our_port) return; switch (NfsState) {