Skip to content

Commit 7fe8e48

Browse files
tiwaiherbertx
authored andcommitted
crypto: bcm - Use scnprintf() for avoiding potential buffer overflow
Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf(). Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 2638268 commit 7fe8e48

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

drivers/crypto/bcm/util.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -366,96 +366,96 @@ static ssize_t spu_debugfs_read(struct file *filp, char __user *ubuf,
366366

367367
ipriv = filp->private_data;
368368
out_offset = 0;
369-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
369+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
370370
"Number of SPUs.........%u\n",
371371
ipriv->spu.num_spu);
372-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
372+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
373373
"Current sessions.......%u\n",
374374
atomic_read(&ipriv->session_count));
375-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
375+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
376376
"Session count..........%u\n",
377377
atomic_read(&ipriv->stream_count));
378-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
378+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
379379
"Cipher setkey..........%u\n",
380380
atomic_read(&ipriv->setkey_cnt[SPU_OP_CIPHER]));
381-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
381+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
382382
"Cipher Ops.............%u\n",
383383
atomic_read(&ipriv->op_counts[SPU_OP_CIPHER]));
384384
for (alg = 0; alg < CIPHER_ALG_LAST; alg++) {
385385
for (mode = 0; mode < CIPHER_MODE_LAST; mode++) {
386386
op_cnt = atomic_read(&ipriv->cipher_cnt[alg][mode]);
387387
if (op_cnt) {
388-
out_offset += snprintf(buf + out_offset,
388+
out_offset += scnprintf(buf + out_offset,
389389
out_count - out_offset,
390390
" %-13s%11u\n",
391391
spu_alg_name(alg, mode), op_cnt);
392392
}
393393
}
394394
}
395-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
395+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
396396
"Hash Ops...............%u\n",
397397
atomic_read(&ipriv->op_counts[SPU_OP_HASH]));
398398
for (alg = 0; alg < HASH_ALG_LAST; alg++) {
399399
op_cnt = atomic_read(&ipriv->hash_cnt[alg]);
400400
if (op_cnt) {
401-
out_offset += snprintf(buf + out_offset,
401+
out_offset += scnprintf(buf + out_offset,
402402
out_count - out_offset,
403403
" %-13s%11u\n",
404404
hash_alg_name[alg], op_cnt);
405405
}
406406
}
407-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
407+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
408408
"HMAC setkey............%u\n",
409409
atomic_read(&ipriv->setkey_cnt[SPU_OP_HMAC]));
410-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
410+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
411411
"HMAC Ops...............%u\n",
412412
atomic_read(&ipriv->op_counts[SPU_OP_HMAC]));
413413
for (alg = 0; alg < HASH_ALG_LAST; alg++) {
414414
op_cnt = atomic_read(&ipriv->hmac_cnt[alg]);
415415
if (op_cnt) {
416-
out_offset += snprintf(buf + out_offset,
416+
out_offset += scnprintf(buf + out_offset,
417417
out_count - out_offset,
418418
" %-13s%11u\n",
419419
hash_alg_name[alg], op_cnt);
420420
}
421421
}
422-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
422+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
423423
"AEAD setkey............%u\n",
424424
atomic_read(&ipriv->setkey_cnt[SPU_OP_AEAD]));
425425

426-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
426+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
427427
"AEAD Ops...............%u\n",
428428
atomic_read(&ipriv->op_counts[SPU_OP_AEAD]));
429429
for (alg = 0; alg < AEAD_TYPE_LAST; alg++) {
430430
op_cnt = atomic_read(&ipriv->aead_cnt[alg]);
431431
if (op_cnt) {
432-
out_offset += snprintf(buf + out_offset,
432+
out_offset += scnprintf(buf + out_offset,
433433
out_count - out_offset,
434434
" %-13s%11u\n",
435435
aead_alg_name[alg], op_cnt);
436436
}
437437
}
438-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
438+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
439439
"Bytes of req data......%llu\n",
440440
(u64)atomic64_read(&ipriv->bytes_out));
441-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
441+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
442442
"Bytes of resp data.....%llu\n",
443443
(u64)atomic64_read(&ipriv->bytes_in));
444-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
444+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
445445
"Mailbox full...........%u\n",
446446
atomic_read(&ipriv->mb_no_spc));
447-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
447+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
448448
"Mailbox send failures..%u\n",
449449
atomic_read(&ipriv->mb_send_fail));
450-
out_offset += snprintf(buf + out_offset, out_count - out_offset,
450+
out_offset += scnprintf(buf + out_offset, out_count - out_offset,
451451
"Check ICV errors.......%u\n",
452452
atomic_read(&ipriv->bad_icv));
453453
if (ipriv->spu.spu_type == SPU_TYPE_SPUM)
454454
for (i = 0; i < ipriv->spu.num_spu; i++) {
455455
spu_ofifo_ctrl = ioread32(ipriv->spu.reg_vbase[i] +
456456
SPU_OFIFO_CTRL);
457457
fifo_len = spu_ofifo_ctrl & SPU_FIFO_WATERMARK;
458-
out_offset += snprintf(buf + out_offset,
458+
out_offset += scnprintf(buf + out_offset,
459459
out_count - out_offset,
460460
"SPU %d output FIFO high water.....%u\n",
461461
i, fifo_len);

0 commit comments

Comments
 (0)