Changeset 0f5c4e4 in mainline


Ignore:
Timestamp:
2025-05-28T19:02:32Z (35 hours ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Parents:
61f28c4
Message:

Fix crash in AHCI driver and sata_bd server.

Location:
uspace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/block/ahci/ahci.c

    r61f28c4 r0f5c4e4  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2012 Petr Jerman
    34 * All rights reserved.
     
    10751076        }
    10761077
     1078        fun = sata->fun;
    10771079        ddf_fun_set_ops(fun, &ahci_ops);
    10781080
  • uspace/lib/drv/generic/remote_ahci.c

    r61f28c4 r0f5c4e4  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2012 Petr Jerman
    34 * All rights reserved.
     
    152153            IPC_M_AHCI_READ_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
    153154
    154         async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
    155 
     155        errno_t rc = async_data_read_start(exch, buf, count * 512);
    156156        async_exchange_end(exch);
    157 
    158         errno_t rc;
    159         async_wait_for(req, &rc);
    160 
    161         return rc;
     157        if (rc != EOK) {
     158                async_forget(req);
     159                return rc;
     160        }
     161
     162        errno_t retval;
     163        async_wait_for(req, &retval);
     164        return retval;
    162165}
    163166
     
    172175            IPC_M_AHCI_WRITE_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
    173176
    174         async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
    175 
     177        errno_t rc = async_data_write_start(exch, buf, count * 512);
    176178        async_exchange_end(exch);
    177179
    178         errno_t rc;
    179         async_wait_for(req, &rc);
    180 
    181         return rc;
     180        if (rc != EOK) {
     181                async_forget(req);
     182                return rc;
     183        }
     184
     185        errno_t retval;
     186        async_wait_for(req, &retval);
     187        return retval;
    182188}
    183189
     
    284290        }
    285291
    286         ipc_call_t data;
    287         size_t maxblock_size;
    288         unsigned int flags;
    289         async_share_out_receive(&data, &maxblock_size, &flags);
    290 
    291         void *buf;
    292         async_share_out_finalize(&data, &buf);
    293 
    294         const uint64_t blocknum =
     292        ipc_call_t rcall;
     293        size_t size;
     294        if (!async_data_read_receive(&rcall, &size)) {
     295                async_answer_0(&rcall, EINVAL);
     296                async_answer_0(call, EINVAL);
     297                return;
     298        }
     299
     300        void *buf = malloc(size);
     301        if (buf == NULL) {
     302                async_answer_0(&rcall, ENOMEM);
     303                async_answer_0(call, ENOMEM);
     304                return;
     305        }
     306
     307        uint64_t blocknum =
    295308            (((uint64_t) (DEV_IPC_GET_ARG1(*call))) << 32) |
    296309            (((uint64_t) (DEV_IPC_GET_ARG2(*call))) & 0xffffffff);
    297         const size_t cnt = (size_t) DEV_IPC_GET_ARG3(*call);
    298 
    299         const errno_t ret = ahci_iface->read_blocks(fun, blocknum, cnt, buf);
    300 
    301         async_answer_0(call, ret);
     310        size_t cnt = (size_t) DEV_IPC_GET_ARG3(*call);
     311
     312        errno_t rc = ahci_iface->read_blocks(fun, blocknum, cnt, buf);
     313        if (rc != EOK) {
     314                async_answer_0(&rcall, ENOMEM);
     315                async_answer_0(call, ENOMEM);
     316                free(buf);
     317                return;
     318        }
     319
     320        async_data_read_finalize(&rcall, buf, size);
     321
     322        free(buf);
     323        async_answer_0(call, EOK);
    302324}
    303325
     
    306328        const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
    307329
    308         if (ahci_iface->read_blocks == NULL) {
    309                 async_answer_0(call, ENOTSUP);
    310                 return;
    311         }
    312 
    313         ipc_call_t data;
    314         size_t maxblock_size;
    315         unsigned int flags;
    316         async_share_out_receive(&data, &maxblock_size, &flags);
    317 
    318         void *buf;
    319         async_share_out_finalize(&data, &buf);
    320 
    321         const uint64_t blocknum =
     330        if (ahci_iface->write_blocks == NULL) {
     331                async_answer_0(call, ENOTSUP);
     332                return;
     333        }
     334
     335        void *data;
     336        size_t dsize;
     337        errno_t rc = async_data_write_accept(&data, false, 0, 0, 0, &dsize);
     338        if (rc != EOK) {
     339                async_answer_0(call, rc);
     340                return;
     341        }
     342
     343        uint64_t blocknum =
    322344            (((uint64_t)(DEV_IPC_GET_ARG1(*call))) << 32) |
    323345            (((uint64_t)(DEV_IPC_GET_ARG2(*call))) & 0xffffffff);
    324         const size_t cnt = (size_t) DEV_IPC_GET_ARG3(*call);
    325 
    326         const errno_t ret = ahci_iface->write_blocks(fun, blocknum, cnt, buf);
    327 
    328         async_answer_0(call, ret);
     346        size_t cnt = (size_t) DEV_IPC_GET_ARG3(*call);
     347
     348        if (dsize != cnt * 512) {
     349                async_answer_0(call, EINVAL);
     350                return;
     351        }
     352
     353        rc = ahci_iface->write_blocks(fun, blocknum, cnt, data);
     354        free(data);
     355        async_answer_0(call, rc);
    329356}
    330357
Note: See TracChangeset for help on using the changeset viewer.