Coverage Report

Created: 2021-07-20 18:14

/libfido2/src/nfc_linux.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2020 Yubico AB. All rights reserved.
3
 * Use of this source code is governed by a BSD-style
4
 * license that can be found in the LICENSE file.
5
 */
6
7
#include <sys/types.h>
8
#include <sys/uio.h>
9
#include <sys/socket.h>
10
11
#include <linux/nfc.h>
12
13
#include <errno.h>
14
#include <libudev.h>
15
#include <signal.h>
16
#include <unistd.h>
17
18
#include "fido.h"
19
#include "fido/param.h"
20
#include "netlink.h"
21
#include "iso7816.h"
22
23
1.39k
#define TX_CHUNK_SIZE   240
24
25
static const uint8_t aid[] = { 0xa0, 0x00, 0x00, 0x06, 0x47, 0x2f, 0x00, 0x01 };
26
static const uint8_t v_u2f[] = { 'U', '2', 'F', '_', 'V', '2' };
27
static const uint8_t v_fido[] = { 'F', 'I', 'D', 'O', '_', '2', '_', '0' };
28
29
struct nfc_linux {
30
        int             fd;
31
        uint32_t        dev;
32
        uint32_t        target;
33
        sigset_t        sigmask;
34
        const sigset_t *sigmaskp;
35
        struct fido_nl *nl;
36
};
37
38
static int
39
tx_short_apdu(fido_dev_t *d, const iso7816_header_t *h, const uint8_t *payload,
40
    uint8_t payload_len, uint8_t cla_flags)
41
1.30k
{
42
1.30k
        uint8_t apdu[5 + UINT8_MAX + 1];
43
1.30k
        uint8_t sw[2];
44
1.30k
        size_t apdu_len;
45
1.30k
        int ok = -1;
46
1.30k
47
1.30k
        memset(&apdu, 0, sizeof(apdu));
48
1.30k
        apdu[0] = h->cla | cla_flags;
49
1.30k
        apdu[1] = h->ins;
50
1.30k
        apdu[2] = h->p1;
51
1.30k
        apdu[3] = h->p2;
52
1.30k
        apdu[4] = payload_len;
53
1.30k
        memcpy(&apdu[5], payload, payload_len);
54
1.30k
        apdu_len = (size_t)(5 + payload_len + 1);
55
1.30k
56
1.30k
        if (d->io.write(d->io_handle, apdu, apdu_len) < 0) {
57
20
                fido_log_debug("%s: write", __func__);
58
20
                goto fail;
59
20
        }
60
1.28k
61
1.28k
        if (cla_flags & 0x10) {
62
86
                if (d->io.read(d->io_handle, sw, sizeof(sw), -1) != 2) {
63
4
                        fido_log_debug("%s: read", __func__);
64
4
                        goto fail;
65
4
                }
66
82
                if ((sw[0] << 8 | sw[1]) != SW_NO_ERROR) {
67
77
                        fido_log_debug("%s: unexpected sw", __func__);
68
77
                        goto fail;
69
77
                }
70
1.20k
        }
71
1.20k
72
1.20k
        ok = 0;
73
1.30k
fail:
74
1.30k
        explicit_bzero(apdu, sizeof(apdu));
75
1.30k
76
1.30k
        return (ok);
77
1.20k
}
78
79
static int
80
nfc_do_tx(fido_dev_t *d, const uint8_t *apdu_ptr, size_t apdu_len)
81
1.29k
{
82
1.29k
        iso7816_header_t h;
83
1.29k
84
1.29k
        if (fido_buf_read(&apdu_ptr, &apdu_len, &h, sizeof(h)) < 0) {
85
0
                fido_log_debug("%s: header", __func__);
86
0
                return (-1);
87
0
        }
88
1.29k
        if (apdu_len < 2) {
89
0
                fido_log_debug("%s: apdu_len %zu", __func__, apdu_len);
90
0
                return (-1);
91
0
        }
92
1.29k
93
1.29k
        apdu_len -= 2; /* trim le1 le2 */
94
1.29k
95
1.30k
        while (apdu_len > TX_CHUNK_SIZE) {
96
86
                if (tx_short_apdu(d, &h, apdu_ptr, TX_CHUNK_SIZE, 0x10) < 0) {
97
81
                        fido_log_debug("%s: chain", __func__);
98
81
                        return (-1);
99
81
                }
100
5
                apdu_ptr += TX_CHUNK_SIZE;
101
5
                apdu_len -= TX_CHUNK_SIZE;
102
5
        }
103
1.29k
104
1.29k
        if (tx_short_apdu(d, &h, apdu_ptr, (uint8_t)apdu_len, 0) < 0) {
105
20
                fido_log_debug("%s: tx_short_apdu", __func__);
106
20
                return (-1);
107
20
        }
108
1.19k
 
109
1.19k
        return (0);
110
1.19k
}
111
112
int
113
fido_nfc_tx(fido_dev_t *d, uint8_t cmd, const unsigned char *buf, size_t count)
114
1.36k
{
115
1.36k
        iso7816_apdu_t *apdu = NULL;
116
1.36k
        const uint8_t *ptr;
117
1.36k
        size_t len;
118
1.36k
        int ok = -1;
119
1.36k
120
1.36k
        switch (cmd) {
121
622
        case CTAP_CMD_INIT: /* select */
122
622
                if ((apdu = iso7816_new(0, 0xa4, 0x04, sizeof(aid))) == NULL ||
123
622
                    iso7816_add(apdu, aid, sizeof(aid)) < 0) {
124
4
                        fido_log_debug("%s: iso7816", __func__);
125
4
                        goto fail;
126
4
                }
127
618
                break;
128
618
        case CTAP_CMD_CBOR: /* wrap cbor */
129
456
                if (count > UINT16_MAX || (apdu = iso7816_new(0x80, 0x10, 0x80,
130
453
                    (uint16_t)count)) == NULL ||
131
456
                    iso7816_add(apdu, buf, count) < 0) {
132
17
                        fido_log_debug("%s: iso7816", __func__);
133
17
                        goto fail;
134
17
                }
135
439
                break;
136
439
        case CTAP_CMD_MSG: /* already an apdu */
137
241
                break;
138
439
        default:
139
49
                fido_log_debug("%s: cmd=%02x", __func__, cmd);
140
49
                goto fail;
141
1.29k
        }
142
1.29k
143
1.29k
        if (apdu != NULL) {
144
1.05k
                ptr = iso7816_ptr(apdu);
145
1.05k
                len = iso7816_len(apdu);
146
1.05k
        } else {
147
241
                ptr = buf;
148
241
                len = count;
149
241
        }
150
1.29k
151
1.29k
        if (nfc_do_tx(d, ptr, len) < 0) {
152
101
                fido_log_debug("%s: nfc_do_tx", __func__);
153
101
                goto fail;
154
101
        }
155
1.19k
156
1.19k
        ok = 0;
157
1.36k
fail:
158
1.36k
        iso7816_free(&apdu);
159
1.36k
160
1.36k
        return (ok);
161
1.19k
}
162
163
static int
164
rx_init(fido_dev_t *d, unsigned char *buf, size_t count, int ms)
165
612
{
166
612
        fido_ctap_info_t *attr = (fido_ctap_info_t *)buf;
167
612
        uint8_t f[64];
168
612
        int n;
169
612
170
612
        if (count != sizeof(*attr)) {
171
0
                fido_log_debug("%s: count=%zu", __func__, count);
172
0
                return (-1);
173
0
        }
174
612
175
612
        memset(attr, 0, sizeof(*attr));
176
612
177
612
        if ((n = d->io.read(d->io_handle, f, sizeof(f), ms)) < 2 ||
178
612
            (f[n - 2] << 8 | f[n - 1]) != SW_NO_ERROR) {
179
199
                fido_log_debug("%s: read", __func__);
180
199
                return (-1);
181
199
        }
182
413
183
413
        n -= 2;
184
413
185
413
        if (n == sizeof(v_u2f) && memcmp(f, v_u2f, sizeof(v_u2f)) == 0)
186
0
                attr->flags = FIDO_CAP_CBOR;
187
413
        else if (n == sizeof(v_fido) && memcmp(f, v_fido, sizeof(v_fido)) == 0)
188
0
                attr->flags = FIDO_CAP_CBOR | FIDO_CAP_NMSG;
189
413
        else {
190
413
                fido_log_debug("%s: unknown version string", __func__);
191
413
#ifdef FIDO_FUZZ
192
413
                attr->flags = FIDO_CAP_CBOR | FIDO_CAP_NMSG;
193
#else
194
                return (-1);
195
#endif
196
413
        }
197
413
198
413
        memcpy(&attr->nonce, &d->nonce, sizeof(attr->nonce)); /* XXX */
199
413
200
413
        return ((int)count);
201
413
}
202
203
static int
204
tx_get_response(fido_dev_t *d, uint8_t count)
205
18
{
206
18
        uint8_t apdu[5];
207
18
208
18
        memset(apdu, 0, sizeof(apdu));
209
18
        apdu[1] = 0xc0; /* GET_RESPONSE */
210
18
        apdu[4] = count;
211
18
212
18
        if (d->io.write(d->io_handle, apdu, sizeof(apdu)) < 0) {
213
5
                fido_log_debug("%s: write", __func__);
214
5
                return (-1);
215
5
        }
216
13
217
13
        return (0);
218
13
}
219
220
static int
221
rx_apdu(fido_dev_t *d, uint8_t sw[2], unsigned char **buf, size_t *count, int ms)
222
593
{
223
593
        uint8_t f[256 + 2];
224
593
        int n, ok = -1;
225
593
226
593
        if ((n = d->io.read(d->io_handle, f, sizeof(f), ms)) < 2) {
227
291
                fido_log_debug("%s: read", __func__);
228
291
                goto fail;
229
291
        }
230
302
231
302
        if (fido_buf_write(buf, count, f, (size_t)(n - 2)) < 0) {
232
0
                fido_log_debug("%s: fido_buf_write", __func__);
233
0
                goto fail;
234
0
        }
235
302
236
302
        memcpy(sw, f + n - 2, 2);
237
302
238
302
        ok = 0;
239
593
fail:
240
593
        explicit_bzero(f, sizeof(f));
241
593
242
593
        return (ok);
243
302
}
244
245
static int
246
rx_msg(fido_dev_t *d, unsigned char *buf, size_t count, int ms)
247
580
{
248
580
        uint8_t sw[2];
249
580
        const size_t bufsiz = count;
250
580
251
580
        if (rx_apdu(d, sw, &buf, &count, ms) < 0) {
252
289
                fido_log_debug("%s: preamble", __func__);
253
289
                return (-1);
254
289
        }
255
291
256
302
        while (sw[0] == SW1_MORE_DATA)
257
291
                if (tx_get_response(d, sw[1]) < 0 ||
258
18
                    rx_apdu(d, sw, &buf, &count, ms) < 0) {
259
7
                        fido_log_debug("%s: chain", __func__);
260
7
                        return (-1);
261
7
                }
262
291
263
291
        if (fido_buf_write(&buf, &count, sw, sizeof(sw)) < 0) {
264
0
                fido_log_debug("%s: sw", __func__);
265
0
                return (-1);
266
0
        }
267
284
268
284
        if (bufsiz - count > INT_MAX) {
269
0
                fido_log_debug("%s: bufsiz", __func__);
270
0
                return (-1);
271
0
        }
272
284
273
284
        return ((int)(bufsiz - count));
274
284
}
275
276
static int
277
rx_cbor(fido_dev_t *d, unsigned char *buf, size_t count, int ms)
278
385
{
279
385
        int r;
280
385
281
385
        if ((r = rx_msg(d, buf, count, ms)) < 2)
282
171
                return (-1);
283
214
284
214
        return (r - 2);
285
214
}
286
287
int
288
fido_nfc_rx(fido_dev_t *d, uint8_t cmd, unsigned char *buf, size_t count, int ms)
289
1.19k
{
290
1.19k
        switch (cmd) {
291
612
        case CTAP_CMD_INIT:
292
612
                return (rx_init(d, buf, count, ms));
293
385
        case CTAP_CMD_CBOR:
294
385
                return (rx_cbor(d, buf, count, ms));
295
195
        case CTAP_CMD_MSG:
296
195
                return (rx_msg(d, buf, count, ms));
297
0
        default:
298
0
                fido_log_debug("%s: cmd=%02x", __func__, cmd);
299
0
                return (-1);
300
1.19k
        }
301
1.19k
}
302
303
static char *
304
get_parent_attr(struct udev_device *dev, const char *subsystem,
305
    const char *devtype, const char *attr)
306
36.0k
{
307
36.0k
        struct udev_device *parent;
308
36.0k
        const char *value;
309
36.0k
310
36.0k
        if ((parent = udev_device_get_parent_with_subsystem_devtype(dev,
311
36.0k
            subsystem, devtype)) == NULL || (value =
312
36.0k
            udev_device_get_sysattr_value(parent, attr)) == NULL)
313
36.0k
                return (NULL);
314
18.0k
315
18.0k
        return (strdup(value));
316
18.0k
}
317
318
static char *
319
get_usb_attr(struct udev_device *dev, const char *attr)
320
36.0k
{
321
36.0k
        return (get_parent_attr(dev, "usb", "usb_device", attr));
322
36.0k
}
323
324
static int
325
to_int(const char *str, int base)
326
0
{
327
0
        char *ep;
328
0
        long long ll;
329
0
330
0
        ll = strtoll(str, &ep, base);
331
0
        if (str == ep || *ep != '\0')
332
0
                return (-1);
333
0
        else if (ll == LLONG_MIN && errno == ERANGE)
334
0
                return (-1);
335
0
        else if (ll == LLONG_MAX && errno == ERANGE)
336
0
                return (-1);
337
0
        else if (ll < 0 || ll > INT_MAX)
338
0
                return (-1);
339
0
340
0
        return ((int)ll);
341
0
}
342
343
static int
344
copy_info(fido_dev_info_t *di, struct udev *udev,
345
    struct udev_list_entry *udev_entry)
346
9.23k
{
347
9.23k
        const char *name;
348
9.23k
        char *str;
349
9.23k
        struct udev_device *dev = NULL;
350
9.23k
        int id, ok = -1;
351
9.23k
352
9.23k
        memset(di, 0, sizeof(*di));
353
9.23k
354
9.23k
        if ((name = udev_list_entry_get_name(udev_entry)) == NULL ||
355
9.23k
            (dev = udev_device_new_from_syspath(udev, name)) == NULL)
356
9.23k
                goto fail;
357
9.17k
358
9.17k
        if ((di->path = strdup(name)) == NULL ||
359
9.17k
            (di->manufacturer = get_usb_attr(dev, "manufacturer")) == NULL ||
360
9.17k
            (di->product = get_usb_attr(dev, "product")) == NULL)
361
9.17k
                goto fail;
362
8.96k
363
8.96k
        /* XXX assumes USB for vendor/product info */
364
8.96k
        if ((str = get_usb_attr(dev, "idVendor")) != NULL &&
365
8.96k
            (id = to_int(str, 16)) > 0 && id <= UINT16_MAX)
366
8.96k
                di->vendor_id = (int16_t)id;
367
8.96k
        free(str);
368
8.96k
369
8.96k
        if ((str = get_usb_attr(dev, "idProduct")) != NULL &&
370
8.96k
            (id = to_int(str, 16)) > 0 && id <= UINT16_MAX)
371
8.96k
                di->product_id = (int16_t)id;
372
8.96k
        free(str);
373
8.96k
374
8.96k
        ok = 0;
375
9.23k
fail:
376
9.23k
        if (dev != NULL)
377
9.23k
                udev_device_unref(dev);
378
9.23k
379
9.23k
        if (ok < 0) {
380
273
                free(di->path);
381
273
                free(di->manufacturer);
382
273
                free(di->product);
383
273
                explicit_bzero(di, sizeof(*di));
384
273
        }
385
9.23k
386
9.23k
        return (ok);
387
8.96k
}
388
389
static int
390
sysnum_from_syspath(const char *path)
391
0
{
392
0
        struct udev *udev = NULL;
393
0
        struct udev_device *dev = NULL;
394
0
        const char *str;
395
0
        int idx;
396
0
397
0
        if ((udev = udev_new()) == NULL ||
398
0
            (dev = udev_device_new_from_syspath(udev, path)) == NULL ||
399
0
            (str = udev_device_get_sysnum(dev)) == NULL)
400
0
                idx = -1;
401
0
        else
402
0
                idx = to_int(str, 10);
403
0
404
0
        if (dev != NULL)
405
0
                udev_device_unref(dev);
406
0
        if (udev != NULL)
407
0
                udev_unref(udev);
408
0
409
0
        return (idx);
410
0
}
411
412
int
413
fido_nfc_manifest(fido_dev_info_t *devlist, size_t ilen, size_t *olen)
414
365
{
415
365
        struct udev *udev = NULL;
416
365
        struct udev_enumerate *udev_enum = NULL;
417
365
        struct udev_list_entry *udev_list;
418
365
        struct udev_list_entry *udev_entry;
419
365
        int r = FIDO_ERR_INTERNAL;
420
365
421
365
        *olen = 0;
422
365
423
365
        if (ilen == 0)
424
4
                return (FIDO_OK);
425
361
426
361
        if (devlist == NULL)
427
361
                return (FIDO_ERR_INVALID_ARGUMENT);
428
361
429
361
        if ((udev = udev_new()) == NULL ||
430
361
            (udev_enum = udev_enumerate_new(udev)) == NULL)
431
361
                goto fail;
432
359
433
359
        if (udev_enumerate_add_match_subsystem(udev_enum, "nfc") < 0 ||
434
359
            udev_enumerate_scan_devices(udev_enum) < 0)
435
2
                goto fail;
436
357
437
357
        if ((udev_list = udev_enumerate_get_list_entry(udev_enum)) == NULL) {
438
13
                r = FIDO_OK; /* zero nfc devices */
439
13
                goto fail;
440
13
        }
441
344
442
9.23k
        udev_list_entry_foreach(udev_entry, udev_list) {
443
9.23k
                if (copy_info(&devlist[*olen], udev, udev_entry) == 0) {
444
8.96k
                        devlist[*olen].io = (fido_dev_io_t) {
445
8.96k
                                fido_nfc_open,
446
8.96k
                                fido_nfc_close,
447
8.96k
                                fido_nfc_read,
448
8.96k
                                fido_nfc_write,
449
8.96k
                        };
450
8.96k
                        devlist[*olen].transport = (fido_dev_transport_t) {
451
8.96k
                                fido_nfc_rx,
452
8.96k
                                fido_nfc_tx,
453
8.96k
                        };
454
8.96k
                        if (++(*olen) == ilen)
455
120
                                break;
456
8.96k
                }
457
9.23k
        }
458
344
459
344
        r = FIDO_OK;
460
361
fail:
461
361
        if (udev_enum != NULL)
462
361
                udev_enumerate_unref(udev_enum);
463
361
        if (udev != NULL)
464
361
                udev_unref(udev);
465
361
466
361
        return (r);
467
344
}
468
469
static int
470
nfc_target_connect(struct nfc_linux *ctx)
471
0
{
472
0
        struct sockaddr_nfc sa;
473
0
474
0
        memset(&sa, 0, sizeof(sa));
475
0
        sa.sa_family = AF_NFC;
476
0
        sa.dev_idx = ctx->dev;
477
0
        sa.target_idx = ctx->target;
478
0
        sa.nfc_protocol = NFC_PROTO_ISO14443;
479
0
480
0
        if ((ctx->fd = socket(AF_NFC, SOCK_SEQPACKET | SOCK_CLOEXEC,
481
0
            NFC_SOCKPROTO_RAW)) == -1) {
482
0
                fido_log_error(errno, "%s: socket", __func__);
483
0
                return (-1);
484
0
        }
485
0
        if (connect(ctx->fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
486
0
                fido_log_error(errno, "%s: connect", __func__);
487
0
                if (close(ctx->fd) == -1)
488
0
                        fido_log_error(errno, "%s: close", __func__);
489
0
                ctx->fd = -1;
490
0
                return (-1);
491
0
        }
492
0
493
0
        return (0);
494
0
}
495
496
static void
497
nfc_free(struct nfc_linux **ctx_p)
498
0
{
499
0
        struct nfc_linux *ctx;
500
0
501
0
        if (ctx_p == NULL || (ctx = *ctx_p) == NULL)
502
0
                return;
503
0
        if (ctx->fd != -1 && close(ctx->fd) == -1)
504
0
                fido_log_error(errno, "%s: close", __func__);
505
0
        if (ctx->nl != NULL)
506
0
                fido_nl_free(&ctx->nl);
507
0
508
0
        free(ctx);
509
0
        *ctx_p = NULL;
510
0
}
511
512
static struct nfc_linux *
513
nfc_new(uint32_t dev)
514
0
{
515
0
        struct nfc_linux *ctx;
516
0
517
0
        if ((ctx = calloc(1, sizeof(*ctx))) == NULL ||
518
0
            (ctx->nl = fido_nl_new()) == NULL) {
519
0
                nfc_free(&ctx);
520
0
                return (NULL);
521
0
        }
522
0
523
0
        ctx->fd = -1;
524
0
        ctx->dev = dev;
525
0
526
0
        return (ctx);
527
0
}
528
529
void *
530
fido_nfc_open(const char *path)
531
0
{
532
0
        struct nfc_linux *ctx = NULL;
533
0
        int idx;
534
0
535
0
        if ((idx = sysnum_from_syspath(path)) < 0 ||
536
0
            (ctx = nfc_new((uint32_t)idx)) == NULL) {
537
0
                fido_log_debug("%s: nfc_new", __func__);
538
0
                goto fail;
539
0
        }
540
0
        if (fido_nl_power_nfc(ctx->nl, ctx->dev) < 0 ||
541
0
            fido_nl_get_nfc_target(ctx->nl, ctx->dev, &ctx->target) < 0 ||
542
0
            nfc_target_connect(ctx) < 0) {
543
0
                fido_log_debug("%s: netlink", __func__);
544
0
                goto fail;
545
0
        }
546
0
547
0
        return (ctx);
548
0
fail:
549
0
        nfc_free(&ctx);
550
0
        return (NULL);
551
0
}
552
553
void
554
fido_nfc_close(void *handle)
555
0
{
556
0
        struct nfc_linux *ctx = handle;
557
0
558
0
        nfc_free(&ctx);
559
0
}
560
561
int
562
fido_nfc_set_sigmask(void *handle, const fido_sigset_t *sigmask)
563
0
{
564
0
        struct nfc_linux *ctx = handle;
565
0
566
0
        ctx->sigmask = *sigmask;
567
0
        ctx->sigmaskp = &ctx->sigmask;
568
0
569
0
        return (FIDO_OK);
570
0
}
571
572
int
573
fido_nfc_read(void *handle, unsigned char *buf, size_t len, int ms)
574
0
{
575
0
        struct nfc_linux *ctx = handle;
576
0
        struct iovec iov[2];
577
0
        uint8_t preamble;
578
0
        ssize_t r;
579
0
580
0
        memset(&iov, 0, sizeof(iov));
581
0
        iov[0].iov_base = &preamble;
582
0
        iov[0].iov_len = sizeof(preamble);
583
0
        iov[1].iov_base = buf;
584
0
        iov[1].iov_len = len;
585
0
586
0
        if (fido_hid_unix_wait(ctx->fd, ms, ctx->sigmaskp) < 0) {
587
0
                fido_log_debug("%s: fido_hid_unix_wait", __func__);
588
0
                return (-1);
589
0
        }
590
0
        if ((r = readv(ctx->fd, iov, nitems(iov))) == -1) {
591
0
                fido_log_error(errno, "%s: read", __func__);
592
0
                return (-1);
593
0
        }
594
0
        if (r < 1) {
595
0
                fido_log_debug("%s: %zd < 1", __func__, r);
596
0
                return (-1);
597
0
        }
598
0
        if (preamble != 0x00) {
599
0
                fido_log_debug("%s: preamble", __func__);
600
0
                return (-1);
601
0
        }
602
0
603
0
        r--;
604
0
        fido_log_xxd(buf, (size_t)r, "%s", __func__);
605
0
606
0
        return ((int)r);
607
0
}
608
609
int
610
fido_nfc_write(void *handle, const unsigned char *buf, size_t len)
611
0
{
612
0
        struct nfc_linux *ctx = handle;
613
0
        ssize_t r;
614
0
615
0
        fido_log_xxd(buf, len, "%s", __func__);
616
0
617
0
        if (len > INT_MAX) {
618
0
                fido_log_debug("%s: len", __func__);
619
0
                return (-1);
620
0
        }
621
0
        if ((r = write(ctx->fd, buf, len)) == -1) {
622
0
                fido_log_error(errno, "%s: write", __func__);
623
0
                return (-1);
624
0
        }
625
0
        if (r < 0 || (size_t)r != len) {
626
0
                fido_log_debug("%s: %zd != %zu", __func__, r, len);
627
0
                return (-1);
628
0
        }
629
0
630
0
        return ((int)r);
631
0
}