Changeset 21ff054 in mainline


Ignore:
Timestamp:
2018-05-22T19:06:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5f03107
Parents:
4e2d387
git-author:
Jakub Jermar <jakub@…> (2018-04-25 19:17:47)
git-committer:
Jakub Jermar <jakub@…> (2018-05-22 19:06:50)
Message:

Make sure the PCI capability is big enough

Location:
uspace/lib/virtio
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/virtio/virtio-pci.c

    r4e2d387 r21ff054  
    180180         */
    181181        uint8_t c;
    182         uint8_t id;
    183         for (rc = pci_config_space_cap_first(pci_sess, &c, &id);
     182        uint8_t cap_vndr;
     183        for (rc = pci_config_space_cap_first(pci_sess, &c, &cap_vndr);
    184184            (rc == EOK) && c;
    185             rc = pci_config_space_cap_next(pci_sess, &c, &id)) {
    186                 if (id != PCI_CAP_VENDORSPECID)
     185            rc = pci_config_space_cap_next(pci_sess, &c, &cap_vndr)) {
     186                if (cap_vndr != PCI_CAP_VENDORSPECID)
    187187                        continue;
    188188
    189                 uint8_t type;
    190                 rc = pci_config_space_read_8(pci_sess, VIRTIO_PCI_CAP_TYPE(c),
    191                     &type);
     189                uint8_t cap_len;
     190                rc = pci_config_space_read_8(pci_sess,
     191                    VIRTIO_PCI_CAP_CAP_LEN(c), &cap_len);
     192                if (rc != EOK)
     193                        goto error;
     194
     195                if (cap_len < VIRTIO_PCI_CAP_END(0)) {
     196                        rc = EINVAL;
     197                        goto error;
     198                }
     199
     200                uint8_t cfg_type;
     201                rc = pci_config_space_read_8(pci_sess,
     202                    VIRTIO_PCI_CAP_CFG_TYPE(c), &cfg_type);
    192203                if (rc != EOK)
    193204                        goto error;
     
    212223
    213224                uint32_t multiplier;
    214                 switch (type) {
     225                switch (cfg_type) {
    215226                case VIRTIO_PCI_CAP_COMMON_CFG:
    216227                        virtio_pci_common_cfg(vdev, bar, offset, length);
    217228                        break;
    218229                case VIRTIO_PCI_CAP_NOTIFY_CFG:
     230                        if (cap_len < VIRTIO_PCI_CAP_END(sizeof(uint32_t))) {
     231                                rc = EINVAL;
     232                                goto error;
     233                        }
    219234                        rc = pci_config_space_read_32(pci_sess,
    220235                            VIRTIO_PCI_CAP_END(c), &multiplier);
  • uspace/lib/virtio/virtio-pci.h

    r4e2d387 r21ff054  
    3737#include <ddi.h>
    3838
    39 #define VIRTIO_PCI_CAP_TYPE(c)          ((c) + 3)
     39#define VIRTIO_PCI_CAP_CAP_LEN(c)       ((c) + 2)
     40#define VIRTIO_PCI_CAP_CFG_TYPE(c)      ((c) + 3)
    4041#define VIRTIO_PCI_CAP_BAR(c)           ((c) + 4)
    4142#define VIRTIO_PCI_CAP_OFFSET(c)        ((c) + 8)
Note: See TracChangeset for help on using the changeset viewer.