table: fix out of bounds write
[dpdk.git] / drivers / raw / ifpga / base / ifpga_fme_rsu.c
index 28198ab..f147aaa 100644 (file)
@@ -128,7 +128,12 @@ static int write_flash_image(struct ifpga_sec_mgr *smgr, const char *image,
        do {
                to_transfer = (length > IFPGA_RSU_DATA_BLK_SIZE) ?
                        IFPGA_RSU_DATA_BLK_SIZE : length;
-               lseek(fd, offset, SEEK_SET);
+               if (lseek(fd, offset, SEEK_SET) < 0) {
+                       dev_err(smgr, "Failed to seek in \'%s\' [e:%s]\n",
+                               image, strerror(errno));
+                       ret = -EIO;
+                       goto end;
+               }
                read_size = read(fd, buf, to_transfer);
                if (read_size < 0) {
                        dev_err(smgr, "Failed to read from \'%s\' [e:%s]\n",
@@ -270,6 +275,7 @@ int fpga_update_flash(struct ifpga_fme_hw *fme, const char *image,
        struct ifpga_sec_mgr *smgr = NULL;
        uint32_t rsu_stat = 0;
        int fd = -1;
+       off_t len = 0;
        struct sigaction old_sigint_action;
        struct sigaction sa;
        time_t start;
@@ -313,9 +319,21 @@ int fpga_update_flash(struct ifpga_fme_hw *fme, const char *image,
                        image, strerror(errno));
                return -EIO;
        }
-       smgr->rsu_length = lseek(fd, 0, SEEK_END);
+       len = lseek(fd, 0, SEEK_END);
        close(fd);
 
+       if (len < 0) {
+               dev_err(smgr,
+                       "Failed to get file length of \'%s\' [e:%s]\n",
+                       image, strerror(errno));
+               return -EIO;
+       }
+       if (len == 0) {
+               dev_err(smgr, "Length of file \'%s\' is invalid\n", image);
+               return -EINVAL;
+       }
+       smgr->rsu_length = len;
+
        if (smgr->max10_dev->staging_area_size < smgr->rsu_length) {
                dev_err(dev, "Size of staging area is small than image length "
                        "[%u<%u]\n", smgr->max10_dev->staging_area_size,