~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to hw/virtio/virtio-rng.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2014-01-27 09:10:37 UTC
  • Revision ID: package-import@ubuntu.com-20140127091037-qf1lsx2iau13d3sk
Tags: 1.7.0+dfsg-2ubuntu8
* SECURITY UPDATE: denial of service via virtio device hot-plugging
  - debian/patches/CVE-2013-4377.patch: upstream commits to refactor
    virtio device unplugging.
  - CVE-2013-4377

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
                   qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + vrng->conf.period_ms);
134
134
}
135
135
 
136
 
static int virtio_rng_device_init(VirtIODevice *vdev)
 
136
static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
137
137
{
138
 
    DeviceState *qdev = DEVICE(vdev);
139
 
    VirtIORNG *vrng = VIRTIO_RNG(vdev);
 
138
    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 
139
    VirtIORNG *vrng = VIRTIO_RNG(dev);
140
140
    Error *local_err = NULL;
141
141
 
142
142
    if (!vrng->conf.period_ms > 0) {
143
 
        qerror_report(QERR_INVALID_PARAMETER_VALUE, "period",
144
 
                      "a positive number");
145
 
        return -1;
 
143
        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "period",
 
144
                  "a positive number");
 
145
        return;
146
146
    }
147
147
 
148
148
    if (vrng->conf.rng == NULL) {
149
149
        vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
150
150
 
151
 
        object_property_add_child(OBJECT(qdev),
 
151
        object_property_add_child(OBJECT(dev),
152
152
                                  "default-backend",
153
153
                                  OBJECT(vrng->conf.default_backend),
154
154
                                  NULL);
155
155
 
156
 
        object_property_set_link(OBJECT(qdev),
 
156
        object_property_set_link(OBJECT(dev),
157
157
                                 OBJECT(vrng->conf.default_backend),
158
158
                                 "rng", NULL);
159
159
    }
162
162
 
163
163
    vrng->rng = vrng->conf.rng;
164
164
    if (vrng->rng == NULL) {
165
 
        qerror_report(QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
166
 
        return -1;
 
165
        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
 
166
        return;
167
167
    }
168
168
 
169
169
    rng_backend_open(vrng->rng, &local_err);
170
170
    if (local_err) {
171
 
        qerror_report_err(local_err);
172
 
        error_free(local_err);
173
 
        return -1;
 
171
        error_propagate(errp, local_err);
 
172
        return;
174
173
    }
175
174
 
176
175
    vrng->vq = virtio_add_queue(vdev, 8, handle_input);
184
183
    timer_mod(vrng->rate_limit_timer,
185
184
                   qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + vrng->conf.period_ms);
186
185
 
187
 
    register_savevm(qdev, "virtio-rng", -1, 1, virtio_rng_save,
 
186
    register_savevm(dev, "virtio-rng", -1, 1, virtio_rng_save,
188
187
                    virtio_rng_load, vrng);
189
 
 
190
 
    return 0;
191
188
}
192
189
 
193
 
static int virtio_rng_device_exit(DeviceState *qdev)
 
190
static void virtio_rng_device_unrealize(DeviceState *dev, Error **errp)
194
191
{
195
 
    VirtIORNG *vrng = VIRTIO_RNG(qdev);
196
 
    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
 
192
    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 
193
    VirtIORNG *vrng = VIRTIO_RNG(dev);
197
194
 
198
195
    timer_del(vrng->rate_limit_timer);
199
196
    timer_free(vrng->rate_limit_timer);
200
 
    unregister_savevm(qdev, "virtio-rng", vrng);
 
197
    unregister_savevm(dev, "virtio-rng", vrng);
201
198
    virtio_cleanup(vdev);
202
 
    return 0;
203
199
}
204
200
 
205
201
static Property virtio_rng_properties[] = {
211
207
{
212
208
    DeviceClass *dc = DEVICE_CLASS(klass);
213
209
    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
214
 
    dc->exit = virtio_rng_device_exit;
 
210
 
215
211
    dc->props = virtio_rng_properties;
216
212
    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
217
 
    vdc->init = virtio_rng_device_init;
 
213
    vdc->realize = virtio_rng_device_realize;
 
214
    vdc->unrealize = virtio_rng_device_unrealize;
218
215
    vdc->get_features = get_features;
219
216
}
220
217