Commit 761fcf4
w1: therm: Fix off-by-one buffer overflow in alarms_store
The sysfs buffer passed to alarms_store() is allocated with 'size + 1'
bytes and a NUL terminator is appended. However, the 'size' argument
does not account for this extra byte. The original code then allocated
'size' bytes and used strcpy() to copy 'buf', which always writes one
byte past the allocated buffer since strcpy() copies until the NUL
terminator at index 'size'.
Fix this by parsing the 'buf' parameter directly using simple_strtoll()
without allocating any intermediate memory or string copying. This
removes the overflow while simplifying the code.
Cc: stable@vger.kernel.org
Fixes: e2c94d6 ("w1_therm: adding alarm sysfs entry")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20251216145007.44328-2-thorsten.blum@linux.dev
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>1 parent 8f0b4cc commit 761fcf4
1 file changed
Lines changed: 20 additions & 42 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1836 | 1836 | | |
1837 | 1837 | | |
1838 | 1838 | | |
1839 | | - | |
1840 | | - | |
| 1839 | + | |
| 1840 | + | |
1841 | 1841 | | |
1842 | | - | |
1843 | | - | |
1844 | | - | |
1845 | | - | |
1846 | | - | |
1847 | | - | |
1848 | | - | |
1849 | | - | |
1850 | | - | |
1851 | | - | |
1852 | | - | |
1853 | | - | |
1854 | | - | |
1855 | | - | |
1856 | | - | |
1857 | | - | |
1858 | | - | |
1859 | | - | |
1860 | | - | |
1861 | | - | |
1862 | | - | |
1863 | | - | |
1864 | | - | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
1865 | 1850 | | |
1866 | 1851 | | |
1867 | 1852 | | |
1868 | | - | |
| 1853 | + | |
1869 | 1854 | | |
1870 | 1855 | | |
1871 | 1856 | | |
1872 | 1857 | | |
1873 | | - | |
1874 | | - | |
1875 | | - | |
1876 | | - | |
1877 | | - | |
1878 | | - | |
1879 | | - | |
1880 | | - | |
1881 | | - | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
1882 | 1864 | | |
1883 | 1865 | | |
1884 | 1866 | | |
1885 | | - | |
| 1867 | + | |
1886 | 1868 | | |
1887 | 1869 | | |
1888 | 1870 | | |
| |||
1905 | 1887 | | |
1906 | 1888 | | |
1907 | 1889 | | |
1908 | | - | |
| 1890 | + | |
1909 | 1891 | | |
1910 | 1892 | | |
1911 | 1893 | | |
1912 | 1894 | | |
1913 | 1895 | | |
1914 | 1896 | | |
1915 | 1897 | | |
1916 | | - | |
| 1898 | + | |
1917 | 1899 | | |
1918 | 1900 | | |
1919 | 1901 | | |
| |||
1922 | 1904 | | |
1923 | 1905 | | |
1924 | 1906 | | |
1925 | | - | |
1926 | | - | |
1927 | | - | |
1928 | | - | |
1929 | 1907 | | |
1930 | 1908 | | |
1931 | 1909 | | |
| |||
0 commit comments