Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: lustre: ko2iblnd: check copy_from_iter/copy_to_iter return code

We now get a helpful warning for code that calls copy_{from,to}_iter
without checking the return value, introduced by commit aa28de275a24
("iov_iter/hardening: move object size checks to inlined part").

drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c: In function 'kiblnd_send':
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c:1643:2: error: ignoring return value of 'copy_from_iter', declared with attribute warn_unused_result [-Werror=unused-result]
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c: In function 'kiblnd_recv':
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c:1744:3: error: ignoring return value of 'copy_to_iter', declared with attribute warn_unused_result [-Werror=unused-result]

In case we get short copies here, we may get incorrect behavior.
I've added failure handling for both rx and tx now, returning
-EFAULT as expected.

Cc: stable@vger.kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: James Simmons <jsimmons@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Arnd Bergmann and committed by
Greg Kroah-Hartman
566e1ce2 dd55d44f

+15 -4
+15 -4
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
··· 1640 1640 ibmsg = tx->tx_msg; 1641 1641 ibmsg->ibm_u.immediate.ibim_hdr = *hdr; 1642 1642 1643 - copy_from_iter(&ibmsg->ibm_u.immediate.ibim_payload, IBLND_MSG_SIZE, 1644 - &from); 1643 + rc = copy_from_iter(&ibmsg->ibm_u.immediate.ibim_payload, payload_nob, 1644 + &from); 1645 + if (rc != payload_nob) { 1646 + kiblnd_pool_free_node(&tx->tx_pool->tpo_pool, &tx->tx_list); 1647 + return -EFAULT; 1648 + } 1649 + 1645 1650 nob = offsetof(struct kib_immediate_msg, ibim_payload[payload_nob]); 1646 1651 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_IMMEDIATE, nob); 1647 1652 ··· 1746 1741 break; 1747 1742 } 1748 1743 1749 - copy_to_iter(&rxmsg->ibm_u.immediate.ibim_payload, 1750 - IBLND_MSG_SIZE, to); 1744 + rc = copy_to_iter(&rxmsg->ibm_u.immediate.ibim_payload, rlen, 1745 + to); 1746 + if (rc != rlen) { 1747 + rc = -EFAULT; 1748 + break; 1749 + } 1750 + 1751 + rc = 0; 1751 1752 lnet_finalize(ni, lntmsg, 0); 1752 1753 break; 1753 1754