Re: autoinstall(8) tweaks

2015-04-17 Thread Theo de Raadt
> On 2015/04/15 12:05, Vincent Gross wrote:
> > The default allocation is actually easy to rework right after a fresh
> > install, as /usr/src, /usr/obj and /home are at the end. Ssh as
> > root, kill /usr/src, /usr/obj and /home, optionally extend /usr/local,
> > and then repartition as you wish.
> 
> I'm sorry but I find this ridiculous. Yes you *can* do it, and sometimes
> you have to when you discover too late that your partitioning scheme is
> wrong, but why should users have to go through contortions to use the
> autoinstaller?

Because the autoinstaller only has support for answering questions
the shell script asks

> If somebody decides to go to the trouble of writing an autoinstall
> script to set things up in some way, I think they should get exactlwhat
> they want.

Well sorry.  The autoinstaller only answer questions the shell script
asks; not the questions asked by deeper programs like fdisk or
disklabel.

In the installer group view, these proposals will bring fragility to
the install script.  When erroneous input is supplied, very ugly
failures.

As to why the autoinstaller only accepts questions the shell script
asks?  That is how Uwe designed it.  We learned from this, and then as
a group we adjusted the installer questions to make auto installs
easy.  It was a significant group effort with lots of learning.
Except the mechanism cannot talk to sub-programs.  A flaw but we got a
long way forward, and now there are obvious demands it to more.

It could be changed to a different mechanism based on what was
learned.  Some ideas have been tossed around, but they are not one-day
hack sessions.  pty's on the install media perhaps?  There are
downsides from such designs as well...

> They'll find some way to do it anyway; not supporting custom
> partitioning in the installer just makes more work for them. It's not
> like it's a manual install user, "oh I can't decide I'll just put
> everything in /", this is only going to be used by people who already
> made the trade-off decision. Maybe they don't even have enough disk
> space to do updates without a custom setup.

Yes, there are many ways to work around the fact that the
autoinstaller can only cope with questions the shell script asks!

The OP suggested one workaround.  Others have suggested other
workarounds.  They are all the same, in essence: chicken scratches fed
as stdin to disklabel...  but what if disklabel changes behaviour in
the future?  Incompatible input; chaos.  I worry that this is OpenBSD
and thus, when a reason is found for disklabel to change behaviour, it
will change, chicken scratches or not... and be incompatible with input
people have placed.

So I believe we need a future complete & maintainable mechanism, or at
least think towards that direction.

It would be nice to see some effort put into extending disklabel
itself (in C) to accept less chicken-scratchy input; perhaps a new
simple input format which coordinates to adjust the auto-label scheme,
more standard, less subject to impact if we change disklabel; maybe a
cleaner way to request this input mode and point to the input file,
rather than stdin.  And a well defined strategy to cope with when the
layout fails to apply to the disk.

Basically, move this problem out of the land of shell scripts and
shell input.

Those are my thoughts for a better design...



Re: [NEW] Driver for the Araneus Alea II USB TRNG

2015-04-17 Thread Martin Pieuchot
On 16/04/15(Thu) 16:06, attila wrote:
> [...] 
> After this was committed I received a critique of the driver from the
> person behind the Alea II (Andreas Gustafsson) who made a few pretty
> good points.  He felt trying to pull all the entropy off of the device
> that would theoretically be available every second was a losing
> strategy for several reasons.  Most importantly I ended up calling
> add_true_randomness() in bursts of 3200 calls every trip through
> ualea_task() whereas rnd_event_space[] in rnd.c only has 64 entries on
> a 32bit machine (42 on amd64); this almost surely means that the vast
> majority of my calls are no-ops... not so useful, it appears.
> 
> The attached diff cranks the buffer size way down and now we call
> add_true_randomness() 32 times every 100ms.  When I crank ALEA_MSECS
> below 100ms I start to notice the load increases on the machine with
> an Alea II plugged in.  I guess this is because the stuff that happens
> in ualea_task() happens in the context of a process and that process
> always appears to be runnable when ALEA_MSECS is e.g. 10ms.  I crank
> the read timeout up to 5000ms because that's what he recommends in his
> sample code; under normal circumstances we never time out.
> 
> The diff also explicitly looks for endpoint #1 because that's the
> endpoint that Andreas says to use, not necc. the first one that I
> find; as it turns out now the first one I find is the right one but
> just to be safe it's better to check explicitly.
> 
> Maybe now this is closer to production-worthy.  All feedback and
> comments most welcome.

Applied, thanks.

Just one note, I had to apply your diff by hand because your MUA changes
the tab into space.  If you can change that for the next diff that would
be great!



Re: On github now

2015-04-17 Thread Martin Pieuchot
On 16/04/15(Thu) 15:24, kanonenvogel@gmail.com wrote:
> Well, lets begin.
> 
> In the future, I wish to have fd_getfile() returning acquired fp instance.
> The goal is to not to have pointer to destroyed fp instance
> in FREF()/FRELE()/fd_getfile() races. This one requres modification of
> getsock(), getvnode() and dupfdopen() functions, they must receive pointer to
> struct proc instance for FRELE() call on referenced fp instance while they
> have internal error cases. While getsock(), getvnode() and dupfdopen()
> functions are called, "struct proc" instance exists, so their
> "struct filedesc *" arg can be replaced by "struct proc *" arg which contains
> pointer to "struct filedesc”.
> 
> The races will be appeared right after at least one FRELE(), FREF() or
> fd_getfile() call will be done outside kernel lock. The “outside kernel lock" 
> call
> capability requires a little more refactoring, but for this functions only, 
> not
> system-wide.
> 
> Now we have something like:
> 
> if((fp = fd_getfile(fds, fd)) == NULL)
> goto error;
> 
> /*
>  * fp can be destroyed here by FRELE() call on other cpu
>  */
> 
> FREF(fp);
> 
> The goal is to avoid this situation.

I came to the same conclusion when I wrote these diffs.  I think the
first 3 are good and simple enough to be committed, somebody else agree?

The fourth one that move FREF() inside fd_getfile() is IMHO incomplete.
As you can see I putted some XXX where the existing code was calling 
fd_getfile() without incrementing the reference count.  Why did you
decide to delete them?

I can't say if the actual behavior is correct or not, what do you think?
I believe all these cases must be carefully fixed first.

> Should I checkout CURRENT and patch it or 5.7 is fine too?

-current is where development happens :)

> I attach already exitig patches for git tree. If it required, I'll
> remake them and send one after another.

Don't flood us ;)  But the next time, one diff *inline* with a clear
subject message is the preferred way so we can simply use our mailbox
to do peer review.

Regarding your previous question about the first diff I sent you:
> I don't understand, why we need to check flags inside fd_getfile

You don't *need* to, but doing so will remove a lot of gotos the
functions calling fd_getfile().  I'm aware it's not strictly necessary
but compare (without diff):

if ((fp = fd_getfile()) == NULL)
return (EBADF);
if (fp->f_flags & mode) == 0)
goto unref;



unref:
FRELE(fp)



to (with diff):

if ((fp = fd_getfile(mode)) == NULL)
return (EBADF);




Of course all the functions do not return EBADF when the mode is
incorrect, but I think the pattern is spread enough for this change
to be worth it.



remove oss support from linux compat (i386 only)

2015-04-17 Thread Alexandre Ratchov
This was "discussed" and nobody steps up to save it:

http://comments.gmane.org/gmane.os.openbsd.misc/217005

removing oss emulation, will remove dependency on obscure audio(4)
features we don't use since ~2009, and in turn will ease audio(4)
driver cleanup without breaking the build.

Tested on i386.

OK?

--- arch/i386/conf/files.i386.orig  Fri Oct 31 16:52:36 2014
+++ arch/i386/conf/files.i386   Fri Oct 31 16:52:51 2014
@@ -264,9 +264,6 @@ filearch/i386/i386/kvm86call.S  kvm86
 include "compat/linux/files.linux"
 file   arch/i386/i386/linux_machdep.c  compat_linux
 
-# OSS audio driver compatibility
-include "compat/ossaudio/files.ossaudio"
-
 device bios {}
 attach bios at mainbus
 file   arch/i386/i386/bios.c   bios needs-count
--- compat/linux/linux_ioctl.c.orig Fri Oct 31 16:54:42 2014
+++ compat/linux/linux_ioctl.c  Fri Oct 31 16:58:14 2014
@@ -48,9 +48,6 @@
 #include 
 #include 
 
-#include 
-#define LINUX_TO_OSS(v) (v)/* do nothing, same ioctl() encoding */
-
 /*
  * Most ioctl command are just converted to their OpenBSD values,
  * and passed on. The ones that take structure pointers and (flag)
@@ -71,12 +68,6 @@ linux_sys_ioctl(p, v, retval)
} */ *uap = v;
 
switch (LINUX_IOCGROUP(SCARG(uap, com))) {
-   case 'M':
-   return oss_ioctl_mixer(p, LINUX_TO_OSS(v), retval);
-   case 'Q':
-   return oss_ioctl_sequencer(p, LINUX_TO_OSS(v), retval);
-   case 'P':
-   return oss_ioctl_audio(p, LINUX_TO_OSS(v), retval);
case 't':
case 'f':
case 'T':   /* XXX MIDI sequencer uses 'T' as well */
--- compat/linux/linux_ioctl.h.orig Fri Oct 31 16:55:09 2014
+++ compat/linux/linux_ioctl.h  Fri Oct 31 16:58:35 2014
@@ -79,8 +79,6 @@
 #defineLINUX_IOCGROUP(x)   _LINUX_IOC_TYPE(x)
 
 struct linux_sys_ioctl_args;
-int linux_ioctl_audio(struct proc *, struct linux_sys_ioctl_args *,
-register_t *);
 int linux_machdepioctl(struct proc *, void *, register_t *);
 int linux_ioctl_termios(struct proc *, void *, register_t *);
 int linux_ioctl_cdrom(struct proc *, void *, register_t *);
--- compat/ossaudio/files.ossaudio.orig Fri Oct 31 16:55:37 2014
+++ compat/ossaudio/files.ossaudio  Fri Oct 31 17:05:04 2014
@@ -1,8 +0,0 @@
-#  $OpenBSD: files.ossaudio,v 1.5 2011/04/05 12:50:15 guenther Exp $
-#  $NetBSD: files.ossaudio,v 1.2 1997/07/20 20:35:44 pk Exp $
-#
-# Config file description for OSS (Voxware) audio driver
-# compatibility.  Used by compat_linux
-# Included by ports that need it.
-
-file   compat/ossaudio/ossaudio.c  compat_linux
--- compat/ossaudio/ossaudio.c.orig Fri Oct 31 16:55:45 2014
+++ compat/ossaudio/ossaudio.c  Fri Oct 31 17:05:04 2014
@@ -1,852 +0,0 @@
-/* $OpenBSD: ossaudio.c,v 1.16 2013/03/28 03:45:32 tedu Exp $  */
-/* $NetBSD: ossaudio.c,v 1.23 1997/10/19 07:41:52 augustss Exp $   */
-
-/*
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-
-#include 
-#include 
-
-#ifdef AUDIO_DEBUG
-#define DPRINTF(x) if (ossdebug) printf x
-int ossdebug = 0;
-#else
-#define DPRINTF(x)
-#endif
-
-#define TO_OSSVOL(x) ((x) * 100 / 255)
-#define FROM_OSSVOL(x) ((x) * 255 / 100)
-
-static struct audiodevinfo *getdevinfo(struct file *, struct proc *);
-
-static void setblocksize(struct file *, struct audio_info *, struct proc *);
-
-
-int
-oss_ioctl_audio(p, uap, retval)
-   struct proc *p;
-   struct oss_sys_ioctl_args /* {
-   syscallarg(int) fd;
- 

remove dsp bits from libossaudio

2015-04-17 Thread Alexandre Ratchov
No code uses the SNDCLT_DSP_* "ioctls" anymore (the last port using
them was removed few months ago), so they could be removed now. As
there's no ABI change, no shlib_version crank is necessary.

The motivation of removing these "ioctls" is to ease
simplifications and development of the audio(4) driver.

OK?

Index: ossaudio.c
===
RCS file: /cvs/src/lib/libossaudio/ossaudio.c,v
retrieving revision 1.17
diff -u -p -u -p -r1.17 ossaudio.c
--- ossaudio.c  27 Mar 2013 20:28:22 -  1.17
+++ ossaudio.c  17 Apr 2015 10:20:35 -
@@ -54,9 +54,6 @@
 
 static struct audiodevinfo *getdevinfo(int);
 
-static void setblocksize(int, struct audio_info *);
-
-static int audio_ioctl(int, unsigned long, void *);
 static int mixer_ioctl(int, unsigned long, void *);
 static int opaque_to_enum(struct audiodevinfo *di, audio_mixer_name_t *label, 
int opq);
 static int enum_to_ord(struct audiodevinfo *di, int enm);
@@ -74,388 +71,13 @@ _oss_ioctl(int fd, unsigned long com, ..
argp = va_arg(ap, void *);
va_end(ap);
if (IOCGROUP(com) == 'P')
-   return audio_ioctl(fd, com, argp);
+   return ENOTTY;
else if (IOCGROUP(com) == 'M')
return mixer_ioctl(fd, com, argp);
else
return ioctl(fd, com, argp);
 }
 
-static int
-audio_ioctl(int fd, unsigned long com, void *argp)
-{
-
-   struct audio_info tmpinfo;
-   struct audio_offset tmpoffs;
-   struct audio_buf_info bufinfo;
-   struct count_info cntinfo;
-   struct audio_encoding tmpenc;
-   struct audio_bufinfo tmpab;
-   u_long ldat;
-   u_int u;
-   int idat, idata;
-   int tempret, retval = 0, rerr = 0;
-
-   switch (com) {
-   case SNDCTL_DSP_RESET:
-   retval = ioctl(fd, AUDIO_FLUSH, 0);
-   rerr = errno;
-   break;
-   case SNDCTL_DSP_SYNC:
-   retval = ioctl(fd, AUDIO_DRAIN, 0);
-   rerr = errno;
-   break;
-   case SNDCTL_DSP_POST:
-   /* This call is merely advisory, and may be a nop. */
-   break;
-   case SNDCTL_DSP_SPEED:
-   AUDIO_INITINFO(&tmpinfo);
-   tmpinfo.play.sample_rate =
-   tmpinfo.record.sample_rate = INTARG;
-   retval = ioctl(fd, AUDIO_SETINFO, &tmpinfo);
-   rerr = errno;
-   /* FALLTHRU */
-   case SOUND_PCM_READ_RATE:
-   tempret = ioctl(fd, AUDIO_GETINFO, &tmpinfo);
-   if (retval >= 0) {
-   retval = tempret;
-   rerr = errno;
-   }
-   INTARG = tmpinfo.play.sample_rate;
-   break;
-   case SNDCTL_DSP_STEREO:
-   AUDIO_INITINFO(&tmpinfo);
-   tmpinfo.play.channels =
-   tmpinfo.record.channels = INTARG ? 2 : 1;
-   retval = ioctl(fd, AUDIO_SETINFO, &tmpinfo);
-   rerr = errno;
-   tempret = ioctl(fd, AUDIO_GETINFO, &tmpinfo);
-   if (retval >= 0) {
-   retval = tempret;
-   rerr = errno;
-   }
-   INTARG = tmpinfo.play.channels - 1;
-   break;
-   case SNDCTL_DSP_GETBLKSIZE:
-   retval = ioctl(fd, AUDIO_GETINFO, &tmpinfo);
-   rerr = errno;
-   setblocksize(fd, &tmpinfo);
-   INTARG = tmpinfo.blocksize;
-   break;
-   case SNDCTL_DSP_SETFMT:
-   AUDIO_INITINFO(&tmpinfo);
-   switch (INTARG) {
-   case AFMT_MU_LAW:
-   tmpinfo.play.precision =
-   tmpinfo.record.precision = 8;
-   tmpinfo.play.encoding =
-   tmpinfo.record.encoding = AUDIO_ENCODING_ULAW;
-   break;
-   case AFMT_A_LAW:
-   tmpinfo.play.precision =
-   tmpinfo.record.precision = 8;
-   tmpinfo.play.encoding =
-   tmpinfo.record.encoding = AUDIO_ENCODING_ALAW;
-   break;
-   case AFMT_U8:
-   tmpinfo.play.precision =
-   tmpinfo.record.precision = 8;
-   tmpinfo.play.encoding =
-   tmpinfo.record.encoding = AUDIO_ENCODING_ULINEAR;
-   break;
-   case AFMT_S8:
-   tmpinfo.play.precision =
-   tmpinfo.record.precision = 8;
-   tmpinfo.play.encoding =
-   tmpinfo.record.encoding = AUDIO_ENCODING_SLINEAR;
-   break;
-   case AFMT_S16_LE:
-   tmpinfo.play.precision =
-   tmpinfo.record.precision = 16;
-   tmpinfo.play.encoding =
-   

Re: On github now

2015-04-17 Thread kanonenvogel . 87g

On 17 Apr 2015, at 12:49, Martin Pieuchot  wrote:

> On 16/04/15(Thu) 15:24, kanonenvogel@gmail.com wrote:
>> Well, lets begin.
>> 
>> In the future, I wish to have fd_getfile() returning acquired fp instance.
>> The goal is to not to have pointer to destroyed fp instance
>> in FREF()/FRELE()/fd_getfile() races. This one requres modification of
>> getsock(), getvnode() and dupfdopen() functions, they must receive pointer to
>> struct proc instance for FRELE() call on referenced fp instance while they
>> have internal error cases. While getsock(), getvnode() and dupfdopen()
>> functions are called, "struct proc" instance exists, so their
>> "struct filedesc *" arg can be replaced by "struct proc *" arg which contains
>> pointer to "struct filedesc”.
>> 
>> The races will be appeared right after at least one FRELE(), FREF() or
>> fd_getfile() call will be done outside kernel lock. The “outside kernel 
>> lock" call
>> capability requires a little more refactoring, but for this functions only, 
>> not
>> system-wide.
>> 
>> Now we have something like:
>> 
>> if((fp = fd_getfile(fds, fd)) == NULL)
>>   goto error;
>> 
>> /*
>> * fp can be destroyed here by FRELE() call on other cpu
>> */
>> 
>> FREF(fp);
>> 
>> The goal is to avoid this situation.
> 
> I came to the same conclusion when I wrote these diffs.  I think the
> first 3 are good and simple enough to be committed, somebody else agree?
> 
> The fourth one that move FREF() inside fd_getfile() is IMHO incomplete.
> As you can see I putted some XXX where the existing code was calling 
> fd_getfile() without incrementing the reference count.  Why did you
> decide to delete them?
Well, my version of fd_getfile() requires “struct proc *” arg for proper
funref() call within. So my original patchset has my own modification of
getsock(), getvnode() and dupfdopen(). They has “struct filedesc *” and 
“struct file *” arguments together, but the only “struct file *" is enough.
And I used your version. :)

At first i modified fd_getfile() internals for acquisition/release races 
on smp machine. Atomic increment of f_count is required in smp case.

Kernel sources has the strange and wrong magic with f_count field. closef()
wants fp->f_count to be >= 2, and closef()’s callers do this magic for panic
prevention. falloc() and FILE_SET_MATURE() do this magic too. Now,
newly created “struct file” instance has f_count == 2. It’s wrong, and below I
describe situation without this magic.

Minimal f_count value of existing “struct file” instance is 1.
Minimal f_count value of existing and acquired “struct file” instance is 2.
Minimal f_count value of acquired “struct file” instance is 1.

“existing” means “exists in “struct filedesc” instance and can be obtained by
fd_getfile() call”.
“acquired” means “returned by fd_getfile() call”. 
“struct filedesc” instance holds existing “struct file” instances.

fdalloc() creates and places “struct file” instance to “struct filedesc” 
container
fdrelease() removes “struct file” instance from “struct filedesc”, but delete it
only if f_count is 1 (fp exists and has no references). fp instance can be
shared between multiple processes and can be shared by multiple
“struct file” correlated syscalls of one multithreaded process. So, we have
races and situation can be: “fp instance” must be removed from
“struct filedesc” but kept for current “struct file” instance users. Last of 
them
will destroy it by FRELE() call. If we don’t increment f_count within 
fd_getfile(),
we can return pointer to already destroyed “struct file” instance. For example
one thread calls fd_getfile() and other calls fdrelease(). If fd_getfile() 
caller
wins, f_count is at least 1 and instance is not destroyed, but removed from
“struct filedesc” container and can’t be obtained by next fd_getfile() call. if
fdrelease() wins it removes and destroys “struct file” instance and fd_getfile()
will return NULL.

the real fucntions must be:

struct file *
fd_getfile(struct filedesc *fdp, int fd, struct proc *p)
{
#ifdef MULTIPROCESSOR
struct file *fp;
unsigned long count;

if(fd <0 || fd >= fdp->fd_nfiles)
return NULL;

restart:
if ((fp = fdp->fd_ofiles[fd]) == NULL)
return NULL;
if ((count = fp->f_count) == 0)
return NULL;
if (atomic_cas_ulong(&fp->f_count, count, count + 1) != count)
goto restart;
if ((fp != fdp->fd_ofiles[fd])) {
funref(fp, p);
goto restart;
}
if (!FILE_IS_USABLE(fp)) {
funref(fp, p);
return (NULL);
}

return fp;
#else
struct file *fp;

if(fd <0 || fd >= fdp->fd_nfiles)
return NULL;
if ((fp != fdp->fd_ofiles[fd]))
return NULL;
if (!FILE_IS_USABLE(fp))
return NULL;
fp->f_count++;

return fp;
#endif
}

/*
* FREF() replacement, must be called on
*

[PATCH] Disable USB bus probes

2015-04-17 Thread Dimitris Papastamos
Hi,

This patch adds an option to usbdevs(8) to disable USB bus probing
at runtime.  The operation is restricted to the root user.

I am not sure if this approach is sensible or even correct.  Some
pointers would be much appreciated.

This was started as part of a reply by mpi on tech@

  http://marc.info/?l=openbsd-tech&m=142917883126679&w=2

I guess the reasoning behind this is to add some protection against
things like badusb?

Index: sys/dev/usb/uhub.c
===
RCS file: /cvs/src/sys/dev/usb/uhub.c,v
retrieving revision 1.83
diff -u -p -r1.83 uhub.c
--- sys/dev/usb/uhub.c  12 Feb 2015 05:07:52 -  1.83
+++ sys/dev/usb/uhub.c  17 Apr 2015 15:36:30 -
@@ -222,6 +222,7 @@ uhub_attach(struct device *parent, struc
hub->nports = nports;
hub->powerdelay = powerdelay;
hub->ttthink = ttthink >> 5;
+   hub->noprobe = 0;
 
if (!dev->self_powered && dev->powersrc->parent != NULL &&
!dev->powersrc->parent->self_powered) {
@@ -494,6 +495,9 @@ uhub_explore(struct usbd_device *dev)
 */
if (speed > sc->sc_hub->speed)
speed = sc->sc_hub->speed;
+
+   if (dev->hub->noprobe)
+   return (0);
 
/* Get device info and set its address. */
err = usbd_new_device(&sc->sc_dev, dev->bus,
Index: sys/dev/usb/usb.c
===
RCS file: /cvs/src/sys/dev/usb/usb.c,v
retrieving revision 1.107
diff -u -p -r1.107 usb.c
--- sys/dev/usb/usb.c   14 Mar 2015 03:38:50 -  1.107
+++ sys/dev/usb/usb.c   17 Apr 2015 15:36:30 -
@@ -607,6 +607,17 @@ usbioctl(dev_t devt, u_long cmd, caddr_t
 #endif
break;
 #endif /* USB_DEBUG */
+   case USB_NO_PROBE:
+   {
+   struct usbd_device *dev = sc->sc_bus->root_hub;
+
+   if ((error = suser(curproc, 0)) != 0)
+   return (error);
+   if (!(flag & FWRITE))
+   return (EBADF);
+   dev->hub->noprobe = !!*(unsigned int *)data;
+   break;
+   }
case USB_REQUEST:
{
struct usb_ctl_request *ur = (void *)data;
Index: sys/dev/usb/usb.h
===
RCS file: /cvs/src/sys/dev/usb/usb.h,v
retrieving revision 1.50
diff -u -p -r1.50 usb.h
--- sys/dev/usb/usb.h   14 Feb 2015 06:18:58 -  1.50
+++ sys/dev/usb/usb.h   17 Apr 2015 15:36:30 -
@@ -728,6 +728,7 @@ struct usb_device_stats {
 #define USB_DEVICE_GET_CDESC   _IOWR('U', 6, struct usb_device_cdesc)
 #define USB_DEVICE_GET_FDESC   _IOWR('U', 7, struct usb_device_fdesc)
 #define USB_DEVICE_GET_DDESC   _IOWR('U', 8, struct usb_device_ddesc)
+#define USB_NO_PROBE   _IOW ('U', 9, unsigned int)
 
 /* Generic HID device */
 #define USB_GET_REPORT_DESC_IOR ('U', 21, struct usb_ctl_report_desc)
Index: sys/dev/usb/usbdivar.h
===
RCS file: /cvs/src/sys/dev/usb/usbdivar.h,v
retrieving revision 1.69
diff -u -p -r1.69 usbdivar.h
--- sys/dev/usb/usbdivar.h  21 Dec 2014 12:04:01 -  1.69
+++ sys/dev/usb/usbdivar.h  17 Apr 2015 15:36:30 -
@@ -94,6 +94,7 @@ struct usbd_hub {
int nports;
u_int8_tpowerdelay;
u_int8_tttthink;
+   u_int8_tnoprobe;
 };
 
 struct usbd_bus {
Index: usr.sbin/usbdevs/usbdevs.8
===
RCS file: /cvs/src/usr.sbin/usbdevs/usbdevs.8,v
retrieving revision 1.9
diff -u -p -r1.9 usbdevs.8
--- usr.sbin/usbdevs/usbdevs.8  26 Jun 2008 05:42:21 -  1.9
+++ usr.sbin/usbdevs/usbdevs.8  17 Apr 2015 15:36:31 -
@@ -39,6 +39,7 @@
 .Op Fl dv
 .Op Fl a Ar addr
 .Op Fl f Ar dev
+.Op Fl p Ar on | off
 .Sh DESCRIPTION
 .Nm
 prints a listing of all USB devices connected to the system
@@ -53,6 +54,10 @@ Only print information about the device 
 Show the device drivers associated with each device.
 .It Fl f Ar dev
 Only print information for the given USB controller.
+.It Fl p Ar on | off
+Enable or disable USB bus probing.  The default
+is
+.Ar on .
 .It Fl v
 Be verbose.
 .El
Index: usr.sbin/usbdevs/usbdevs.c
===
RCS file: /cvs/src/usr.sbin/usbdevs/usbdevs.c,v
retrieving revision 1.24
diff -u -p -r1.24 usbdevs.c
--- usr.sbin/usbdevs/usbdevs.c  31 Mar 2015 13:38:27 -  1.24
+++ usr.sbin/usbdevs/usbdevs.c  17 Apr 2015 15:36:31 -
@@ -30,6 +30,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -53,6 +54,7 @@ void usage(void);
 void usbdev(int f, int a, int rec);
 void usbdump(int f);
 void dumpone(char *name, int f, int addr);
+void setprobe(unsigned int);
 int main(int, char **);
 
 extern char *

Re: atoi -> strtonum

2015-04-17 Thread Theo de Raadt
Jeremy Devenport and Brendan MacDonell reviewed the changes and
spotted a few issues.  Here is a new diff.

Index: bin/csh/proc.c
===
RCS file: /cvs/src/bin/csh/proc.c,v
retrieving revision 1.26
diff -u -p -u -r1.26 proc.c
--- bin/csh/proc.c  8 Feb 2015 06:09:50 -   1.26
+++ bin/csh/proc.c  13 Apr 2015 14:58:41 -
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -931,6 +932,7 @@ void
 dokill(Char **v, struct command *t)
 {
 int signum = SIGTERM;
+const char *errstr;
 char *name;
 
 v++;
@@ -940,8 +942,8 @@ dokill(Char **v, struct command *t)
if (!Isdigit(v[1][0]))
stderror(ERR_NAME | ERR_BADSIG);
 
-   signum = atoi(short2str(v[1]));
-   if (signum < 0 || signum >= NSIG)
+   signum = strtonum(short2str(v[1]), 0, NSIG-1, &errstr);
+   if (errstr)
stderror(ERR_NAME | ERR_BADSIG);
else if (signum == 0)
(void) fputc('0', cshout); /* 0's symbolic name is '0' */
@@ -958,8 +960,8 @@ dokill(Char **v, struct command *t)
return;
}
if (Isdigit(v[0][1])) {
-   signum = atoi(short2str(v[0] + 1));
-   if (signum < 0 || signum >= NSIG)
+   signum = strtonum(short2str(v[0] + 1), 0, NSIG-1, &errstr);
+   if (errstr)
stderror(ERR_NAME | ERR_BADSIG);
}
else {
@@ -1147,12 +1149,18 @@ pfind(Char *cp)
return (pprevious);
 }
 if (Isdigit(cp[1])) {
-   int idx = atoi(short2str(cp + 1));
+   const char *errstr;
+   int idx = strtonum(short2str(cp + 1), 1, INT_MAX, &errstr);
 
+   if (errstr) {
+   stderror(ERR_NAME | ERR_NOSUCHJOB);
+   return (0);
+   }
for (pp = proclist.p_next; pp; pp = pp->p_next)
if (pp->p_index == idx && pp->p_pid == pp->p_jobid)
return (pp);
stderror(ERR_NAME | ERR_NOSUCHJOB);
+   return (0);
 }
 np = NULL;
 for (pp = proclist.p_next; pp; pp = pp->p_next)
Index: bin/date/date.c
===
RCS file: /cvs/src/bin/date/date.c,v
retrieving revision 1.46
diff -u -p -u -r1.46 date.c
--- bin/date/date.c 17 Mar 2015 19:31:30 -  1.46
+++ bin/date/date.c 7 Apr 2015 17:11:20 -
@@ -59,6 +59,7 @@ int
 main(int argc, char *argv[])
 {
struct timezone tz;
+   const char *errstr;
struct tm *tp;
int ch, rflag;
char *format, buf[1024], *outzone = NULL;
@@ -87,12 +88,10 @@ main(int argc, char *argv[])
err(1, "cannot unsetenv TZ");
break;
case 't':   /* minutes west of GMT */
-   /* error check; don't allow "PST" */
-   if (isdigit((unsigned char)*optarg)) {
-   tz.tz_minuteswest = atoi(optarg);
-   break;
-   }
-   /* FALLTHROUGH */
+   tz.tz_minuteswest = strtonum(optarg, 0, 24*60-1, 
&errstr);
+   if (errstr)
+   errx(1, "-t %s: %s", optarg, errstr);
+   break;
case 'z':
outzone = optarg;
break;
Index: bin/ksh/exec.c
===
RCS file: /cvs/src/bin/ksh/exec.c,v
retrieving revision 1.50
diff -u -p -u -r1.50 exec.c
--- bin/ksh/exec.c  10 Jun 2013 21:09:27 -  1.50
+++ bin/ksh/exec.c  16 Apr 2015 02:47:37 -
@@ -1234,6 +1234,7 @@ do_selectargs(char **ap, bool print_menu
static const char *const read_args[] = {
"read", "-r", "REPLY", (char *) 0
};
+   const char *errstr;
char *s;
int i, argct;
 
@@ -1252,8 +1253,10 @@ do_selectargs(char **ap, bool print_menu
return (char *) 0;
s = str_val(global("REPLY"));
if (*s) {
-   i = atoi(s);
-   return (i >= 1 && i <= argct) ? ap[i - 1] : null;
+   i = strtonum(s, 1, argct, &errstr);
+   if (errstr)
+   return null;
+   return ap[i - 1];
}
print_menu = 1;
}
Index: bin/ksh/jobs.c
===
RCS file: /cvs/src/bin/ksh/jobs.c,v
retrieving revision 1.40
diff -u -p -u -r1.40 jobs.c
--- bin/ksh/jobs.c  4 Sep 2013 15:49:18 -   1.40
+++ bin/ksh/jobs.c  13 Apr 2015 04:20:47 -
@@ -1428,11 +1428,17 @@ static Job *
 j_lookup(const char *cp, int *ecodep)
 {
Job *j, *las