Commit d913d32
netlink: Use copy_to_user() for optval in netlink_getsockopt().
Brad Spencer provided a detailed report [0] that when calling getsockopt()
for AF_NETLINK, some SOL_NETLINK options set only 1 byte even though such
options require at least sizeof(int) as length.
The options return a flag value that fits into 1 byte, but such behaviour
confuses users who do not initialise the variable before calling
getsockopt() and do not strictly check the returned value as char.
Currently, netlink_getsockopt() uses put_user() to copy data to optlen and
optval, but put_user() casts the data based on the pointer, char *optval.
As a result, only 1 byte is set to optval.
To avoid this behaviour, we need to use copy_to_user() or cast optval for
put_user().
Note that this changes the behaviour on big-endian systems, but we document
that the size of optval is int in the man page.
$ man 7 netlink
...
Socket options
To set or get a netlink socket option, call getsockopt(2) to read
or setsockopt(2) to write the option with the option level argument
set to SOL_NETLINK. Unless otherwise noted, optval is a pointer to
an int.
Fixes: 9a4595b ("[NETLINK]: Add set/getsockopt options to support more than 32 groups")
Fixes: be0c22a ("netlink: add NETLINK_BROADCAST_ERROR socket option")
Fixes: 38938bf ("netlink: add NETLINK_NO_ENOBUFS socket flag")
Fixes: 0a6a3a2 ("netlink: add NETLINK_CAP_ACK socket option")
Fixes: 2d4bc93 ("netlink: extended ACK reporting")
Fixes: 89d3552 ("netlink: Add new socket option to enable strict checking on dumps")
Reported-by: Brad Spencer <bspencer@blackberry.com>
Link: https://lore.kernel.org/netdev/ZD7VkNWFfp22kTDt@datsun.rim.net/
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Johannes Berg <johannes@sipsolutions.net>
Link: https://lore.kernel.org/r/20230421185255.94606-1-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>1 parent 60fd497 commit d913d32
1 file changed
Lines changed: 23 additions & 52 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1742 | 1742 | | |
1743 | 1743 | | |
1744 | 1744 | | |
1745 | | - | |
| 1745 | + | |
| 1746 | + | |
1746 | 1747 | | |
1747 | 1748 | | |
1748 | 1749 | | |
| |||
1754 | 1755 | | |
1755 | 1756 | | |
1756 | 1757 | | |
1757 | | - | |
1758 | | - | |
1759 | | - | |
1760 | | - | |
1761 | | - | |
1762 | | - | |
1763 | | - | |
1764 | | - | |
| 1758 | + | |
1765 | 1759 | | |
1766 | 1760 | | |
1767 | | - | |
1768 | | - | |
1769 | | - | |
1770 | | - | |
1771 | | - | |
1772 | | - | |
1773 | | - | |
1774 | | - | |
| 1761 | + | |
1775 | 1762 | | |
1776 | 1763 | | |
1777 | | - | |
1778 | | - | |
1779 | | - | |
1780 | | - | |
1781 | | - | |
1782 | | - | |
1783 | | - | |
1784 | | - | |
| 1764 | + | |
1785 | 1765 | | |
1786 | 1766 | | |
1787 | | - | |
| 1767 | + | |
1788 | 1768 | | |
1789 | | - | |
1790 | 1769 | | |
1791 | 1770 | | |
1792 | 1771 | | |
| |||
1803 | 1782 | | |
1804 | 1783 | | |
1805 | 1784 | | |
1806 | | - | |
| 1785 | + | |
1807 | 1786 | | |
1808 | 1787 | | |
1809 | | - | |
1810 | | - | |
1811 | | - | |
1812 | | - | |
1813 | | - | |
1814 | | - | |
1815 | | - | |
1816 | | - | |
| 1788 | + | |
1817 | 1789 | | |
1818 | 1790 | | |
1819 | | - | |
1820 | | - | |
1821 | | - | |
1822 | | - | |
1823 | | - | |
1824 | | - | |
1825 | | - | |
| 1791 | + | |
1826 | 1792 | | |
1827 | 1793 | | |
1828 | | - | |
1829 | | - | |
1830 | | - | |
1831 | | - | |
1832 | | - | |
1833 | | - | |
1834 | | - | |
| 1794 | + | |
1835 | 1795 | | |
1836 | 1796 | | |
1837 | | - | |
| 1797 | + | |
1838 | 1798 | | |
1839 | | - | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
1840 | 1811 | | |
1841 | 1812 | | |
1842 | 1813 | | |
| |||
0 commit comments