1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
permissions: 0.984
debug: 0.978
other: 0.963
assembly: 0.958
performance: 0.952
PID: 0.950
semantic: 0.950
architecture: 0.946
arm: 0.946
register: 0.934
device: 0.932
boot: 0.929
socket: 0.927
vnc: 0.926
risc-v: 0.926
graphic: 0.924
files: 0.910
network: 0.879
TCG: 0.868
x86: 0.782
mistranslation: 0.770
kernel virtual machine: 0.738
[Qemu-devel] [BUG] 216 Alerts reported by LGTM for QEMU (some might be release critical)
Hi,
LGTM reports 16 errors, 81 warnings and 119 recommendations:
https://lgtm.com/projects/g/qemu/qemu/alerts/?mode=list
.
Some of them are already know (wrong format strings), others look like
real errors:
- several multiplication results which don't work as they should in
contrib/vhost-user-gpu, block/* (m->nb_clusters * s->cluster_size only
32 bit!), target/i386/translate.c and other files
- potential buffer overflows in gdbstub.c and other files
I am afraid that the overflows in the block code are release critical,
maybe that in target/i386/translate.c and other errors, too.
About half of the alerts are issues which can be fixed later.
Regards
Stefan
On 13/07/19 19:46, Stefan Weil wrote:
>
>
LGTM reports 16 errors, 81 warnings and 119 recommendations:
>
https://lgtm.com/projects/g/qemu/qemu/alerts/?mode=list
.
>
>
Some of them are already know (wrong format strings), others look like
>
real errors:
>
>
- several multiplication results which don't work as they should in
>
contrib/vhost-user-gpu, block/* (m->nb_clusters * s->cluster_size only
>
32 bit!), target/i386/translate.c and other files
m->nb_clusters here is limited by s->l2_slice_size (see for example
handle_alloc) so I wouldn't be surprised if this is a false positive. I
couldn't find this particular multiplication in Coverity, but it has
about 250 issues marked as intentional or false positive so there's
probably a lot of overlap with what LGTM found.
Paolo
Am 13.07.2019 um 21:42 schrieb Paolo Bonzini:
>
On 13/07/19 19:46, Stefan Weil wrote:
>
> LGTM reports 16 errors, 81 warnings and 119 recommendations:
>
>
https://lgtm.com/projects/g/qemu/qemu/alerts/?mode=list
.
>
>
>
> Some of them are already known (wrong format strings), others look like
>
> real errors:
>
>
>
> - several multiplication results which don't work as they should in
>
> contrib/vhost-user-gpu, block/* (m->nb_clusters * s->cluster_size only
>
> 32 bit!), target/i386/translate.c and other files
>
m->nb_clusters here is limited by s->l2_slice_size (see for example
>
handle_alloc) so I wouldn't be surprised if this is a false positive. I
>
couldn't find this particular multiplication in Coverity, but it has
>
about 250 issues marked as intentional or false positive so there's
>
probably a lot of overlap with what LGTM found.
>
>
Paolo
>
From other projects I know that there is a certain overlap between the
results from Coverity Scan an LGTM, but it is good to have both
analyzers, and the results from LGTM are typically quite reliable.
Even if we know that there is no multiplication overflow, the code could
be modified. Either the assigned value should use the same data type as
the factors (possible when there is never an overflow, avoids a size
extension), or the multiplication could use the larger data type by
adding a type cast to one of the factors (then an overflow cannot
happen, static code analysers and human reviewers have an easier job,
but the multiplication costs more time).
Stefan
Am 14.07.2019 um 15:28 hat Stefan Weil geschrieben:
>
Am 13.07.2019 um 21:42 schrieb Paolo Bonzini:
>
> On 13/07/19 19:46, Stefan Weil wrote:
>
>> LGTM reports 16 errors, 81 warnings and 119 recommendations:
>
>>
https://lgtm.com/projects/g/qemu/qemu/alerts/?mode=list
.
>
>>
>
>> Some of them are already known (wrong format strings), others look like
>
>> real errors:
>
>>
>
>> - several multiplication results which don't work as they should in
>
>> contrib/vhost-user-gpu, block/* (m->nb_clusters * s->cluster_size only
>
>> 32 bit!), target/i386/translate.c and other files
Request sizes are limited to 32 bit in the generic block layer before
they are even passed to the individual block drivers, so most if not all
of these are going to be false positives.
>
> m->nb_clusters here is limited by s->l2_slice_size (see for example
>
> handle_alloc) so I wouldn't be surprised if this is a false positive. I
>
> couldn't find this particular multiplication in Coverity, but it has
>
> about 250 issues marked as intentional or false positive so there's
>
> probably a lot of overlap with what LGTM found.
>
>
>
> Paolo
>
>
From other projects I know that there is a certain overlap between the
>
results from Coverity Scan an LGTM, but it is good to have both
>
analyzers, and the results from LGTM are typically quite reliable.
>
>
Even if we know that there is no multiplication overflow, the code could
>
be modified. Either the assigned value should use the same data type as
>
the factors (possible when there is never an overflow, avoids a size
>
extension), or the multiplication could use the larger data type by
>
adding a type cast to one of the factors (then an overflow cannot
>
happen, static code analysers and human reviewers have an easier job,
>
but the multiplication costs more time).
But if you look at the code we're talking about, you see that it's
complaining about things where being more explicit would make things
less readable.
For example, if complains about the multiplication in this line:
s->file_size += n * s->header.cluster_size;
We know that n * s->header.cluster_size fits in 32 bits, but
s->file_size is 64 bits (and has to be 64 bits). Do you really think we
should introduce another uint32_t variable to store the intermediate
result? And if we cast n to uint64_t, not only might the multiplication
cost more time, but also human readers would wonder why the result could
become larger than 32 bits. So a cast would be misleading.
It also complains about this line:
ret = bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size,
PREALLOC_MODE_OFF, &local_err);
Here, we don't even assign the result to a 64 bit variable, but just
pass it to a function which takes a 64 bit parameter. Again, I don't
think introducing additional variables for the intermediate result or
adding casts would be an improvement of the situation.
So I don't think this is a good enough tool to base our code on what it
does and doesn't understand. It would have too much of a negative impact
on our code. We'd rather need a way to mark false positives as such and
move on without changing the code in such cases.
Kevin
On Sat, 13 Jul 2019 at 18:46, Stefan Weil <address@hidden> wrote:
>
LGTM reports 16 errors, 81 warnings and 119 recommendations:
>
https://lgtm.com/projects/g/qemu/qemu/alerts/?mode=list
.
I had a look at some of these before, but mostly I came
to the conclusion that it wasn't worth trying to put the
effort into keeping up with the site because they didn't
seem to provide any useful way to mark things as false
positives. Coverity has its flaws but at least you can do
that kind of thing in its UI (it runs at about a 33% fp
rate, I think.) "Analyzer thinks this multiply can overflow
but in fact it's not possible" is quite a common false
positive cause...
Anyway, if you want to fish out specific issues, analyse
whether they're false positive or real, and report them
to the mailing list as followups to the patches which
introduced the issue, that's probably the best way for
us to make use of this analyzer. (That is essentially
what I do for coverity.)
thanks
-- PMM
Am 14.07.2019 um 19:30 schrieb Peter Maydell:
[...]
>
"Analyzer thinks this multiply can overflow
>
but in fact it's not possible" is quite a common false
>
positive cause...
The analysers don't complain because a multiply can overflow.
They complain because the code indicates that a larger result is
expected, for example uint64_t = uint32_t * uint32_t. They would not
complain for the same multiplication if it were assigned to a uint32_t.
So there is a simple solution to write the code in a way which avoids
false positives...
Stefan
Stefan Weil <address@hidden> writes:
>
Am 14.07.2019 um 19:30 schrieb Peter Maydell:
>
[...]
>
> "Analyzer thinks this multiply can overflow
>
> but in fact it's not possible" is quite a common false
>
> positive cause...
>
>
>
The analysers don't complain because a multiply can overflow.
>
>
They complain because the code indicates that a larger result is
>
expected, for example uint64_t = uint32_t * uint32_t. They would not
>
complain for the same multiplication if it were assigned to a uint32_t.
I agree this is an anti-pattern.
>
So there is a simple solution to write the code in a way which avoids
>
false positives...
You wrote elsewhere in this thread:
Either the assigned value should use the same data type as the
factors (possible when there is never an overflow, avoids a size
extension), or the multiplication could use the larger data type by
adding a type cast to one of the factors (then an overflow cannot
happen, static code analysers and human reviewers have an easier
job, but the multiplication costs more time).
Makes sense to me.
On 7/14/19 5:30 PM, Peter Maydell wrote:
>
I had a look at some of these before, but mostly I came
>
to the conclusion that it wasn't worth trying to put the
>
effort into keeping up with the site because they didn't
>
seem to provide any useful way to mark things as false
>
positives. Coverity has its flaws but at least you can do
>
that kind of thing in its UI (it runs at about a 33% fp
>
rate, I think.)
Yes, LGTM wants you to modify the source code with
/* lgtm [cpp/some-warning-code] */
and on the same line as the reported problem. Which is mildly annoying in that
you're definitely committing to LGTM in the long term. Also for any
non-trivial bit of code, it will almost certainly run over 80 columns.
r~
|