From: Dan Carpenter <dan.carpenter@oracle.com>
To: eric.lapuyade@linux.intel.com
Cc: linux-wireless@vger.kernel.org, linux-nfc@ml01.01.org,
Johannes Berg <johannes@sipsolutions.net>
Subject: re: NFC: Initial support for Inside Secure microread
Date: Mon, 20 Jan 2014 17:29:52 +0300 [thread overview]
Message-ID: <20140120142952.GB4954@elgon.mountain> (raw)
Hello Eric Lapuyade,
The patch cfad1ba87150: "NFC: Initial support for Inside Secure
microread" from Dec 18, 2012, leads to the following
Sparse warning:
drivers/nfc/microread/microread.c:534:25:
warning: cast to restricted __le16"
drivers/nfc/microread/microread.c
512 case MICROREAD_GATE_ID_MREAD_ISO_A_3:
513 targets->supported_protocols =
514 nfc_hci_sak_to_protocol(skb->data[MICROREAD_EMCF_A3_SAK]);
515 targets->sens_res =
516 be16_to_cpu(*(u16 *)&skb->data[MICROREAD_EMCF_A3_ATQA]);
^^^^^^^^^^^
sens_res is network (big) endian here. We could silence the sparse
warning by doing:
argets->sens_res =
ntohs(*(__be16 *)&skb->data[MICROREAD_EMCF_A3_ATQA]);
517 targets->sel_res = skb->data[MICROREAD_EMCF_A3_SAK];
518 targets->nfcid1_len = skb->data[MICROREAD_EMCF_A3_LEN];
519 if (targets->nfcid1_len > sizeof(targets->nfcid1)) {
520 r = -EINVAL;
521 goto exit_free;
522 }
523 memcpy(targets->nfcid1, &skb->data[MICROREAD_EMCF_A3_UID],
524 targets->nfcid1_len);
525 break;
526 case MICROREAD_GATE_ID_MREAD_ISO_B:
527 targets->supported_protocols = NFC_PROTO_ISO14443_B_MASK;
528 memcpy(targets->nfcid1, &skb->data[MICROREAD_EMCF_B_UID], 4);
529 targets->nfcid1_len = 4;
530 break;
531 case MICROREAD_GATE_ID_MREAD_NFC_T1:
532 targets->supported_protocols = NFC_PROTO_JEWEL_MASK;
533 targets->sens_res =
534 le16_to_cpu(*(u16 *)&skb->data[MICROREAD_EMCF_T1_ATQA]);
^^^^^^^^^^^
But here it is little endian. This seems like either a horrible
protocol or a bug in the code.
535 memcpy(targets->nfcid1, &skb->data[MICROREAD_EMCF_T1_UID], 4);
536 targets->nfcid1_len = 4;
537 break;
Btw, we also don't seem to check if we are reading beyond the end of
skb->len. This would only be a problem if we got unlucky and skb->data
were allocated at the end of page. The read beyond the end of the page
would cause an oops.
regards,
dan carpenter
next reply other threads:[~2014-01-20 14:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-20 14:29 Dan Carpenter [this message]
2014-01-20 18:03 ` NFC: Initial support for Inside Secure microread Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140120142952.GB4954@elgon.mountain \
--to=dan.carpenter@oracle.com \
--cc=eric.lapuyade@linux.intel.com \
--cc=johannes@sipsolutions.net \
--cc=linux-nfc@ml01.01.org \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox