NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: kern/58051: ccd(4) sysctl()s abused the api
The following reply was made to PR kern/58051; it has been noted by GNATS.
From: Paul Goyette <paul%whooppee.com@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc:
Subject: Re: kern/58051: ccd(4) sysctl()s abused the api
Date: Sat, 26 Apr 2025 07:24:48 -0700 (PDT)
Any reason to keep this PR open? At the least, can we commit
the proposed work-around, and then lower the priority?
>> Fix:
> The following works around the problem. The correct solution
> would need a rewrite of ccd(4)'s sysctl() code.
>
> Index: ccd.c
> ===================================================================
> RCS file: /cvsroot/src/sys/dev/ccd.c,v
> retrieving revision 1.189
> diff -u -p -r1.189 ccd.c
> --- ccd.c 28 Mar 2022 12:48:35 -0000 1.189
> +++ ccd.c 5 Mar 2024 20:17:50 -0000
> @@ -1772,13 +1772,14 @@ ccd_info_sysctl(SYSCTLFN_ARGS)
> struct sysctlnode node;
> struct ccddiskinfo ccd;
> struct ccd_softc *sc;
> - int unit;
> + int unit, error;
>
> if (newp == NULL || newlen != sizeof(int))
> return EINVAL;
>
> - unit = *(const int *)newp;
> - newp = NULL;
> + error = sysctl_copyin(l, newp, &unit, sizeof unit);
> + if (error)
> + return error;
> newlen = 0;
> ccd.ccd_ndisks = ~0;
> mutex_enter(&ccd_lock);
> @@ -1816,8 +1817,9 @@ ccd_components_sysctl(SYSCTLFN_ARGS)
> return EINVAL;
>
> size = 0;
> - unit = *(const int *)newp;
> - newp = NULL;
> + error = sysctl_copyin(l, newp, &unit, sizeof unit);
> + if (error)
> + return error;
> newlen = 0;
> mutex_enter(&ccd_lock);
> LIST_FOREACH(sc, &ccds, sc_link)
+---------------------+--------------------------+----------------------+
| Paul Goyette (.sig) | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | 1B11 1849 721C 56C8 F63A | paul%whooppee.com@localhost |
| Software Developer | 6E2E 05FD 15CE 9F2D 5102 | pgoyette%netbsd.org@localhost |
| & Network Engineer | | pgoyette99%gmail.com@localhost |
+---------------------+--------------------------+----------------------+
Home |
Main Index |
Thread Index |
Old Index