Changeset 3ae470a in mainline


Ignore:
Timestamp:
2007-06-21T17:04:06Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00acd66
Parents:
6765c07
Message:

Add sanity checks for reads and writes that occur past the end of the
ramdisk image.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/rd/rd.c

    r6765c07 r3ae470a  
    5656/** Pointer to the ramdisk's image. */
    5757static void *rd_addr;
     58/** Size of the ramdisk. */
     59static size_t rd_size;
    5860
    5961/**
     
    7577        ipc_call_t call;
    7678        int retval;
    77         uintptr_t fs_va = NULL;
     79        void *fs_va = NULL;
    7880        ipcarg_t offset;
    7981
     
    140142                case RD_READ_BLOCK:
    141143                        offset = IPC_GET_ARG1(call);
     144                        if (offset * BLOCK_SIZE > rd_size - BLOCK_SIZE) {
     145                                /*
     146                                 * Reading past the end of the device.
     147                                 */
     148                                retval = ELIMIT;
     149                                break;
     150                        }
    142151                        futex_down(&rd_futex);
    143                         memcpy((void *) fs_va, rd_addr + offset, BLOCK_SIZE);
     152                        memcpy(fs_va, rd_addr + offset, BLOCK_SIZE);
    144153                        futex_up(&rd_futex);
    145154                        retval = EOK;
     
    147156                case RD_WRITE_BLOCK:
    148157                        offset = IPC_GET_ARG1(call);
     158                        if (offset * BLOCK_SIZE > rd_size - BLOCK_SIZE) {
     159                                /*
     160                                 * Writing past the end of the device.
     161                                 */
     162                                retval = ELIMIT;
     163                                break;
     164                        }
    149165                        futex_up(&rd_futex);
    150                         memcpy(rd_addr + offset, (void *) fs_va, BLOCK_SIZE);
     166                        memcpy(rd_addr + offset, fs_va, BLOCK_SIZE);
    151167                        futex_down(&rd_futex);
    152168                        retval = EOK;
     
    171187        int retval, flags;
    172188
    173         size_t rd_size = sysinfo_value("rd.size");
     189        rd_size = sysinfo_value("rd.size");
    174190        void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical");
    175191       
Note: See TracChangeset for help on using the changeset viewer.