Re: svn commit: r332072 - head/sys/sys

2018-04-06 Thread Roger Pau Monné
On Fri, Apr 06, 2018 at 03:12:08AM +1000, Bruce Evans wrote:
> On Thu, 5 Apr 2018, Warner Losh wrote:
> 
> > On Thu, Apr 5, 2018 at 9:46 AM, Roger Pau Monné  wrote:
> > 
> > > On Thu, Apr 05, 2018 at 09:32:57AM -0600, Ian Lepore wrote:
> > > > On Thu, 2018-04-05 at 14:31 +, Roger Pau Monné wrote:
> > > > > Log:
> > > > >   introduce GiB and MiB macros
> > > > > ...
> > > > > +/* Unit conversion macros. */
> > > > > +#define GiB(v) (v ## ULL << 30)
> > > > > +#define MiB(v) (v ## ULL << 20)
> > > > > +
> > > > >  #endif /* _SYS_PARAM_H_ */
> > > > 
> > > > These names don't make it clear whether the conversion is bytes->GiB or
> > > > GiB->bytes.  The names seem way too generic for a public namespace in a
> > > > file as heavily included behind your back as param.h is.
> > > > 
> > > > Also, this completely reasonable usage won't work, likely with
> > > > confusing compile error messages:
> > > > 
> > > >   int bytes, gibytes;
> > > >   ...
> > > >   bytes = GiB(gibytes);
> > > 
> > > I find those helpful for their specific usage. I could introduce
> > > static inline functions like:
> > > 
> > > size_t gb_to_bytes(size_t)...
> > > 
> > > But I assume this is also going to cause further discussion.
> 
> Yes, it gives even more namespace pollution and type errors.  Macros
> at least don't expose their internals if they are not used.
> 
> size_t is actually already part of the undocumented namespace pollution
> in .
> 
> The type errors are restriction to just one type in another way.  Type-
> generic APIs that avoid such restrictions are much harder to implement
> using inline functions than macros.
> 
> > Yea, traditional macro names would be "gibtob" and "btogib" but I didn't
> > just reply to bikeshed a name:
> > 
> > But you don't need to specify a type, consider the current btodb macro:
> > #define btodb(bytes)/* calculates (bytes / DEV_BSIZE)
> > */ \
> >(sizeof (bytes) > sizeof(long) \
> > ? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \
> > : (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT))
> > 
> > which shows how to do this in a macro, which is orthogonal to any name you
> > may choose. I can also bikeshed function vs macro :)
> 
> This macro is mostly my mistake in 1995-1996.  The long long abominations
> in it were supposed to be temporary (until C99 standardized something
> better).  It was originally MD for i386 only and then the sizes of almost
> all types are known and fixed so it is easier to hard-code minimal sizes
> that work.  The optimization of avoiding using 64-bit types was more needed
> in 1995-1996 since CPUs were slower and compilers did less strength reduction.
> 
> btodb() is much easier than dbtob() since it shifts right, so it can't
> overflow unless the cast of 'bytes' is wrong so that it truncations.
> dbtob() doesn't try hard to be optimal.  It just always upcasts to
> off_t.
> 
> jake later convinced me (in connection with his PAE and sparc64 work) that
> it should be the caller's responsibility to avoid overflow.  Any casts in
> the macro limits it to the types in it.  This is why the page to byte
> conversion macros don't have any casts in them.  PAE usually needs 64-bit
> results, but this would just be a pessimization for normal i386, and
> deciding the casts in the macro as above is complicated.
> 
> So correct GB() macros would look like ((v) << 30), where the caller must
> cast v to a large enough type.  E.g., for variable v which might be larger
> than 4, on 32-bit systems, the caller must write something like
> GB((uintmax_t)v).  But it is easier for writing to just multiply v by 1G.
> This is also easier for reading since it is unclear that GB() is even a
> conversion or which direction it goes in.  A longer descriptive name would
> be about as clear and long as an explicit multiplication.
> 
> I usually write 1G as ((type)1024 * 1024 * 1024) since the decimal and
> even hex values of 1G have too many digits to be clear, and
> multiplication is clearer than shifting and allows the type to be in
> the factor.
> 
> Disk block size conversions need to use macros since the DEV_BSIZE = 512
> was variable in theory (in practice this is now a fixed virtual size).
> Conversions to G don't need macros since the magic number in them is no
> more magic than the G in their name.

I personally find the following chunk:

if (addr < GiB(4))
...

Much more easier to read and parse than:

if (addr < (4 * 1024 * 1024 * 1024))
...

But I won't insist anymore.

I will revert this and introduce the macros locally where I need them.

Roger.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332092 - in head/sys: amd64/amd64 sys x86/x86

2018-04-06 Thread Roger Pau Monné
Author: royger
Date: Fri Apr  6 11:20:06 2018
New Revision: 332092
URL: https://svnweb.freebsd.org/changeset/base/332092

Log:
  remove GiB/MiB macros from param.h
  
  And instead define them in the files where they are used.
  
  Requested by: bde

Modified:
  head/sys/amd64/amd64/mp_machdep.c
  head/sys/sys/param.h
  head/sys/x86/x86/mp_x86.c

Modified: head/sys/amd64/amd64/mp_machdep.c
==
--- head/sys/amd64/amd64/mp_machdep.c   Fri Apr  6 09:25:08 2018
(r332091)
+++ head/sys/amd64/amd64/mp_machdep.c   Fri Apr  6 11:20:06 2018
(r332092)
@@ -83,6 +83,8 @@ __FBSDID("$FreeBSD$");
 #define BIOS_RESET (0x0f)
 #define BIOS_WARM  (0x0a)
 
+#define GiB(v) (v ## ULL << 30)
+
 extern struct pcpu __pcpu[];
 
 /* Temporary variables for init_secondary()  */

Modified: head/sys/sys/param.h
==
--- head/sys/sys/param.hFri Apr  6 09:25:08 2018(r332091)
+++ head/sys/sys/param.hFri Apr  6 11:20:06 2018(r332092)
@@ -362,8 +362,4 @@ __END_DECLS
  */
 #define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset])
 
-/* Unit conversion macros. */
-#define GiB(v) (v ## ULL << 30)
-#define MiB(v) (v ## ULL << 20)
-
 #endif /* _SYS_PARAM_H_ */

Modified: head/sys/x86/x86/mp_x86.c
==
--- head/sys/x86/x86/mp_x86.c   Fri Apr  6 09:25:08 2018(r332091)
+++ head/sys/x86/x86/mp_x86.c   Fri Apr  6 11:20:06 2018(r332092)
@@ -160,6 +160,8 @@ struct cache_info {
 
 unsigned int boot_address;
 
+#define MiB(v) (v ## ULL << 20)
+
 void
 mem_range_AP_init(void)
 {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r332092 - in head/sys: amd64/amd64 sys x86/x86

2018-04-06 Thread Bruce Evans

On Fri, 6 Apr 2018, [UTF-8] Roger Pau Monn?? wrote:


Log:
 remove GiB/MiB macros from param.h

 And instead define them in the files where they are used.

 Requested by: bde


Thanks, but these files have a negative need for the macros.


Modified: head/sys/amd64/amd64/mp_machdep.c
==
--- head/sys/amd64/amd64/mp_machdep.c   Fri Apr  6 09:25:08 2018
(r332091)
+++ head/sys/amd64/amd64/mp_machdep.c   Fri Apr  6 11:20:06 2018
(r332092)
@@ -83,6 +83,8 @@ __FBSDID("$FreeBSD$");
#define BIOS_RESET  (0x0f)
#define BIOS_WARM   (0x0a)

+#define GiB(v) (v ## ULL << 30)
+


In this file, the macro is used only once.  It takes about 4 times as
much code to define and use the macro once as to write
(vm_paddr_t)4 << 30.  Much more than 4 times longer to read, since some
searching is needed to find the macro and some decoding is needed to
understand it.  More to see that the wrong type returned by the macro
is not a problem.  The value can be written more consisely as 4L << 30
after doing a similar type analysis.  1G is normally written as
1024 * 1024 * 1024 since this is a bit clearer than 1 << 30.  This depends
n a similar type analysis -- the multipliction and the shift don't overflow
32-bit ints.  But care must be taken with multiplication by another 4 or
even 2.


Modified: head/sys/x86/x86/mp_x86.c
==
--- head/sys/x86/x86/mp_x86.c   Fri Apr  6 09:25:08 2018(r332091)
+++ head/sys/x86/x86/mp_x86.c   Fri Apr  6 11:20:06 2018(r332092)
@@ -160,6 +160,8 @@ struct cache_info {

unsigned int boot_address;

+#define MiB(v) (v ## ULL << 20)
+


In this file, the macro is used twice with v = 1.  Defining and using it
takes only about twice as much code and time to read as (vm_paddr_t)1 << 20.
Here it is more important to use vm_paddr_t since this code is shared by
amd64, i386 and i386-PAE so the size of vm_paddr_t is variable.  However,
since 1MB is far below INT_MAX, it doesn't take much type analysis to see
than the shorter 1 << 20 is safe.  2 copies of the clearer 1024 * 1024
is also shorter than the macro and 2 calls to it.

The macro name doesn't match the comment.  The comment still says 1MB.
The fix is not to break the comment.

Later in the file, basemem is converted from K to bytes by multiplying
by 1024.  Now 1024 is shorter and clearer than 1 << 10 or 0x400 or a
macro with many undocmented details.  The type analysis to show that
multiplying by 1024 doesn't overflow is slightly more complicated since
basemem is a variable.  It is only easy to see that this doesn't
overflow because basemem is an old real-mode value.  640K was large
enough for anyone, and basemem in bytes is less than that.  640K was
20 times INT_MAX, but is now 1/3276 of INT_MAX.

Bruce___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332099 - head/usr.sbin/syslogd

2018-04-06 Thread Ed Schouten
Author: ed
Date: Fri Apr  6 12:57:01 2018
New Revision: 332099
URL: https://svnweb.freebsd.org/changeset/base/332099

Log:
  Add RFC 5424 syslog message parsing to syslogd.
  
  Syslogd currently uses the RFC 3164 format for its log messages.One
  limitation of RFC 3164 is that it cannot be used to log entries with
  sub-second precision timestamps. One of our users has expressed a desire
  for doing this for doing some basic performance measurements.
  
  This change attempts to make a first cut at switching to RFC 5424 based
  logging. The first step is to alter syslogd's input path to properly
  parse such messages. It alters the logmsg() prototype to match the
  fields of RFC 5424. The parsemsg() function is extended to parse both
  RFC 3164 and 5424 messages and call into logmsg() accordingly.
  
  Additional changes include:
  
  - Introducing proper parsing of timestamps, so that they can be printed
in any desired output format. This means we need to infer the year and
timezone for RFC 3164 timestamps.
  - Removing ISKERNEL. This can now be realised by simply providing an
APP-NAME (== "kernel").
  - Extending RFC 3164 parsing to trim off the TAG prefix and using that
to derive APP-NAME and PROCID.
  - Increase MAXLINE. RFC 5424 mentions we should support 2k messages.
  
  Differential Revision:https://reviews.freebsd.org/D14926

Modified:
  head/usr.sbin/syslogd/syslogd.c

Modified: head/usr.sbin/syslogd/syslogd.c
==
--- head/usr.sbin/syslogd/syslogd.c Fri Apr  6 12:39:47 2018
(r332098)
+++ head/usr.sbin/syslogd/syslogd.c Fri Apr  6 12:57:01 2018
(r332099)
@@ -28,6 +28,33 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2018 Prodrive Technologies, https://prodrive-technologies.com/
+ * Author: Ed Schouten 
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ */
 
 #ifndef lint
 static const char copyright[] =
@@ -71,8 +98,7 @@ __FBSDID("$FreeBSD$");
  */
 
 /* Maximum number of characters in time of last occurrence */
-#defineMAXDATELEN  16
-#defineMAXLINE 1024/* maximum line length */
+#defineMAXLINE 2048/* maximum line length */
 #defineMAXSVLINE   MAXLINE /* maximum saved line length */
 #defineDEFUPRI (LOG_USER|LOG_NOTICE)
 #defineDEFSPRI (LOG_KERN|LOG_CRIT)
@@ -97,8 +123,8 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #endif
-#include 
 
+#include 
 #include 
 #include 
 #include 
@@ -107,6 +133,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -174,8 +201,17 @@ static STAILQ_HEAD(, socklist) shead = STAILQ_HEAD_INI
 #defineIGN_CONS0x001   /* don't print on console */
 #defineSYNC_FILE   0x002   /* do fsync on file after printing */
 #defineMARK0x008   /* this message is a mark */
-#defineISKERNEL0x010   /* kernel generated message */
 
+/* Timestamps of log entries. */
+struct logtime {
+   struct tm   tm;
+   suseconds_t usec;
+};
+
+/* Traditional syslog timestamp format. */
+#defineRFC3164_DATELEN 15
+#defineRFC3164_DATEFMT "%b %e %H:%M:%S"
+
 /*
  * This structure represents the files that will have log
  * copies printed.
@@ -215,10 +251,10 @@ struct filed {
 #definefu_pipe_pname   f_un.f_pipe.f_pname
 #definefu_pipe_pid f_un.f_pipe.f_pid
charf_prevline[MAXSVLINE];  /* last message logged */
- 

svn commit: r332100 - in head: . lib/libc/gen sys/sys

2018-04-06 Thread Ed Schouten
Author: ed
Date: Fri Apr  6 13:00:45 2018
New Revision: 332100
URL: https://svnweb.freebsd.org/changeset/base/332100

Log:
  Let syslog(3) use RFC 5424.
  
  With r332099 changing syslogd(8) to parse RFC 5424 formatted syslog
  messages, go ahead and also change the syslog(3) libc function to
  generate them. Compared to RFC 3164, RFC 5424 has various advantages,
  such as sub-second precision for log entry timestamps.
  
  As this change could have adverse effects when not updating syslogd(8)
  or using a different system logging daemon, add a notice to UPDATING and
  increase __FreeBSD_version.
  
  Differential Revision:https://reviews.freebsd.org/D14926

Modified:
  head/UPDATING
  head/lib/libc/gen/syslog.3
  head/lib/libc/gen/syslog.c
  head/sys/sys/param.h

Modified: head/UPDATING
==
--- head/UPDATING   Fri Apr  6 12:57:01 2018(r332099)
+++ head/UPDATING   Fri Apr  6 13:00:45 2018(r332100)
@@ -51,6 +51,45 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 12.x IS SLOW:
 
 ** SPECIAL WARNING: **
 
+20180406:
+   In addition to supporting RFC 3164 formatted messages, the
+   syslogd(8) service is now capable of parsing RFC 5424 formatted
+   log messages. The main benefit of using RFC 5424 is that clients
+   may now send log messages with timestamps containing year numbers,
+   microseconds and time zone offsets.
+
+   Similarly, the syslog(3) C library function has been altered to
+   send RFC 5424 formatted messages to the local system logging
+   daemon. On systems using syslogd(8), this change should have no
+   negative impact, as long as syslogd(8) and the C library are
+   updated at the same time. On systems using a different system
+   logging daemon, it may be necessary to make configuration
+   adjustments, depending on the software used.
+
+   When using syslog-ng, add the 'syslog-protocol' flag to local
+   input sources to enable parsing of RFC 5424 formatted messages:
+
+   source src {
+   unix-dgram("/var/run/log" flags(syslog-protocol));
+   }
+
+   When using rsyslog, disable the 'SysSock.UseSpecialParser' option
+   of the 'imuxsock' module to let messages be processed by the
+   regular RFC 3164/5424 parsing pipeline:
+
+   module(load="imuxsock" SysSock.UseSpecialParser="off")
+
+   Do note that these changes only affect communication between local
+   applications and syslogd(8). The format that syslogd(8) uses to
+   store messages on disk or forward messages to other systems
+   remains unchanged. syslogd(8) still uses RFC 3164 for these
+   purposes. Options to customize this behaviour will be added in the
+   future. Utilities that process log files stored in /var/log are
+   thus expected to continue to function as before.
+
+   __FreeBSD_version has been incremented to 1200061 to denote this
+   change.
+
 20180328:
Support for token ring networks has been removed. If you
have "device token" in your kernel config you should remove

Modified: head/lib/libc/gen/syslog.3
==
--- head/lib/libc/gen/syslog.3  Fri Apr  6 12:57:01 2018(r332099)
+++ head/lib/libc/gen/syslog.3  Fri Apr  6 13:00:45 2018(r332100)
@@ -28,7 +28,7 @@
 .\" @(#)syslog.3   8.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd November 5, 2017
+.Dd April 6, 2018
 .Dt SYSLOG 3
 .Os
 .Sh NAME
@@ -156,6 +156,9 @@ Write the message to standard error output as well to 
 .It Dv LOG_PID
 Log the process id with each message: useful for identifying
 instantiations of daemons.
+On
+.Fx ,
+this option is enabled by default.
 .El
 .Pp
 The

Modified: head/lib/libc/gen/syslog.c
==
--- head/lib/libc/gen/syslog.c  Fri Apr  6 12:57:01 2018(r332099)
+++ head/lib/libc/gen/syslog.c  Fri Apr  6 13:00:45 2018(r332100)
@@ -36,9 +36,10 @@ static char sccsid[] = "@(#)syslog.c 8.5 (Berkeley) 4/
 __FBSDID("$FreeBSD$");
 
 #include "namespace.h"
-#include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -134,11 +135,13 @@ syslog(int pri, const char *fmt, ...)
 static void
 vsyslog1(int pri, const char *fmt, va_list ap)
 {
-   int cnt;
+   struct timeval now;
+   struct tm tm;
char ch, *p;
-   time_t now;
-   int fd, saved_errno;
-   char *stdp, tbuf[2048], fmt_cpy[1024], timbuf[26], errstr[64];
+   long tz_offset;
+   int cnt, fd, saved_errno;
+   char hostname[MAXHOSTNAMELEN], *stdp, tbuf[2048], fmt_cpy[1024],
+   errstr[64], tz_sign;
  

Re: svn commit: r332092 - in head/sys: amd64/amd64 sys x86/x86

2018-04-06 Thread Conrad Meyer
I like something like this for clarity.  But I don't see any reason
for these function-like macros instead of the more general definition
of an SI prefix constant multiple.  A multiple works with numeric
literals and variables alike.  Something like:

#define GiB ((size_t)1 << 30)
my_foo = 15 * GiB;

(There's nothing byte-specific about SI prefixes, but "Gi" alone is a
worse name.  Arguably, size_t is wrong for quantities of bytes on
32-bit platforms with 64-bit off_t.)

The compiler will still reduce constant expressions.  Perhaps even
better, conversion away is straightforward units math, and the
compiler can still do the clever thing with right shifts:

my_gb = howmany(my_foo, GiB); //or
my_gb = my_foo / GiB;

Unfortunately, I expect a lot of code to already have defines or
variables with conflicting names, so I'm not sure adding these names
to primary headers is viable as-is.

Best,
Conrad

On Fri, Apr 6, 2018 at 4:20 AM, Roger Pau Monné  wrote:
> Author: royger
> Date: Fri Apr  6 11:20:06 2018
> New Revision: 332092
> URL: https://svnweb.freebsd.org/changeset/base/332092
>
> Log:
>   remove GiB/MiB macros from param.h
>
>   And instead define them in the files where they are used.
>
>   Requested by: bde
>
> Modified:
>   head/sys/amd64/amd64/mp_machdep.c
>   head/sys/sys/param.h
>   head/sys/x86/x86/mp_x86.c
>
> Modified: head/sys/amd64/amd64/mp_machdep.c
> ==
> --- head/sys/amd64/amd64/mp_machdep.c   Fri Apr  6 09:25:08 2018
> (r332091)
> +++ head/sys/amd64/amd64/mp_machdep.c   Fri Apr  6 11:20:06 2018
> (r332092)
> @@ -83,6 +83,8 @@ __FBSDID("$FreeBSD$");
>  #define BIOS_RESET (0x0f)
>  #define BIOS_WARM  (0x0a)
>
> +#define GiB(v) (v ## ULL << 30)
> +
>  extern struct pcpu __pcpu[];
>
>  /* Temporary variables for init_secondary()  */
>
> Modified: head/sys/sys/param.h
> ==
> --- head/sys/sys/param.hFri Apr  6 09:25:08 2018(r332091)
> +++ head/sys/sys/param.hFri Apr  6 11:20:06 2018(r332092)
> @@ -362,8 +362,4 @@ __END_DECLS
>   */
>  #define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset])
>
> -/* Unit conversion macros. */
> -#define GiB(v) (v ## ULL << 30)
> -#define MiB(v) (v ## ULL << 20)
> -
>  #endif /* _SYS_PARAM_H_ */
>
> Modified: head/sys/x86/x86/mp_x86.c
> ==
> --- head/sys/x86/x86/mp_x86.c   Fri Apr  6 09:25:08 2018(r332091)
> +++ head/sys/x86/x86/mp_x86.c   Fri Apr  6 11:20:06 2018(r332092)
> @@ -160,6 +160,8 @@ struct cache_info {
>
>  unsigned int boot_address;
>
> +#define MiB(v) (v ## ULL << 20)
> +
>  void
>  mem_range_AP_init(void)
>  {
>
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332101 - head/sys/netpfil/pf

2018-04-06 Thread Kristof Provost
Author: kp
Date: Fri Apr  6 15:01:45 2018
New Revision: 332101
URL: https://svnweb.freebsd.org/changeset/base/332101

Log:
  pf: Improve ioctl validation for DIOCRADDTABLES and DIOCRDELTABLES
  
  The DIOCRADDTABLES and DIOCRDELTABLES ioctls can process a number of
  tables at a time, and as such try to allocate  *
  sizeof(struct pfr_table). This multiplication can overflow. Thanks to
  mallocarray() this is not exploitable, but an overflow does panic the
  system.
  
  Arbitrarily limit this to 65535 tables. pfctl only ever processes one
  table at a time, so it presents no issues there.
  
  MFC after:1 week

Modified:
  head/sys/netpfil/pf/pf_ioctl.c

Modified: head/sys/netpfil/pf/pf_ioctl.c
==
--- head/sys/netpfil/pf/pf_ioctl.c  Fri Apr  6 13:00:45 2018
(r332100)
+++ head/sys/netpfil/pf/pf_ioctl.c  Fri Apr  6 15:01:45 2018
(r332101)
@@ -89,6 +89,8 @@ __FBSDID("$FreeBSD$");
 #include 
 #endif
 
+#define PF_TABLES_MAX_REQUEST   65535 /* Maximum tables per request. */
+
 static struct pf_pool  *pf_get_pool(char *, u_int32_t, u_int8_t, u_int32_t,
u_int8_t, u_int8_t, u_int8_t);
 
@@ -2530,13 +2532,15 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
-   totlen = io->pfrio_size * sizeof(struct pfr_table);
-   pfrts = mallocarray(io->pfrio_size, sizeof(struct pfr_table),
-   M_TEMP, M_WAITOK);
-   if (! pfrts) {
+
+   if (io->pfrio_size < 0 || io->pfrio_size > 
PF_TABLES_MAX_REQUEST) {
error = ENOMEM;
break;
}
+
+   totlen = io->pfrio_size * sizeof(struct pfr_table);
+   pfrts = mallocarray(io->pfrio_size, sizeof(struct pfr_table),
+   M_TEMP, M_WAITOK);
error = copyin(io->pfrio_buffer, pfrts, totlen);
if (error) {
free(pfrts, M_TEMP);
@@ -2559,13 +2563,15 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
-   totlen = io->pfrio_size * sizeof(struct pfr_table);
-   pfrts = mallocarray(io->pfrio_size, sizeof(struct pfr_table),
-   M_TEMP, M_WAITOK);
-   if (! pfrts) {
+
+   if (io->pfrio_size < 0 || io->pfrio_size > 
PF_TABLES_MAX_REQUEST) {
error = ENOMEM;
break;
}
+
+   totlen = io->pfrio_size * sizeof(struct pfr_table);
+   pfrts = mallocarray(io->pfrio_size, sizeof(struct pfr_table),
+   M_TEMP, M_WAITOK);
error = copyin(io->pfrio_buffer, pfrts, totlen);
if (error) {
free(pfrts, M_TEMP);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332102 - in head: etc/mtree tests/sys/netpfil/pf tests/sys/netpfil/pf/ioctl

2018-04-06 Thread Kristof Provost
Author: kp
Date: Fri Apr  6 15:03:48 2018
New Revision: 332102
URL: https://svnweb.freebsd.org/changeset/base/332102

Log:
  pf tests: Basic ioctl validation tests
  
  Validate the DIOCRADDTABLES and DIOCRDELTABLES ioctls with invalid size
  values. All of these requests should fail.
  
  MFC after:1 week

Added:
  head/tests/sys/netpfil/pf/ioctl/
  head/tests/sys/netpfil/pf/ioctl/Makefile   (contents, props changed)
  head/tests/sys/netpfil/pf/ioctl/validation.c   (contents, props changed)
Modified:
  head/etc/mtree/BSD.tests.dist
  head/tests/sys/netpfil/pf/Makefile

Modified: head/etc/mtree/BSD.tests.dist
==
--- head/etc/mtree/BSD.tests.dist   Fri Apr  6 15:01:45 2018
(r332101)
+++ head/etc/mtree/BSD.tests.dist   Fri Apr  6 15:03:48 2018
(r332102)
@@ -742,6 +742,8 @@
 ..
 netpfil
 pf
+ioctl
+..
 ..
 ..
 opencrypto

Modified: head/tests/sys/netpfil/pf/Makefile
==
--- head/tests/sys/netpfil/pf/Makefile  Fri Apr  6 15:01:45 2018
(r332101)
+++ head/tests/sys/netpfil/pf/Makefile  Fri Apr  6 15:03:48 2018
(r332102)
@@ -3,6 +3,7 @@
 PACKAGE=   tests
 
 TESTSDIR=   ${TESTSBASE}/sys/netpfil/pf
+TESTS_SUBDIRS+=ioctl
 
 ATF_TESTS_SH+= pass_block \
forward \

Added: head/tests/sys/netpfil/pf/ioctl/Makefile
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tests/sys/netpfil/pf/ioctl/MakefileFri Apr  6 15:03:48 2018
(r332102)
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+PACKAGE=   tests
+
+TESTSDIR=   ${TESTSBASE}/sys/netpfil/pf/ioctl
+
+ATF_TESTS_C += \
+   validation
+
+.include 

Added: head/tests/sys/netpfil/pf/ioctl/validation.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tests/sys/netpfil/pf/ioctl/validation.cFri Apr  6 15:03:48 
2018(r332102)
@@ -0,0 +1,130 @@
+/*-
+ * Copyright (c) 2018  Kristof Provost 
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+
+static int dev;
+
+#define COMMON_HEAD() \
+   if (modfind("pf") == -1) \
+   atf_tc_skip("pf not loaded"); \
+   dev = open("/dev/pf", O_RDWR); \
+   if (dev == -1) \
+   atf_tc_skip("Failed to open /dev/pf");
+
+#define COMMON_CLEANUP() \
+   close(dev);
+
+ATF_TC_WITHOUT_HEAD(addtables);
+ATF_TC_BODY(addtables, tc)
+{
+   struct pfioc_table io;
+   struct pfr_table tbl;
+   int flags;
+
+   COMMON_HEAD();
+
+   flags = 0;
+
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = flags;
+   io.pfrio_buffer = &tbl;
+   io.pfrio_esize = sizeof(tbl);
+
+   /* Negative size */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRADDTABLES, &io) == 0)
+   atf_tc_fail("Request with size -1 succeeded");
+
+   /* Overly large size */
+   io.pfrio_size = 1 << 24;
+   if (ioctl(dev, DIOCRADDTABLES, &io) == 0)
+   atf_tc_fail("Request with size 1 << 24 succeeded");
+
+   /* NULL buffer */
+   io.pfrio_size = 1;
+   io.pfrio_buffer = NULL;
+   if (ioctl(dev, DIOCRADDTABLES, &io) == 0)
+   atf_tc_fail("Request with NULL buffer succeeded");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(deltables);

svn commit: r332104 - head/sys/dev/ipmi

2018-04-06 Thread Jonathan T. Looney
Author: jtl
Date: Fri Apr  6 15:15:21 2018
New Revision: 332104
URL: https://svnweb.freebsd.org/changeset/base/332104

Log:
  In cases where an application issues certain IPMI commands at a high
  enough rate, the IPMI code can print large numbers of messages to the
  console, such as:
ipmi0: KCS: Failed to read completion code
ipmi0: KCS error: ff
ipmi0: KCS: Failed to read completion code
ipmi0: KCS error: ff
  
  These seem to be innocuous from a system standpoint, and the user-
  space code can deal with the failures. Therefore, suppress printing
  these messages to the console unless bootverbose is enabled.
  
  Obtained from:Netflix, Inc.

Modified:
  head/sys/dev/ipmi/ipmi_kcs.c

Modified: head/sys/dev/ipmi/ipmi_kcs.c
==
--- head/sys/dev/ipmi/ipmi_kcs.cFri Apr  6 15:09:30 2018
(r332103)
+++ head/sys/dev/ipmi/ipmi_kcs.cFri Apr  6 15:15:21 2018
(r332104)
@@ -150,7 +150,7 @@ kcs_error(struct ipmi_softc *sc)
 
/* Read error status */
data = INB(sc, KCS_DATA);
-   if (data != 0)
+   if (data != 0 && (data != 0xff || bootverbose))
device_printf(sc->ipmi_dev, "KCS error: %02x\n",
data);
 
@@ -416,8 +416,10 @@ kcs_polled_request(struct ipmi_softc *sc, struct ipmi_
 
/* Next we read the completion code. */
if (kcs_read_byte(sc, &req->ir_compcode) != 1) {
-   device_printf(sc->ipmi_dev,
-   "KCS: Failed to read completion code\n");
+   if (bootverbose) {
+   device_printf(sc->ipmi_dev,
+   "KCS: Failed to read completion code\n");
+   }
goto fail;
}
 #ifdef KCS_DEBUG
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332105 - head/sys/arm/allwinner

2018-04-06 Thread Kyle Evans
Author: kevans
Date: Fri Apr  6 15:17:09 2018
New Revision: 332105
URL: https://svnweb.freebsd.org/changeset/base/332105

Log:
  aw_sid(4): Use prctl read for all reads when it's required
  
  It was later found that some operation on the OrangePi one will cause
  direct accesses to the eeprom to return wrong data again, so reading it all
  once via prctl at attach time is no longer sufficient.

Modified:
  head/sys/arm/allwinner/aw_sid.c

Modified: head/sys/arm/allwinner/aw_sid.c
==
--- head/sys/arm/allwinner/aw_sid.c Fri Apr  6 15:15:21 2018
(r332104)
+++ head/sys/arm/allwinner/aw_sid.c Fri Apr  6 15:17:09 2018
(r332105)
@@ -61,8 +61,11 @@ __FBSDID("$FreeBSD$");
 #defineSID_RDKEY   0x60
 
 #defineSID_SRAM0x200
-#defineSID_THERMAL_CALIB0  (SID_SRAM + 0x34)
-#defineSID_THERMAL_CALIB1  (SID_SRAM + 0x38)
+/* Offsets into efuse space, for convenience */
+#defineSID_THERMAL_CALIB0_OFF  (0x34)
+#defineSID_THERMAL_CALIB1_OFF  (0x38)
+#defineSID_THERMAL_CALIB0  (SID_SRAM + SID_THERMAL_CALIB0_OFF)
+#defineSID_THERMAL_CALIB1  (SID_SRAM + SID_THERMAL_CALIB1_OFF)
 
 #defineROOT_KEY_SIZE   4
 
@@ -116,6 +119,7 @@ static struct ofw_compat_data compat_data[] = {
 };
 
 struct aw_sid_softc {
+   device_tsid_dev;
struct resource *res;
struct aw_sid_conf  *sid_conf;
struct mtx  prctl_mtx;
@@ -135,6 +139,8 @@ enum sid_keys {
 #defineRD4(sc, reg)bus_read_4((sc)->res, (reg))
 #defineWR4(sc, reg, val)   bus_write_4((sc)->res, (reg), (val))
 
+#definePRCTL_RD4(sc, reg, val) aw_sid_prctl_read((sc)->sid_dev, (reg), 
(val))
+
 static int aw_sid_sysctl(SYSCTL_HANDLER_ARGS);
 static int aw_sid_prctl_read(device_t dev, bus_size_t offset, uint32_t *val);
 
@@ -183,10 +189,9 @@ static int
 aw_sid_attach(device_t dev)
 {
struct aw_sid_softc *sc;
-   bus_size_t i;
-   uint32_t val;
 
sc = device_get_softc(dev);
+   sc->sid_dev = dev;
 
if (bus_alloc_resources(dev, aw_sid_spec, &sc->res) != 0) {
device_printf(dev, "cannot allocate resources for device\n");
@@ -197,19 +202,6 @@ aw_sid_attach(device_t dev)
sc->sid_conf = (struct aw_sid_conf *)ofw_bus_search_compatible(dev, 
compat_data)->ocd_data;
aw_sid_sc = sc;
 
-   /*
-* This set of reads is solely for working around a silicon bug on some
-* SoC that require a prctl read in order for direct register access to
-* return a non-garbled value. Hence, the values we read are simply
-* ignored.
-*/
-   if (sc->sid_conf->requires_prctl_read)
-   for (i = 0; i < sc->sid_conf->efuse_size; i += 4)
-   if (aw_sid_prctl_read(dev, i, &val) != 0) {
-   device_printf(dev, "failed prctl read\n");
-   goto fail;
-   }
-
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "rootkey",
@@ -217,11 +209,6 @@ aw_sid_attach(device_t dev)
dev, AW_SID_ROOT_KEY, aw_sid_sysctl, "A", "Root Key");
 
return (0);
-
-fail:
-   bus_release_resources(dev, aw_sid_spec, &sc->res);
-   mtx_destroy(&sc->prctl_mtx);
-   return (ENXIO);
 }
 
 int
@@ -235,8 +222,13 @@ aw_sid_read_tscalib(uint32_t *calib0, uint32_t *calib1
if (!sc->sid_conf->has_thermal)
return (ENXIO);
 
-   *calib0 = RD4(sc, SID_THERMAL_CALIB0);
-   *calib1 = RD4(sc, SID_THERMAL_CALIB1);
+   if (sc->sid_conf->requires_prctl_read) {
+   PRCTL_RD4(sc, SID_THERMAL_CALIB0_OFF, calib0);
+   PRCTL_RD4(sc, SID_THERMAL_CALIB1_OFF, calib1);
+   } else {
+   *calib0 = RD4(sc, SID_THERMAL_CALIB0);
+   *calib1 = RD4(sc, SID_THERMAL_CALIB1);
+   }
 
return (0);
 }
@@ -254,7 +246,10 @@ aw_sid_get_rootkey(u_char *out)
return (ENXIO);
root_key_off = aw_sid_sc->sid_conf->rootkey_offset;
for (i = 0; i < ROOT_KEY_SIZE ; i++) {
-   tmp = RD4(aw_sid_sc, root_key_off + (i * 4));
+   if (sc->sid_conf->requires_prctl_read)
+   PRCTL_RD4(sc, (i * 4), &tmp);
+   else
+   tmp = RD4(aw_sid_sc, root_key_off + (i * 4));
be32enc(&out[i * 4], tmp);
}
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332106 - head/stand/lua

2018-04-06 Thread Kyle Evans
Author: kevans
Date: Fri Apr  6 15:19:48 2018
New Revision: 332106
URL: https://svnweb.freebsd.org/changeset/base/332106

Log:
  lualoader: Fix menu skipping with loader.conf(5) vars
  
  Earlier efforts to stop loading the menu broke the ability to skip the menu
  with, e.g., beastie_disable in loader.conf(5) as it was decided before
  configuration was read.
  
  Defer bringing in the menu module until we've loaded configuration so that
  we can make a more informed decision on whether the menu should be skipped
  or not.

Modified:
  head/stand/lua/loader.lua

Modified: head/stand/lua/loader.lua
==
--- head/stand/lua/loader.lua   Fri Apr  6 15:17:09 2018(r332105)
+++ head/stand/lua/loader.lua   Fri Apr  6 15:19:48 2018(r332106)
@@ -37,15 +37,17 @@ require("cli")
 local color = require("color")
 local core = require("core")
 local config = require("config")
-local menu
-if not core.isMenuSkipped() then
-   menu = require("menu")
-end
 local password = require("password")
+-- The menu module will be brought in after config has loaded if we actually
+-- need it.
+local menu
 
 try_include("local")
 
 config.load()
+if not core.isMenuSkipped() then
+   menu = require("menu")
+end
 if core.isUEFIBoot() then
loader.perform("efi-autoresizecons")
 end
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332107 - in head/sys: net netpfil/pf

2018-04-06 Thread Kristof Provost
Author: kp
Date: Fri Apr  6 15:54:30 2018
New Revision: 332107
URL: https://svnweb.freebsd.org/changeset/base/332107

Log:
  pf: Improve ioctl validation for DIOCRGETTABLES, DIOCRGETTSTATS, 
DIOCRCLRTSTATS and DIOCRSETTFLAGS
  
  These ioctls can process a number of items at a time, which puts us at
  risk of overflow in mallocarray() and of impossibly large allocations
  even if we don't overflow.
  
  Limit the allocation to required size (or the user allocation, if that's
  smaller). That does mean we need to do the allocation with the rules
  lock held (so the number doesn't change while we're doing this), so it
  can't M_WAITOK.
  
  MFC after:1 week

Modified:
  head/sys/net/pfvar.h
  head/sys/netpfil/pf/pf_ioctl.c
  head/sys/netpfil/pf/pf_table.c

Modified: head/sys/net/pfvar.h
==
--- head/sys/net/pfvar.hFri Apr  6 15:19:48 2018(r332106)
+++ head/sys/net/pfvar.hFri Apr  6 15:54:30 2018(r332107)
@@ -1638,6 +1638,7 @@ void  pfr_detach_table(struct pfr_ktable *);
 intpfr_clr_tables(struct pfr_table *, int *, int);
 intpfr_add_tables(struct pfr_table *, int, int *, int);
 intpfr_del_tables(struct pfr_table *, int, int *, int);
+intpfr_table_count(struct pfr_table *, int);
 intpfr_get_tables(struct pfr_table *, struct pfr_table *, int *, int);
 intpfr_get_tstats(struct pfr_table *, struct pfr_tstats *, int *, int);
 intpfr_clr_tstats(struct pfr_table *, int, int *, int);

Modified: head/sys/netpfil/pf/pf_ioctl.c
==
--- head/sys/netpfil/pf/pf_ioctl.c  Fri Apr  6 15:19:48 2018
(r332106)
+++ head/sys/netpfil/pf/pf_ioctl.c  Fri Apr  6 15:54:30 2018
(r332107)
@@ -2588,20 +2588,25 @@ DIOCCHANGEADDR_error:
case DIOCRGETTABLES: {
struct pfioc_table *io = (struct pfioc_table *)addr;
struct pfr_table *pfrts;
-   size_t totlen;
+   size_t totlen, n;
 
if (io->pfrio_esize != sizeof(struct pfr_table)) {
error = ENODEV;
break;
}
+   PF_RULES_RLOCK();
+   n = pfr_table_count(&io->pfrio_table, io->pfrio_flags);
+   io->pfrio_size = min(io->pfrio_size, n);
+
totlen = io->pfrio_size * sizeof(struct pfr_table);
+
pfrts = mallocarray(io->pfrio_size, sizeof(struct pfr_table),
-   M_TEMP, M_WAITOK);
-   if (! pfrts) {
+   M_TEMP, M_NOWAIT);
+   if (pfrts == NULL) {
error = ENOMEM;
+   PF_RULES_RUNLOCK();
break;
}
-   PF_RULES_RLOCK();
error = pfr_get_tables(&io->pfrio_table, pfrts,
&io->pfrio_size, io->pfrio_flags | PFR_FLAG_USERIOCTL);
PF_RULES_RUNLOCK();
@@ -2614,20 +2619,24 @@ DIOCCHANGEADDR_error:
case DIOCRGETTSTATS: {
struct pfioc_table *io = (struct pfioc_table *)addr;
struct pfr_tstats *pfrtstats;
-   size_t totlen;
+   size_t totlen, n;
 
if (io->pfrio_esize != sizeof(struct pfr_tstats)) {
error = ENODEV;
break;
}
+   PF_RULES_WLOCK();
+   n = pfr_table_count(&io->pfrio_table, io->pfrio_flags);
+   io->pfrio_size = min(io->pfrio_size, n);
+
totlen = io->pfrio_size * sizeof(struct pfr_tstats);
pfrtstats = mallocarray(io->pfrio_size,
-   sizeof(struct pfr_tstats), M_TEMP, M_WAITOK);
-   if (! pfrtstats) {
+   sizeof(struct pfr_tstats), M_TEMP, M_NOWAIT);
+   if (pfrtstats == NULL) {
error = ENOMEM;
+   PF_RULES_WUNLOCK();
break;
}
-   PF_RULES_WLOCK();
error = pfr_get_tstats(&io->pfrio_table, pfrtstats,
&io->pfrio_size, io->pfrio_flags | PFR_FLAG_USERIOCTL);
PF_RULES_WUNLOCK();
@@ -2640,25 +2649,31 @@ DIOCCHANGEADDR_error:
case DIOCRCLRTSTATS: {
struct pfioc_table *io = (struct pfioc_table *)addr;
struct pfr_table *pfrts;
-   size_t totlen;
+   size_t totlen, n;
 
if (io->pfrio_esize != sizeof(struct pfr_table)) {
error = ENODEV;
break;
}
+
+   PF_RULES_WLOCK();
+   n = pfr_table_count(&io->pfrio_table, io->pfrio_flags);
+   io->pfrio_size = min(io->pfrio_size, n);
+
totlen = io->pfrio_size * sizeof(struct pfr_table);
pfrts = mallocarray(io->pfrio_size, si

svn commit: r332108 - head/tests/sys/netpfil/pf/ioctl

2018-04-06 Thread Kristof Provost
Author: kp
Date: Fri Apr  6 15:57:20 2018
New Revision: 332108
URL: https://svnweb.freebsd.org/changeset/base/332108

Log:
  pf tests: Basic ioctl validation for DIOCRGETTABLES, DIOCRGETTSTATS, 
DIOCRCLRTSTATS and DIOCRSETTFLAGS
  
  Validate the DIOCRGETTABLES, DIOCRGETTSTATS, DIOCRCLRTSTATS and
  DIOCRSETTFLAGS ioctls with invalid values. These may succeed (because
  the kernel uses the minimally required size, not the specified size),
  but should not trigger kernel panics.
  
  MFC after:1 week

Modified:
  head/tests/sys/netpfil/pf/ioctl/validation.c

Modified: head/tests/sys/netpfil/pf/ioctl/validation.c
==
--- head/tests/sys/netpfil/pf/ioctl/validation.cFri Apr  6 15:54:30 
2018(r332107)
+++ head/tests/sys/netpfil/pf/ioctl/validation.cFri Apr  6 15:57:20 
2018(r332108)
@@ -51,6 +51,16 @@ static int dev;
 #define COMMON_CLEANUP() \
close(dev);
 
+void
+common_init_tbl(struct pfr_table *tbl)
+{
+   bzero(tbl, sizeof(struct pfr_table));
+   strcpy(tbl->pfrt_anchor, "anchor");
+   strcpy(tbl->pfrt_name, "name");
+   tbl->pfrt_flags = 0;
+   tbl->pfrt_fback = 0;
+}
+
 ATF_TC_WITHOUT_HEAD(addtables);
 ATF_TC_BODY(addtables, tc)
 {
@@ -121,10 +131,138 @@ ATF_TC_BODY(deltables, tc)
COMMON_CLEANUP();
 }
 
+ATF_TC_WITHOUT_HEAD(gettables);
+ATF_TC_BODY(gettables, tc)
+{
+   struct pfioc_table io;
+   struct pfr_table tbl;
+   int flags;
+
+   COMMON_HEAD();
+
+   flags = 0;
+
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = flags;
+   io.pfrio_buffer = &tbl;
+   io.pfrio_esize = sizeof(tbl);
+
+   /* Negative size. This will succeed, because the kernel will not copy
+* tables than it has. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRGETTABLES, &io) != 0)
+   atf_tc_fail("Request with size -1 failed");
+
+   /* Overly large size. See above. */
+   io.pfrio_size = 1 << 24;
+   if (ioctl(dev, DIOCRGETTABLES, &io) != 0)
+   atf_tc_fail("Request with size 1 << 24 failed");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(gettstats);
+ATF_TC_BODY(gettstats, tc)
+{
+   struct pfioc_table io;
+   struct pfr_tstats stats;
+   int flags;
+
+   COMMON_HEAD();
+
+   flags = 0;
+
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = flags;
+   io.pfrio_buffer = &stats;
+   io.pfrio_esize = sizeof(stats);
+
+   /* Negative size. This will succeed, because the kernel will not copy
+* tables than it has. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRGETTSTATS, &io) != 0)
+   atf_tc_fail("Request with size -1 failed");
+
+   /* Overly large size. See above. */
+   io.pfrio_size = 1 << 24;
+   if (ioctl(dev, DIOCRGETTSTATS, &io) != 0)
+   atf_tc_fail("Request with size 1 << 24 failed");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(clrtstats);
+ATF_TC_BODY(clrtstats, tc)
+{
+   struct pfioc_table io;
+   struct pfr_table tbl;
+   int flags;
+
+   COMMON_HEAD();
+
+   flags = 0;
+
+   common_init_tbl(&tbl);
+
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = flags;
+   io.pfrio_buffer = &tbl;
+   io.pfrio_esize = sizeof(tbl);
+
+   /* Negative size. This will succeed, because the kernel will not copy
+* tables than it has. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRCLRTSTATS, &io) != 0)
+   atf_tc_fail("Request with size -1 failed ");
+
+   /* Overly large size. See above. */
+   io.pfrio_size = 1 << 24;
+   if (ioctl(dev, DIOCRCLRTSTATS, &io) != 0)
+   atf_tc_fail("Request with size 1 << 24 failed");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(settflags);
+ATF_TC_BODY(settflags, tc)
+{
+   struct pfioc_table io;
+   struct pfr_table tbl;
+   int flags;
+
+   COMMON_HEAD();
+
+   flags = 0;
+
+   common_init_tbl(&tbl);
+
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = flags;
+   io.pfrio_buffer = &tbl;
+   io.pfrio_esize = sizeof(tbl);
+
+   /* Negative size. This will succeed, because the kernel will not copy
+* tables than it has. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRSETTFLAGS, &io) != 0)
+   atf_tc_fail("Request with size -1 failed");
+
+   /* Overly large size. See above. */
+   io.pfrio_size = 1 << 28;
+   if (ioctl(dev, DIOCRSETTFLAGS, &io) != 0)
+   atf_tc_fail("Request with size 1 << 24 failed");
+
+   COMMON_CLEANUP();
+}
+
 ATF_TP_ADD_TCS(tp)
 {
ATF_TP_ADD_TC(tp, addtables);
ATF_TP_ADD_TC(tp, deltables);
+   ATF_TP_ADD_TC(tp, gettables);
+   ATF_TP_ADD_TC(tp, gettstats);
+   ATF_TP_ADD_TC(tp, clrtstats);
+   ATF_TP_ADD_TC(tp, settflags);
 
return (atf_no_error());
 }
_

Re: svn commit: r332092 - in head/sys: amd64/amd64 sys x86/x86

2018-04-06 Thread Rodney W. Grimes
[ Charset UTF-8 unsupported, converting... ]
> Author: royger
> Date: Fri Apr  6 11:20:06 2018
> New Revision: 332092
> URL: https://svnweb.freebsd.org/changeset/base/332092
> 
> Log:
>   remove GiB/MiB macros from param.h
>   
>   And instead define them in the files where they are used.

It would of been better to "revert" your prior change and
make a seperate new commit.  It is rarely desireable to combine
a revert of a change with anything.


>   Requested by: bde
> 
> Modified:
>   head/sys/amd64/amd64/mp_machdep.c
>   head/sys/sys/param.h
>   head/sys/x86/x86/mp_x86.c
> 
> Modified: head/sys/amd64/amd64/mp_machdep.c
...

-- 
Rod Grimes rgri...@freebsd.org
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332109 - in head/sys: amd64/amd64 x86/x86

2018-04-06 Thread Roger Pau Monné
Author: royger
Date: Fri Apr  6 16:22:14 2018
New Revision: 332109
URL: https://svnweb.freebsd.org/changeset/base/332109

Log:
  x86: fix trampoline memory allocation after r332073
  
  Add the missing breaks in the for loops, in order to exit the loop
  when a suitable entry is found.
  
  Also switch amd64 native_start_all_aps to use PHYS_TO_DMAP in order to
  find the virtual address of the boot_trampoline and the initial page
  tables.
  
  Reported and tested by:   pho
  Sponsored by: Citrix Systems R&D

Modified:
  head/sys/amd64/amd64/mp_machdep.c
  head/sys/x86/x86/mp_x86.c

Modified: head/sys/amd64/amd64/mp_machdep.c
==
--- head/sys/amd64/amd64/mp_machdep.c   Fri Apr  6 15:57:20 2018
(r332108)
+++ head/sys/amd64/amd64/mp_machdep.c   Fri Apr  6 16:22:14 2018
(r332109)
@@ -128,6 +128,7 @@ mp_bootaddress(vm_paddr_t *physmap, unsigned int *phys
sizeof(*physmap) * (*physmap_idx - i + 2));
*physmap_idx -= 2;
}
+   break;
}
 
if (!allocated) {
@@ -336,7 +337,6 @@ init_secondary(void)
 int
 native_start_all_aps(void)
 {
-   vm_offset_t va = boot_address + KERNBASE;
u_int64_t *pt4, *pt3, *pt2;
u_int32_t mpbioswarmvec;
int apic_id, cpu, i;
@@ -344,13 +344,11 @@ native_start_all_aps(void)
 
mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
 
-   /* install the AP 1st level boot code */
-   pmap_kenter(va, boot_address);
-   pmap_invalidate_page(kernel_pmap, va);
-   bcopy(mptramp_start, (void *)va, bootMP_size);
+   /* copy the AP 1st level boot code */
+   bcopy(mptramp_start, (void *)PHYS_TO_DMAP(boot_address), bootMP_size);
 
/* Locate the page tables, they'll be below the trampoline */
-   pt4 = (u_int64_t *)(uintptr_t)(mptramp_pagetables + KERNBASE);
+   pt4 = (uint64_t *)PHYS_TO_DMAP(mptramp_pagetables);
pt3 = pt4 + (PAGE_SIZE) / sizeof(u_int64_t);
pt2 = pt3 + (PAGE_SIZE) / sizeof(u_int64_t);
 

Modified: head/sys/x86/x86/mp_x86.c
==
--- head/sys/x86/x86/mp_x86.c   Fri Apr  6 15:57:20 2018(r332108)
+++ head/sys/x86/x86/mp_x86.c   Fri Apr  6 16:22:14 2018(r332109)
@@ -947,6 +947,7 @@ alloc_ap_trampoline(vm_paddr_t *physmap, unsigned int 
sizeof(*physmap) * (*physmap_idx - i + 2));
*physmap_idx -= 2;
}
+   break;
}
 
if (!allocated) {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332110 - head/usr.sbin/syslogd

2018-04-06 Thread Ed Schouten
Author: ed
Date: Fri Apr  6 16:24:03 2018
New Revision: 332110
URL: https://svnweb.freebsd.org/changeset/base/332110

Log:
  Properly respect the passed in hostname for RFC 5424 messages.
  
  Only override the hostname in case none is provided or when remote
  hostnames should be ignored.

Modified:
  head/usr.sbin/syslogd/syslogd.c

Modified: head/usr.sbin/syslogd/syslogd.c
==
--- head/usr.sbin/syslogd/syslogd.c Fri Apr  6 16:22:14 2018
(r332109)
+++ head/usr.sbin/syslogd/syslogd.c Fri Apr  6 16:24:03 2018
(r332110)
@@ -1028,6 +1028,8 @@ parsemsg_rfc5424(const char *from, int pri, char *msg)
msg[-1] = '\0'; \
}
PARSE_STRING("HOSTNAME", hostname);
+   if (hostname == NULL || !RemoteHostname)
+   hostname = from;
PARSE_STRING("APP-NAME", app_name);
PARSE_STRING("PROCID", procid);
PARSE_STRING("MSGID", msgid);
@@ -1079,7 +1081,7 @@ parsemsg_rfc5424(const char *from, int pri, char *msg)
 #undef IF_NOT_NILVALUE
 
parsemsg_remove_unsafe_characters(msg, line, sizeof(line));
-   logmsg(pri, timestamp, from, app_name, procid, msgid,
+   logmsg(pri, timestamp, hostname, app_name, procid, msgid,
structured_data, line, 0);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332111 - head/usr.sbin/syslogd

2018-04-06 Thread Ed Schouten
Author: ed
Date: Fri Apr  6 16:26:46 2018
New Revision: 332111
URL: https://svnweb.freebsd.org/changeset/base/332111

Log:
  Remove some places where error messages are prefixed with "syslogd".
  
  Due to using RFC 5424, the application name is stored in a dedicated
  field. It can simply be passed as an argument to logmsg() now.

Modified:
  head/usr.sbin/syslogd/syslogd.c

Modified: head/usr.sbin/syslogd/syslogd.c
==
--- head/usr.sbin/syslogd/syslogd.c Fri Apr  6 16:24:03 2018
(r332110)
+++ head/usr.sbin/syslogd/syslogd.c Fri Apr  6 16:26:46 2018
(r332111)
@@ -1991,7 +1991,7 @@ domark(int signo __unused)
  * Print syslogd errors some place.
  */
 static void
-logerror(const char *type)
+logerror(const char *msg)
 {
char buf[512];
static int recursed = 0;
@@ -2000,15 +2000,15 @@ logerror(const char *type)
if (recursed)
return;
recursed++;
-   if (errno)
-   (void)snprintf(buf,
-   sizeof buf, "syslogd: %s: %s", type, strerror(errno));
-   else
-   (void)snprintf(buf, sizeof buf, "syslogd: %s", type);
+   if (errno != 0) {
+   (void)snprintf(buf, sizeof(buf), "%s: %s", msg,
+   strerror(errno));
+   msg = buf;
+   }
errno = 0;
dprintf("%s\n", buf);
-   logmsg(LOG_SYSLOG|LOG_ERR, NULL, LocalHostName, NULL, NULL, NULL,
-   NULL, buf, 0);
+   logmsg(LOG_SYSLOG|LOG_ERR, NULL, LocalHostName, "syslogd", NULL, NULL,
+   NULL, msg, 0);
recursed--;
 }
 
@@ -2355,18 +2355,18 @@ init(int signo)
}
}
 
-   logmsg(LOG_SYSLOG|LOG_INFO, NULL, LocalHostName, NULL, NULL, NULL,
-   NULL, "syslogd: restart", 0);
+   logmsg(LOG_SYSLOG | LOG_INFO, NULL, LocalHostName, "syslogd", NULL,
+   NULL, NULL, "restart", 0);
dprintf("syslogd: restarted\n");
/*
 * Log a change in hostname, but only on a restart.
 */
if (signo != 0 && strcmp(oldLocalHostName, LocalHostName) != 0) {
(void)snprintf(hostMsg, sizeof(hostMsg),
-   "syslogd: hostname changed, \"%s\" to \"%s\"",
+   "hostname changed, \"%s\" to \"%s\"",
oldLocalHostName, LocalHostName);
-   logmsg(LOG_SYSLOG|LOG_INFO, NULL, LocalHostName, NULL, NULL,
-   NULL, NULL, hostMsg, 0);
+   logmsg(LOG_SYSLOG | LOG_INFO, NULL, LocalHostName, "syslogd",
+   NULL, NULL, NULL, hostMsg, 0);
dprintf("%s\n", hostMsg);
}
/*
@@ -2375,9 +2375,9 @@ init(int signo)
 */
if (signo == 0 && !use_bootfile) {
(void)snprintf(bootfileMsg, sizeof(bootfileMsg),
-   "syslogd: kernel boot file is %s", bootfile);
-   logmsg(LOG_KERN|LOG_INFO, NULL, LocalHostName, NULL, NULL,
-   NULL, NULL, bootfileMsg, 0);
+   "kernel boot file is %s", bootfile);
+   logmsg(LOG_KERN | LOG_INFO, NULL, LocalHostName, "syslogd",
+   NULL, NULL, NULL, bootfileMsg, 0);
dprintf("%s\n", bootfileMsg);
}
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332114 - head/sys/netinet

2018-04-06 Thread Jonathan T. Looney
Author: jtl
Date: Fri Apr  6 16:48:11 2018
New Revision: 332114
URL: https://svnweb.freebsd.org/changeset/base/332114

Log:
  Check that in_pcbfree() is only called once for each PCB.  If that
  assumption is violated, "bad things" could follow.
  
  I believe such an assert would have detected some of the problems jch@
  was chasing in PR 203175 (see r307551).  We also use it in our internal
  TCP development efforts.  And, in case a bug does slip through to
  released code, this change silently ignores subsequent calls to
  in_pcbfree().
  
  Reviewed by:  rrs
  Sponsored by: Netflix, Inc.
  Differential Revision:https://reviews.freebsd.org/D14990

Modified:
  head/sys/netinet/in_pcb.c

Modified: head/sys/netinet/in_pcb.c
==
--- head/sys/netinet/in_pcb.c   Fri Apr  6 16:48:07 2018(r332113)
+++ head/sys/netinet/in_pcb.c   Fri Apr  6 16:48:11 2018(r332114)
@@ -1288,6 +1288,13 @@ in_pcbfree(struct inpcb *inp)
 
KASSERT(inp->inp_socket == NULL, ("%s: inp_socket != NULL", __func__));
 
+   KASSERT((inp->inp_flags2 & INP_FREED) == 0,
+   ("%s: called twice for pcb %p", __func__, inp));
+   if (inp->inp_flags2 & INP_FREED) {
+   INP_WUNLOCK(inp);
+   return;
+   }
+
 #ifdef INVARIANTS
if (pcbinfo == &V_tcbinfo) {
INP_INFO_LOCK_ASSERT(pcbinfo);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332117 - head/sys/amd64/amd64

2018-04-06 Thread Jonathan T. Looney
Author: jtl
Date: Fri Apr  6 17:06:22 2018
New Revision: 332117
URL: https://svnweb.freebsd.org/changeset/base/332117

Log:
  Pat the watchdog less while producing a coredump.  Prior to this change,
  we patted the watchdog approximately once per 4KB page of memory.  After
  this change, we pat the watchdog approximately once per 128MB of memory.
  On a sample machine, this translated to patting the watchdog approximately
  every 5.4 seconds, which "seems reasonable". We can choose a different
  value in the future, if warranted.
  
  This has extensive field experience. It is a performance improvement, and
  has not caused any known problems.
  
  Reviewed by:  imp, kib
  Sponsored by: Netflix, Inc.
  Differential Revision:https://reviews.freebsd.org/D14988

Modified:
  head/sys/amd64/amd64/minidump_machdep.c

Modified: head/sys/amd64/amd64/minidump_machdep.c
==
--- head/sys/amd64/amd64/minidump_machdep.c Fri Apr  6 17:04:21 2018
(r332116)
+++ head/sys/amd64/amd64/minidump_machdep.c Fri Apr  6 17:06:22 2018
(r332117)
@@ -62,7 +62,7 @@ static struct kerneldumpheader kdh;
 /* Handle chunked writes. */
 static size_t fragsz;
 static void *dump_va;
-static size_t counter, progress, dumpsize;
+static size_t counter, progress, dumpsize, wdog_next;
 
 CTASSERT(sizeof(*vm_page_dump) == 8);
 static int dump_retry_count = 5;
@@ -134,6 +134,9 @@ report_progress(size_t progress, size_t dumpsize)
}
 }
 
+/* Pat the watchdog approximately every 128MB of the dump. */
+#defineWDOG_DUMP_INTERVAL  (128 * 1024 * 1024)
+
 static int
 blk_write(struct dumperinfo *di, char *ptr, vm_paddr_t pa, size_t sz)
 {
@@ -173,9 +176,14 @@ blk_write(struct dumperinfo *di, char *ptr, vm_paddr_t
report_progress(progress, dumpsize);
counter &= (1<<24) - 1;
}
+   if (progress <= wdog_next) {
+   wdog_kern_pat(WD_LASTVAL);
+   if (wdog_next > WDOG_DUMP_INTERVAL)
+   wdog_next -= WDOG_DUMP_INTERVAL;
+   else
+   wdog_next = 0;
+   }
 
-   wdog_kern_pat(WD_LASTVAL);
-
if (ptr) {
error = dump_append(di, ptr, 0, len);
if (error)
@@ -313,7 +321,7 @@ minidumpsys(struct dumperinfo *di)
}
dumpsize += PAGE_SIZE;
 
-   progress = dumpsize;
+   wdog_next = progress = dumpsize;
 
/* Initialize mdhdr */
bzero(&mdhdr, sizeof(mdhdr));
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332118 - head/usr.sbin/syslogd

2018-04-06 Thread Ed Schouten
Author: ed
Date: Fri Apr  6 17:16:50 2018
New Revision: 332118
URL: https://svnweb.freebsd.org/changeset/base/332118

Log:
  Push RFC 5424 message format from logmsg() into fprintlog().
  
  Now that all of parsemsg() parses both RFC 3164 and 5424 messages and
  hands them to logmsg(), alter the latter to properly forward all RFC
  5424 message attributes to fprintlog(). While there, make some minor
  cleanups to this code:
  
  - Instead of extending the existing code that compares hostnames and
message bodies for deduplication, print all of the relevant message
fields into a single string that we can compare ('saved').
  
  - No longer let the behaviour of fprintflog() depend on whether
'msg == NULL' to print repetition messages, Simply decompose this
function into fprintlog_first() and fprintlog_successive(). This
makes the interpretation of function arguments less magical and also
allows us to get consistent behaviour across RFC 3164 and 5424 when
adding support for the RFC 5424 output format.
  
  - As RFC 5424 syslog messages have a dedicated application name field,
alter the repetition messages to be printed on behalf of syslogd on
the current system. Change these messages to use the local hostname,
so that it's obvious which syslogd instance detected the repetition.
Remove f_prevhost, as it has now become unnecessary.
  
  - Remove a useless strdup(). Deconsting the message string is safe in
this specific case.

Modified:
  head/usr.sbin/syslogd/syslogd.c

Modified: head/usr.sbin/syslogd/syslogd.c
==
--- head/usr.sbin/syslogd/syslogd.c Fri Apr  6 17:06:22 2018
(r332117)
+++ head/usr.sbin/syslogd/syslogd.c Fri Apr  6 17:16:50 2018
(r332118)
@@ -252,7 +252,6 @@ struct filed {
 #definefu_pipe_pid f_un.f_pipe.f_pid
charf_prevline[MAXSVLINE];  /* last message logged */
struct logtime f_lasttime;  /* time of last occurrence */
-   charf_prevhost[MAXHOSTNAMELEN]; /* host from which recd. */
int f_prevpri;  /* pri of f_prevline */
size_t  f_prevlen;  /* length of f_prevline */
int f_prevcount;/* repetition cnt of prevline */
@@ -385,7 +384,9 @@ static void die(int) __dead2;
 static voiddodie(int);
 static voiddofsync(void);
 static voiddomark(int);
-static voidfprintlog(struct filed *, int, const char *);
+static voidfprintlog_first(struct filed *, const char *, const char *,
+const char *, const char *, const char *, const char *, int);
+static voidfprintlog_successive(struct filed *, int);
 static voidinit(int);
 static voidlogerror(const char *);
 static voidlogmsg(int, const struct logtime *, const char *, const char *,
@@ -1411,19 +1412,19 @@ skip_message(const char *name, const char *spec, int c
  * STRUCTURED-DATA fields are thus discarded for the time being.
  */
 static void
-logmsg(int pri, const struct logtime *timestamp, const char *from,
-const char *app_name, const char *procid, const char *msgid __unused,
-const char *structured_data __unused, const char *msg, int flags)
+logmsg(int pri, const struct logtime *timestamp, const char *hostname,
+const char *app_name, const char *procid, const char *msgid,
+const char *structured_data, const char *msg, int flags)
 {
struct timeval tv;
struct logtime timestamp_now;
struct filed *f;
-   size_t msglen;
+   size_t savedlen;
int fac, prilev;
-   char buf[MAXLINE+1];
+   char saved[MAXSVLINE];
 
dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n",
-   pri, flags, from, msg);
+   pri, flags, hostname, msg);
 
(void)gettimeofday(&tv, NULL);
now = tv.tv_sec;
@@ -1445,18 +1446,6 @@ logmsg(int pri, const struct logtime *timestamp, const
 
prilev = LOG_PRI(pri);
 
-   /* Prepend the application name to the message if provided. */
-   if (app_name != NULL) {
-   if (procid != NULL)
-   msglen = snprintf(buf, sizeof(buf), "%s[%s]: %s",
-   app_name, procid, msg);
-   else
-   msglen = snprintf(buf, sizeof(buf), "%s: %s",
-   app_name, msg);
-   msg = buf;
-   } else
-   msglen = strlen(msg);
-
/* log the message to the particular outputs */
if (!Initialized) {
f = &consfile;
@@ -1468,12 +1457,27 @@ logmsg(int pri, const struct logtime *timestamp, const
 
if (f->f_file >= 0) {
f->f_lasttime = *timestamp;
-   fprintlog(f, flags, msg);
+   fprintlog_first(f, hostname, app_name, procid, msgid,
+   structured_data, msg, flags);

svn commit: r332119 - in head/lib/libc: amd64/sys gen i386/sys powerpc/sys powerpc64/sys sparc64/sys

2018-04-06 Thread Brooks Davis
Author: brooks
Date: Fri Apr  6 17:17:34 2018
New Revision: 332119
URL: https://svnweb.freebsd.org/changeset/base/332119

Log:
  Remove caching from getlogin(2).
  
  This caching has existed since the CSRG import, but serves no obvious
  purpose. Sure, setlogin() is called rarely, but calls to getlogin()
  should also be infrequent. The required invalidation was not
  implemented on aarch64, arm, mips, amd riscv so updates would never
  occur if getlogin() was called before setlogin().
  
  Reported by:  Ali Mashtizadeh 
  Reviewed by:  kib
  Sponsored by: DARPA, AFRL
  Differential Revision:https://reviews.freebsd.org/D14965

Deleted:
  head/lib/libc/amd64/sys/setlogin.S
  head/lib/libc/i386/sys/setlogin.S
  head/lib/libc/powerpc/sys/setlogin.S
  head/lib/libc/powerpc64/sys/setlogin.S
  head/lib/libc/sparc64/sys/setlogin.S
Modified:
  head/lib/libc/amd64/sys/Makefile.inc
  head/lib/libc/gen/getlogin.c
  head/lib/libc/i386/sys/Makefile.inc
  head/lib/libc/powerpc/sys/Makefile.inc
  head/lib/libc/powerpc64/sys/Makefile.inc
  head/lib/libc/sparc64/sys/Makefile.inc

Modified: head/lib/libc/amd64/sys/Makefile.inc
==
--- head/lib/libc/amd64/sys/Makefile.incFri Apr  6 17:16:50 2018
(r332118)
+++ head/lib/libc/amd64/sys/Makefile.incFri Apr  6 17:17:34 2018
(r332119)
@@ -9,7 +9,7 @@ SRCS+=  \
amd64_set_gsbase.c
 
 MDASM= vfork.S brk.S cerror.S exect.S getcontext.S \
-   sbrk.S setlogin.S
+   sbrk.S
 
 # Don't generate default code for these syscalls:
 NOASM+=vfork.o

Modified: head/lib/libc/gen/getlogin.c
==
--- head/lib/libc/gen/getlogin.cFri Apr  6 17:16:50 2018
(r332118)
+++ head/lib/libc/gen/getlogin.cFri Apr  6 17:17:34 2018
(r332119)
@@ -47,62 +47,33 @@ __FBSDID("$FreeBSD$");
 
 #include "libc_private.h"
 
-#defineTHREAD_LOCK()   if (__isthreaded) 
_pthread_mutex_lock(&logname_mutex)
-#defineTHREAD_UNLOCK() if (__isthreaded) 
_pthread_mutex_unlock(&logname_mutex)
-
 extern int _getlogin(char *, int);
 
-int_logname_valid __hidden; /* known to setlogin() */
-static pthread_mutex_t logname_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-static char *
-getlogin_basic(int *status)
-{
-   static char logname[MAXLOGNAME];
-
-   if (_logname_valid == 0) {
-   if (_getlogin(logname, sizeof(logname)) < 0) {
-   *status = errno;
-   return (NULL);
-   }
-   _logname_valid = 1;
-   }
-   *status = 0;
-   return (*logname ? logname : NULL);
-}
-
 char *
 getlogin(void)
 {
-   char*result;
-   int status;
+   static char logname[MAXLOGNAME];
 
-   THREAD_LOCK();
-   result = getlogin_basic(&status);
-   THREAD_UNLOCK();
-   return (result);
+   if (_getlogin(logname, sizeof(logname)) < 0)
+   return (NULL);
+   return (logname[0] != '\0' ? logname : NULL);
 }
 
 int
 getlogin_r(char *logname, int namelen)
 {
-   char*result;
+   char tmpname[MAXLOGNAME];
int len;
-   int status;
 
if (namelen < 1)
return (ERANGE);
logname[0] = '\0';
 
-   THREAD_LOCK();
-   result = getlogin_basic(&status);
-   if (status == 0 && result != NULL) {
-   len = strlen(result) + 1;
-   if (len > namelen)
-   status = ERANGE;
-   else
-   strncpy(logname, result, len);
-   }
-   THREAD_UNLOCK();
-   return (status);
+   if (_getlogin(tmpname, sizeof(tmpname)) < 0)
+   return (errno);
+   len = strlen(tmpname) + 1;
+   if (len > namelen)
+   return (ERANGE);
+   strlcpy(logname, tmpname, len);
+   return (0);
 }

Modified: head/lib/libc/i386/sys/Makefile.inc
==
--- head/lib/libc/i386/sys/Makefile.inc Fri Apr  6 17:16:50 2018
(r332118)
+++ head/lib/libc/i386/sys/Makefile.inc Fri Apr  6 17:17:34 2018
(r332119)
@@ -8,7 +8,7 @@ SRCS+=  i386_get_fsbase.c i386_get_gsbase.c i386_get_io
i386_set_fsbase.c i386_set_gsbase.c i386_set_ioperm.c i386_set_ldt.c
 
 MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S \
-   sbrk.S setlogin.S syscall.S
+   sbrk.S syscall.S
 
 NOASM+=vfork.o
 

Modified: head/lib/libc/powerpc/sys/Makefile.inc
==
--- head/lib/libc/powerpc/sys/Makefile.inc  Fri Apr  6 17:16:50 2018
(r332118)
+++ head/lib/libc/powerpc/sys/Makefile.inc  Fri Apr  6 17:17:34 2018
(r332119)
@@ -1,3 +1,3 @@
 # $FreeBSD$
 
-MDASM+=brk.S cerror.S exect.S sbrk.S setlogin.S
+MDASM+=brk.S cerror.S 

svn commit: r332120 - head/sys/netinet

2018-04-06 Thread Jonathan T. Looney
Author: jtl
Date: Fri Apr  6 17:20:37 2018
New Revision: 332120
URL: https://svnweb.freebsd.org/changeset/base/332120

Log:
  If a user closes the socket before we call tcp_usr_abort(), then
  tcp_drop() may unlock the INP.  Currently, tcp_usr_abort() does not
  check for this case, which results in a panic while trying to unlock
  the already-unlocked INP (not to mention, a use-after-free violation).
  
  Make tcp_usr_abort() check the return value of tcp_drop(). In the case
  where tcp_drop() returns NULL, tcp_usr_abort() can skip further steps
  to abort the connection and simply unlock the INP_INFO lock prior to
  returning.
  
  Reviewed by:  glebius
  MFC after:2 weeks
  Sponsored by: Netflix, Inc.

Modified:
  head/sys/netinet/tcp_usrreq.c

Modified: head/sys/netinet/tcp_usrreq.c
==
--- head/sys/netinet/tcp_usrreq.c   Fri Apr  6 17:17:34 2018
(r332119)
+++ head/sys/netinet/tcp_usrreq.c   Fri Apr  6 17:20:37 2018
(r332120)
@@ -1095,7 +1095,9 @@ tcp_usr_abort(struct socket *so)
!(inp->inp_flags & INP_DROPPED)) {
tp = intotcpcb(inp);
TCPDEBUG1();
-   tcp_drop(tp, ECONNABORTED);
+   tp = tcp_drop(tp, ECONNABORTED);
+   if (tp == NULL)
+   goto dropped;
TCPDEBUG2(PRU_ABORT);
TCP_PROBE2(debug__user, tp, PRU_ABORT);
}
@@ -1106,6 +1108,7 @@ tcp_usr_abort(struct socket *so)
inp->inp_flags |= INP_SOCKREF;
}
INP_WUNLOCK(inp);
+dropped:
INP_INFO_RUNLOCK(&V_tcbinfo);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332121 - head

2018-04-06 Thread Brooks Davis
Author: brooks
Date: Fri Apr  6 17:23:47 2018
New Revision: 332121
URL: https://svnweb.freebsd.org/changeset/base/332121

Log:
  Support -DNO_CLEAN builds across r332119.

Modified:
  head/Makefile.inc1

Modified: head/Makefile.inc1
==
--- head/Makefile.inc1  Fri Apr  6 17:20:37 2018(r332120)
+++ head/Makefile.inc1  Fri Apr  6 17:23:47 2018(r332121)
@@ -807,7 +807,8 @@ _cleanobj_fast_depend_hack: .PHONY
 # 20170624  r320278  fstat fstatat fstatfs getdirentries getfsstat statfs
 # 20180404  r332048  sigreturn
 # 20180405  r332080  shmat
-.for f in fstat fstatat fstatfs getdirentries getfsstat shmat sigreturn statfs
+# 20180406  r332119  setlogin
+.for f in fstat fstatat fstatfs getdirentries getfsstat setlogin shmat 
sigreturn statfs
 .if exists(${OBJTOP}/lib/libc/.depend.${f}.o)
@if egrep -qw '${f}\.[sS]' \
${OBJTOP}/lib/libc/.depend.${f}.o; then \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332122 - in head/sys: amd64/amd64 amd64/ia32 amd64/linux amd64/linux32 arm/arm arm64/arm64 cam/scsi compat/freebsd32 compat/ia32 compat/linux conf dev/aac dev/aacraid dev/acpica dev/at...

2018-04-06 Thread Brooks Davis
Author: brooks
Date: Fri Apr  6 17:35:35 2018
New Revision: 332122
URL: https://svnweb.freebsd.org/changeset/base/332122

Log:
  Move most of the contents of opt_compat.h to opt_global.h.
  
  opt_compat.h is mentioned in nearly 180 files. In-progress network
  driver compabibility improvements may add over 100 more so this is
  closer to "just about everywhere" than "only some files" per the
  guidance in sys/conf/options.
  
  Keep COMPAT_LINUX32 in opt_compat.h as it is confined to a subset of
  sys/compat/linux/*.c.  A fake _COMPAT_LINUX option ensure opt_compat.h
  is created on all architectures.
  
  Move COMPAT_LINUXKPI to opt_dontuse.h as it is only used to control the
  set of compiled files.
  
  Reviewed by:  kib, cem, jhb, jtl
  Sponsored by: DARPA, AFRL
  Differential Revision:https://reviews.freebsd.org/D14941

Modified:
  head/sys/amd64/amd64/db_trace.c
  head/sys/amd64/amd64/exception.S
  head/sys/amd64/amd64/genassym.c
  head/sys/amd64/amd64/machdep.c
  head/sys/amd64/amd64/ptrace_machdep.c
  head/sys/amd64/amd64/vm_machdep.c
  head/sys/amd64/ia32/ia32_misc.c
  head/sys/amd64/ia32/ia32_reg.c
  head/sys/amd64/ia32/ia32_signal.c
  head/sys/amd64/ia32/ia32_sigtramp.S
  head/sys/amd64/ia32/ia32_syscall.c
  head/sys/amd64/linux/linux_dummy.c
  head/sys/amd64/linux/linux_sysvec.c
  head/sys/amd64/linux32/linux32_dummy.c
  head/sys/amd64/linux32/linux32_machdep.c
  head/sys/amd64/linux32/linux32_sysent.c
  head/sys/amd64/linux32/linux32_sysvec.c
  head/sys/amd64/linux32/syscalls.master
  head/sys/arm/arm/machdep.c
  head/sys/arm/arm/vm_machdep.c
  head/sys/arm64/arm64/machdep.c
  head/sys/cam/scsi/scsi_enc.c
  head/sys/cam/scsi/scsi_pass.c
  head/sys/compat/freebsd32/freebsd32_ioctl.c
  head/sys/compat/freebsd32/freebsd32_misc.c
  head/sys/compat/freebsd32/freebsd32_sysent.c
  head/sys/compat/ia32/ia32_genassym.c
  head/sys/compat/ia32/ia32_sysvec.c
  head/sys/compat/linux/linux_util.c
  head/sys/conf/options
  head/sys/conf/options.amd64
  head/sys/conf/options.arm64
  head/sys/conf/options.mips
  head/sys/conf/options.powerpc
  head/sys/dev/aac/aac.c
  head/sys/dev/aacraid/aacraid.c
  head/sys/dev/acpica/acpi_hpet.c
  head/sys/dev/atkbdc/atkbd.c
  head/sys/dev/cy/cy.c
  head/sys/dev/drm2/drmP.h
  head/sys/dev/drm2/drm_ioc32.c
  head/sys/dev/drm2/i915/i915_ioc32.c
  head/sys/dev/drm2/radeon/radeon_ioc32.c
  head/sys/dev/filemon/filemon.c
  head/sys/dev/filemon/filemon_wrapper.c
  head/sys/dev/kbdmux/kbdmux.c
  head/sys/dev/md/md.c
  head/sys/dev/mfi/mfi.c
  head/sys/dev/mpr/mpr_user.c
  head/sys/dev/mps/mps_user.c
  head/sys/dev/mrsas/mrsas_linux.c
  head/sys/dev/null/null.c
  head/sys/dev/pci/pci_user.c
  head/sys/dev/rp/rp.c
  head/sys/dev/sio/sio.c
  head/sys/dev/syscons/scvidctl.c
  head/sys/dev/syscons/syscons.c
  head/sys/dev/uart/uart_kbd_sun.c
  head/sys/dev/usb/input/ukbd.c
  head/sys/dev/vkbd/vkbd.c
  head/sys/dev/vt/vt_core.c
  head/sys/fs/cuse/cuse.c
  head/sys/fs/devfs/devfs_devs.c
  head/sys/fs/procfs/procfs_dbregs.c
  head/sys/fs/procfs/procfs_fpregs.c
  head/sys/fs/procfs/procfs_ioctl.c
  head/sys/fs/procfs/procfs_map.c
  head/sys/fs/procfs/procfs_regs.c
  head/sys/geom/geom_dev.c
  head/sys/i386/i386/genassym.c
  head/sys/i386/i386/locore.s
  head/sys/i386/i386/machdep.c
  head/sys/i386/i386/sigtramp.s
  head/sys/i386/linux/linux_dummy.c
  head/sys/kern/imgact_elf.c
  head/sys/kern/init_sysent.c
  head/sys/kern/kern_descrip.c
  head/sys/kern/kern_event.c
  head/sys/kern/kern_exec.c
  head/sys/kern/kern_exit.c
  head/sys/kern/kern_jail.c
  head/sys/kern/kern_mib.c
  head/sys/kern/kern_module.c
  head/sys/kern/kern_proc.c
  head/sys/kern/kern_prot.c
  head/sys/kern/kern_resource.c
  head/sys/kern/kern_sendfile.c
  head/sys/kern/kern_sharedpage.c
  head/sys/kern/kern_sig.c
  head/sys/kern/kern_sysctl.c
  head/sys/kern/kern_tc.c
  head/sys/kern/kern_thr.c
  head/sys/kern/kern_umtx.c
  head/sys/kern/kern_xxx.c
  head/sys/kern/makesyscalls.sh
  head/sys/kern/subr_dummy_vdso_tc.c
  head/sys/kern/sys_generic.c
  head/sys/kern/sys_getrandom.c
  head/sys/kern/sys_pipe.c
  head/sys/kern/sys_process.c
  head/sys/kern/sysv_ipc.c
  head/sys/kern/sysv_msg.c
  head/sys/kern/sysv_sem.c
  head/sys/kern/sysv_shm.c
  head/sys/kern/tty.c
  head/sys/kern/tty_compat.c
  head/sys/kern/uipc_mqueue.c
  head/sys/kern/uipc_sem.c
  head/sys/kern/uipc_socket.c
  head/sys/kern/uipc_syscalls.c
  head/sys/kern/vfs_aio.c
  head/sys/kern/vfs_bio.c
  head/sys/kern/vfs_subr.c
  head/sys/kern/vfs_syscalls.c
  head/sys/mips/include/reg.h
  head/sys/mips/include/sigframe.h
  head/sys/mips/include/tls.h
  head/sys/mips/include/ucontext.h
  head/sys/mips/mips/freebsd32_machdep.c
  head/sys/mips/mips/pm_machdep.c
  head/sys/mips/mips/swtch.S
  head/sys/mips/mips/trap.c
  head/sys/mips/mips/vm_machdep.c
  head/sys/modules/aac/Makefile
  head/sys/modules/aacraid/Makefile
  head/sys/modules/cam/Makefile
  head/sys/modules/cryptodev/Makefile
  head/sys/modules/cuse/Makefile
  head/sys/modules/drm2/drm2/Makefile
  he

Re: svn commit: r327954 - in head/sys: amd64/conf conf dev/acpica vm x86/acpica

2018-04-06 Thread John Baldwin
On Sunday, April 01, 2018 01:35:45 PM Ian Lepore wrote:
> On Sun, 2018-01-14 at 03:36 +, Jeff Roberson wrote:
> > Author: jeff
> > Date: Sun Jan 14 03:36:03 2018
> > New Revision: 327954
> > URL: https://svnweb.freebsd.org/changeset/base/327954
> > 
> > Log:
> >   Move VM_NUMA_ALLOC and DEVICE_NUMA under the single global config
> > option NUMA.
> >   
> >   Sponsored by: Netflix, Dell/EMC Isilon
> >   Discussed with:   jhb
> 
> It turns out this breaks building powerpc lint kernels. It shakes out
> like this... makeLINT.mk copies sys/conf/NOTES into the generated LINT
> config (I guess on the theory that things documented in NOTES are
> supported by all arches). So option NUMA is present on powerpc, but the
> powerpc vmparam.h doesn't define VM_LEVEL_0_ORDER so the build fails.
> (Mips also doesn't define that, but it has no lint kernel build at all
> right now.)
> 
> It could be fixed in vm_domainset.c with:
> 
> -#ifdef NUMA
> +#if defined(NUMA) && defined(VM_LEVEL_0_ORDER)
> 
> but there may be some better way to fix it, I don't know that much
> about this stuff.

Maybe add 'nooption NUMA' to sys/powerpc/conf/NOTES?  (It has several
nooption and nodevice lines already)  If it affects more than powerpc
then I wouldn't do that, but if it's only powerpc then I think patching
powerpc/conf/NOTES is most consistent with how this has been handled to
date.

-- 
John Baldwin
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r332090 - head/stand/i386

2018-04-06 Thread John Baldwin
On Friday, April 06, 2018 02:57:58 AM Ed Maste wrote:
> Author: emaste
> Date: Fri Apr  6 02:57:58 2018
> New Revision: 332090
> URL: https://svnweb.freebsd.org/changeset/base/332090
> 
> Log:
>   stand: pass --no-rosegment for i386 bits when linking with lld
>   
>   btxld does not correctly handle input with other than 2 PT_LOAD
>   segments.  Passing --no-rosegment lets lld produce output eqivalent to
>   ld.bfd: 2 PT_LOAD segments and no PT_GNU_RELRO.
>   
>   PR: 225775
>   MFC after:  3 weeks
>   Sponsored by:   The FreeBSD Foundation
>   Differential Revision:  https://reviews.freebsd.org/D14956
> 
> Modified:
>   head/stand/i386/Makefile.inc
> 
> Modified: head/stand/i386/Makefile.inc
> ==
> --- head/stand/i386/Makefile.inc  Fri Apr  6 02:47:43 2018
> (r332089)
> +++ head/stand/i386/Makefile.inc  Fri Apr  6 02:57:58 2018
> (r332090)
> @@ -2,8 +2,13 @@
>  #
>  # $FreeBSD$
>  
> +.sinclude 
> +
>  LOADER_ADDRESS?=0x20
>  LDFLAGS+=-nostdlib
> +.if defined(LINKER_TYPE) && ${LINKER_TYPE} == "lld"
> +LDFLAGS+=-Wl,--no-rosegment
> +.endif

Maybe we should support LDFLAGS.${LINKER_TYPE} as we do for CFLAGS, etc.?

-- 
John Baldwin
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r332090 - head/stand/i386

2018-04-06 Thread Warner Losh
On Fri, Apr 6, 2018 at 11:54 AM, John Baldwin  wrote:

> On Friday, April 06, 2018 02:57:58 AM Ed Maste wrote:
> > Author: emaste
> > Date: Fri Apr  6 02:57:58 2018
> > New Revision: 332090
> > URL: https://svnweb.freebsd.org/changeset/base/332090
> >
> > Log:
> >   stand: pass --no-rosegment for i386 bits when linking with lld
> >
> >   btxld does not correctly handle input with other than 2 PT_LOAD
> >   segments.  Passing --no-rosegment lets lld produce output eqivalent to
> >   ld.bfd: 2 PT_LOAD segments and no PT_GNU_RELRO.
> >
> >   PR: 225775
> >   MFC after:  3 weeks
> >   Sponsored by:   The FreeBSD Foundation
> >   Differential Revision:  https://reviews.freebsd.org/D14956
> >
> > Modified:
> >   head/stand/i386/Makefile.inc
> >
> > Modified: head/stand/i386/Makefile.inc
> > 
> ==
> > --- head/stand/i386/Makefile.inc  Fri Apr  6 02:47:43 2018
> (r332089)
> > +++ head/stand/i386/Makefile.inc  Fri Apr  6 02:57:58 2018
> (r332090)
> > @@ -2,8 +2,13 @@
> >  #
> >  # $FreeBSD$
> >
> > +.sinclude 
> > +
> >  LOADER_ADDRESS?=0x20
> >  LDFLAGS+=-nostdlib
> > +.if defined(LINKER_TYPE) && ${LINKER_TYPE} == "lld"
> > +LDFLAGS+=-Wl,--no-rosegment
> > +.endif
>
> Maybe we should support LDFLAGS.${LINKER_TYPE} as we do for CFLAGS, etc.?
>

I concur. It doesn't take too many of these for that to pay off big time,
especially if we have to do anything globally...

Warner
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332133 - head/sys/conf

2018-04-06 Thread Brooks Davis
Author: brooks
Date: Fri Apr  6 19:11:22 2018
New Revision: 332133
URL: https://svnweb.freebsd.org/changeset/base/332133

Log:
  Add an unused _COMPAT_LINUX32 option to ensure opt_compat.h exists on
  platforms without COMPAT_LINUX32.
  
  Reported by:  kib

Modified:
  head/sys/conf/options

Modified: head/sys/conf/options
==
--- head/sys/conf/options   Fri Apr  6 19:10:11 2018(r332132)
+++ head/sys/conf/options   Fri Apr  6 19:11:22 2018(r332133)
@@ -92,6 +92,7 @@ COMPAT_FREEBSD11  opt_global.h
 COMPAT_CLOUDABI32  opt_dontuse.h
 COMPAT_CLOUDABI64  opt_dontuse.h
 COMPAT_LINUXKPIopt_dontuse.h
+_COMPAT_LINUX32opt_compat.h# XXX: make sure opt_compat.h exists
 COMPILING_LINT opt_global.h
 CY_PCI_FASTINTR
 DEADLKRES  opt_watchdog.h
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332136 - head/sys/netpfil/pf

2018-04-06 Thread Kristof Provost
Author: kp
Date: Fri Apr  6 19:20:45 2018
New Revision: 332136
URL: https://svnweb.freebsd.org/changeset/base/332136

Log:
  pf: Improve ioctl validation for DIOCIGETIFACES and DIOCXCOMMIT
  
  These ioctls can process a number of items at a time, which puts us at
  risk of overflow in mallocarray() and of impossibly large allocations
  even if we don't overflow.
  
  There's no obvious limit to the request size for these, so we limit the
  requests to something which won't overflow. Change the memory allocation
  to M_NOWAIT so excessive requests will fail rather than stall forever.
  
  MFC after:1 week

Modified:
  head/sys/netpfil/pf/pf_ioctl.c

Modified: head/sys/netpfil/pf/pf_ioctl.c
==
--- head/sys/netpfil/pf/pf_ioctl.c  Fri Apr  6 19:17:59 2018
(r332135)
+++ head/sys/netpfil/pf/pf_ioctl.c  Fri Apr  6 19:20:45 2018
(r332136)
@@ -3143,10 +3143,17 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
+
+   if (io->size < 0 ||
+   WOULD_OVERFLOW(io->size, sizeof(struct pfioc_trans_e))) {
+   error = EINVAL;
+   break;
+   }
+
totlen = sizeof(struct pfioc_trans_e) * io->size;
ioes = mallocarray(io->size, sizeof(struct pfioc_trans_e),
-   M_TEMP, M_WAITOK);
-   if (! ioes) {
+   M_TEMP, M_NOWAIT);
+   if (ioes == NULL) {
error = ENOMEM;
break;
}
@@ -3349,13 +3356,20 @@ DIOCCHANGEADDR_error:
break;
}
 
+   if (io->pfiio_size < 0 ||
+   WOULD_OVERFLOW(io->pfiio_size, sizeof(struct pfi_kif))) {
+   error = EINVAL;
+   break;
+   }
+
bufsiz = io->pfiio_size * sizeof(struct pfi_kif);
ifstore = mallocarray(io->pfiio_size, sizeof(struct pfi_kif),
-   M_TEMP, M_WAITOK);
-   if (! ifstore) {
+   M_TEMP, M_NOWAIT);
+   if (ifstore == NULL) {
error = ENOMEM;
break;
}
+
PF_RULES_RLOCK();
pfi_get_ifaces(io->pfiio_name, ifstore, &io->pfiio_size);
PF_RULES_RUNLOCK();
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332137 - head/tests/sys/netpfil/pf/ioctl

2018-04-06 Thread Kristof Provost
Author: kp
Date: Fri Apr  6 19:21:29 2018
New Revision: 332137
URL: https://svnweb.freebsd.org/changeset/base/332137

Log:
  pf tests: Basic ioctl validation for DIOCIGETIFACES and DIOCXCOMMIT
  
  Validate the DIOCIGETIFACES and DIOCXCOMMIT ioctls with invalid values.
  
  MFC after:1 week

Modified:
  head/tests/sys/netpfil/pf/ioctl/validation.c

Modified: head/tests/sys/netpfil/pf/ioctl/validation.c
==
--- head/tests/sys/netpfil/pf/ioctl/validation.cFri Apr  6 19:20:45 
2018(r332136)
+++ head/tests/sys/netpfil/pf/ioctl/validation.cFri Apr  6 19:21:29 
2018(r332137)
@@ -255,6 +255,63 @@ ATF_TC_BODY(settflags, tc)
COMMON_CLEANUP();
 }
 
+ATF_TC_WITHOUT_HEAD(igetifaces);
+ATF_TC_BODY(igetifaces, tc)
+{
+   struct pfioc_iface io;
+   struct pfi_kif kif;
+
+   COMMON_HEAD();
+
+   bzero(&io, sizeof(io));
+   io.pfiio_flags = 0;
+   io.pfiio_buffer = &kif;
+   io.pfiio_esize = sizeof(kif);
+
+   /* Negative size */
+   io.pfiio_size = -1;
+   if (ioctl(dev, DIOCIGETIFACES, &io) == 0)
+   atf_tc_fail("request with size -1 succeeded");
+
+   /* Overflow size */
+   io.pfiio_size = 1 << 31;
+   if (ioctl(dev, DIOCIGETIFACES, &io) == 0)
+   atf_tc_fail("request with size 1 << 31 succeeded");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(commit);
+ATF_TC_BODY(commit, tc)
+{
+   struct pfioc_trans io;
+   struct pfioc_trans_e ioe;
+
+   COMMON_HEAD();
+
+   bzero(&io, sizeof(io));
+   io.esize = sizeof(ioe);
+   io.array = &ioe;
+
+   /* Negative size */
+   io.size = -1;
+   if (ioctl(dev, DIOCXCOMMIT, &io) == 0)
+   atf_tc_fail("request with size -1 succeeded");
+
+   /* Overflow size */
+   io.size = 1 << 30;
+   if (ioctl(dev, DIOCXCOMMIT, &io) == 0)
+   atf_tc_fail("request with size 1 << 30 succeeded");
+
+   /* NULL buffer */
+   io.size = 1;
+   io.array = NULL;
+   if (ioctl(dev, DIOCXCOMMIT, &io) == 0)
+   atf_tc_fail("request with size -1 succeeded");
+
+   COMMON_CLEANUP();
+}
+
 ATF_TP_ADD_TCS(tp)
 {
ATF_TP_ADD_TC(tp, addtables);
@@ -263,6 +320,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, gettstats);
ATF_TP_ADD_TC(tp, clrtstats);
ATF_TP_ADD_TC(tp, settflags);
+   ATF_TP_ADD_TC(tp, igetifaces);
+   ATF_TP_ADD_TC(tp, commit);
 
return (atf_no_error());
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332139 - head/tests/sys/netpfil/pf/ioctl

2018-04-06 Thread Kristof Provost
Author: kp
Date: Fri Apr  6 19:22:22 2018
New Revision: 332139
URL: https://svnweb.freebsd.org/changeset/base/332139

Log:
  pf tests: Try to provoke a memory leak
  
  There was a memory leak in the DIOCRADDTABLES ioctl() code which could
  be triggered by trying to add tables with the same name.
  Try to provoke this memory leak. It was fixed in r331225.
  
  MFC after:1 week

Modified:
  head/tests/sys/netpfil/pf/ioctl/validation.c

Modified: head/tests/sys/netpfil/pf/ioctl/validation.c
==
--- head/tests/sys/netpfil/pf/ioctl/validation.cFri Apr  6 19:21:36 
2018(r332138)
+++ head/tests/sys/netpfil/pf/ioctl/validation.cFri Apr  6 19:22:22 
2018(r332139)
@@ -66,6 +66,7 @@ ATF_TC_BODY(addtables, tc)
 {
struct pfioc_table io;
struct pfr_table tbl;
+   struct pfr_table tbls[4];
int flags;
 
COMMON_HEAD();
@@ -92,6 +93,14 @@ ATF_TC_BODY(addtables, tc)
io.pfrio_buffer = NULL;
if (ioctl(dev, DIOCRADDTABLES, &io) == 0)
atf_tc_fail("Request with NULL buffer succeeded");
+
+   /* This can provoke a memory leak, see r331225. */
+   io.pfrio_size = 4;
+   for (int i = 0; i < io.pfrio_size; i++)
+   common_init_tbl(&tbls[i]);
+
+   io.pfrio_buffer = &tbls;
+   ioctl(dev, DIOCRADDTABLES, &io);
 
COMMON_CLEANUP();
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332143 - head/tests/sys/netpfil/pf/ioctl

2018-04-06 Thread Kristof Provost
Author: kp
Date: Fri Apr  6 19:37:15 2018
New Revision: 332143
URL: https://svnweb.freebsd.org/changeset/base/332143

Log:
  pf tests: Basic ioctl validation
  
  Basic validation tests for DIOCRADDADDRS, DIOCRDELADDRS, DIOCRSETADDRS,
  DIOCRGETADDRS, DIOCRGETASTATS, DIOCRCLRASTATS, DIOCRTSTADDRS,
  DIOCRINADEFINE, DIOCXBEGIN and DIOCXROLLBACK.
  
  MFC after:1 week

Modified:
  head/tests/sys/netpfil/pf/ioctl/validation.c

Modified: head/tests/sys/netpfil/pf/ioctl/validation.c
==
--- head/tests/sys/netpfil/pf/ioctl/validation.cFri Apr  6 19:36:35 
2018(r332142)
+++ head/tests/sys/netpfil/pf/ioctl/validation.cFri Apr  6 19:37:15 
2018(r332143)
@@ -264,6 +264,232 @@ ATF_TC_BODY(settflags, tc)
COMMON_CLEANUP();
 }
 
+ATF_TC_WITHOUT_HEAD(addaddrs);
+ATF_TC_BODY(addaddrs, tc)
+{
+   struct pfioc_table io;
+   struct pfr_addr addr;
+
+   COMMON_HEAD();
+
+   bzero(&addr, sizeof(addr));
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = 0;
+   io.pfrio_buffer = &addr;
+   io.pfrio_esize = sizeof(addr);
+
+   /* Negative size. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRADDADDRS, &io) == 0)
+   atf_tc_fail("Request with size -1 succeeded");
+
+   /* Overly large size. */
+   io.pfrio_size = 1 << 28;
+   if (ioctl(dev, DIOCRADDADDRS, &io) == 0)
+   atf_tc_fail("Reuqest with size 1 << 28 failed");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(deladdrs);
+ATF_TC_BODY(deladdrs, tc)
+{
+   struct pfioc_table io;
+   struct pfr_addr addr;
+
+   COMMON_HEAD();
+
+   bzero(&addr, sizeof(addr));
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = 0;
+   io.pfrio_buffer = &addr;
+   io.pfrio_esize = sizeof(addr);
+
+   /* Negative size. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRDELADDRS, &io) == 0)
+   atf_tc_fail("Request with size -1 succeeded");
+
+   /* Overly large size. */
+   io.pfrio_size = 1 << 28;
+   if (ioctl(dev, DIOCRDELADDRS, &io) == 0)
+   atf_tc_fail("Reuqest with size 1 << 28 failed");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(setaddrs);
+ATF_TC_BODY(setaddrs, tc)
+{
+   struct pfioc_table io;
+   struct pfr_addr addr;
+
+   COMMON_HEAD();
+
+   bzero(&addr, sizeof(addr));
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = 0;
+   io.pfrio_buffer = &addr;
+   io.pfrio_esize = sizeof(addr);
+
+   /* Negative size. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRSETADDRS, &io) == 0)
+   atf_tc_fail("Request with size -1 succeeded");
+
+   /* Overly large size. */
+   io.pfrio_size = 1 << 28;
+   if (ioctl(dev, DIOCRSETADDRS, &io) == 0)
+   atf_tc_fail("Reuqest with size 1 << 28 failed");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(getaddrs);
+ATF_TC_BODY(getaddrs, tc)
+{
+   struct pfioc_table io;
+   struct pfr_addr addr;
+
+   COMMON_HEAD();
+
+   bzero(&addr, sizeof(addr));
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = 0;
+   io.pfrio_buffer = &addr;
+   io.pfrio_esize = sizeof(addr);
+
+   common_init_tbl(&io.pfrio_table);
+
+   /* Negative size. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRGETADDRS, &io) == 0)
+   atf_tc_fail("Request with size -1 succeeded");
+
+   /* Overly large size. */
+   io.pfrio_size = 1 << 24;
+   if (ioctl(dev, DIOCRGETADDRS, &io) == 0)
+   atf_tc_fail("Request with size 1 << 24 failed");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(getastats);
+ATF_TC_BODY(getastats, tc)
+{
+   struct pfioc_table io;
+   struct pfr_astats astats;
+
+   COMMON_HEAD();
+
+   bzero(&astats, sizeof(astats));
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = 0;
+   io.pfrio_buffer = &astats;
+   io.pfrio_esize = sizeof(astats);
+
+   common_init_tbl(&io.pfrio_table);
+
+   /* Negative size. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRGETASTATS, &io) == 0)
+   atf_tc_fail("Request with size -1 succeeded");
+
+   /* Overly large size. */
+   io.pfrio_size = 1 << 24;
+   if (ioctl(dev, DIOCRGETASTATS, &io) == 0)
+   atf_tc_fail("Request with size 1 << 24 failed");
+
+   COMMON_CLEANUP();
+}
+
+ATF_TC_WITHOUT_HEAD(clrastats);
+ATF_TC_BODY(clrastats, tc)
+{
+   struct pfioc_table io;
+   struct pfr_addr addr;
+
+   COMMON_HEAD();
+
+   bzero(&addr, sizeof(addr));
+   bzero(&io, sizeof(io));
+   io.pfrio_flags = 0;
+   io.pfrio_buffer = &addr;
+   io.pfrio_esize = sizeof(addr);
+
+   common_init_tbl(&io.pfrio_table);
+
+   /* Negative size. */
+   io.pfrio_size = -1;
+   if (ioctl(dev, DIOCRCLRASTATS, &io) == 0)
+   atf_tc_fail("Request with size -1 succeede

svn commit: r332142 - head/sys/netpfil/pf

2018-04-06 Thread Kristof Provost
Author: kp
Date: Fri Apr  6 19:36:35 2018
New Revision: 332142
URL: https://svnweb.freebsd.org/changeset/base/332142

Log:
  pf: Improve ioctl validation
  
  Ensure that multiplications for memory allocations cannot overflow, and
  that we'll not try to allocate M_WAITOK for potentially overly large
  allocations.
  
  MFC after:1 week

Modified:
  head/sys/netpfil/pf/pf_ioctl.c

Modified: head/sys/netpfil/pf/pf_ioctl.c
==
--- head/sys/netpfil/pf/pf_ioctl.c  Fri Apr  6 19:34:21 2018
(r332141)
+++ head/sys/netpfil/pf/pf_ioctl.c  Fri Apr  6 19:36:35 2018
(r332142)
@@ -2740,9 +2740,14 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
+   if (io->pfrio_size < 0 ||
+   WOULD_OVERFLOW(io->pfrio_size, sizeof(struct pfr_addr))) {
+   error = EINVAL;
+   break;
+   }
totlen = io->pfrio_size * sizeof(struct pfr_addr);
pfras = mallocarray(io->pfrio_size, sizeof(struct pfr_addr),
-   M_TEMP, M_WAITOK);
+   M_TEMP, M_NOWAIT);
if (! pfras) {
error = ENOMEM;
break;
@@ -2772,9 +2777,14 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
+   if (io->pfrio_size < 0 ||
+   WOULD_OVERFLOW(io->pfrio_size, sizeof(struct pfr_addr))) {
+   error = EINVAL;
+   break;
+   }
totlen = io->pfrio_size * sizeof(struct pfr_addr);
pfras = mallocarray(io->pfrio_size, sizeof(struct pfr_addr),
-   M_TEMP, M_WAITOK);
+   M_TEMP, M_NOWAIT);
if (! pfras) {
error = ENOMEM;
break;
@@ -2804,10 +2814,18 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
+   if (io->pfrio_size < 0 || io->pfrio_size2 < 0) {
+   error = EINVAL;
+   break;
+   }
count = max(io->pfrio_size, io->pfrio_size2);
+   if (WOULD_OVERFLOW(count, sizeof(struct pfr_addr))) {
+   error = EINVAL;
+   break;
+   }
totlen = count * sizeof(struct pfr_addr);
pfras = mallocarray(count, sizeof(struct pfr_addr), M_TEMP,
-   M_WAITOK);
+   M_NOWAIT);
if (! pfras) {
error = ENOMEM;
break;
@@ -2838,9 +2856,14 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
+   if (io->pfrio_size < 0 ||
+   WOULD_OVERFLOW(io->pfrio_size, sizeof(struct pfr_addr))) {
+   error = EINVAL;
+   break;
+   }
totlen = io->pfrio_size * sizeof(struct pfr_addr);
pfras = mallocarray(io->pfrio_size, sizeof(struct pfr_addr),
-   M_TEMP, M_WAITOK);
+   M_TEMP, M_NOWAIT);
if (! pfras) {
error = ENOMEM;
break;
@@ -2864,9 +2887,14 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
+   if (io->pfrio_size < 0 ||
+   WOULD_OVERFLOW(io->pfrio_size, sizeof(struct pfr_astats))) {
+   error = EINVAL;
+   break;
+   }
totlen = io->pfrio_size * sizeof(struct pfr_astats);
pfrastats = mallocarray(io->pfrio_size,
-   sizeof(struct pfr_astats), M_TEMP, M_WAITOK);
+   sizeof(struct pfr_astats), M_TEMP, M_NOWAIT);
if (! pfrastats) {
error = ENOMEM;
break;
@@ -2890,9 +2918,14 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
+   if (io->pfrio_size < 0 ||
+   WOULD_OVERFLOW(io->pfrio_size, sizeof(struct pfr_addr))) {
+   error = EINVAL;
+   break;
+   }
totlen = io->pfrio_size * sizeof(struct pfr_addr);
pfras = mallocarray(io->pfrio_size, sizeof(struct pfr_addr),
-   M_TEMP, M_WAITOK);
+   M_TEMP, M_NOWAIT);
if (! pfras) {
error = ENOMEM;
break;
@@ -2922,9 +2955,14 @@ DIOCCHANGEADDR_error:
error = ENODEV;
break;
}
+ 

svn commit: r332145 - head/sys/cam/scsi

2018-04-06 Thread Alexander Motin
Author: mav
Date: Fri Apr  6 19:47:44 2018
New Revision: 332145
URL: https://svnweb.freebsd.org/changeset/base/332145

Log:
  Do not fail devices just for errors in descriptor format.
  
  MFC after:1 week
  Sponsored by: iXsystems, Inc.

Modified:
  head/sys/cam/scsi/scsi_cd.c
  head/sys/cam/scsi/scsi_da.c

Modified: head/sys/cam/scsi/scsi_cd.c
==
--- head/sys/cam/scsi/scsi_cd.c Fri Apr  6 19:47:07 2018(r332144)
+++ head/sys/cam/scsi/scsi_cd.c Fri Apr  6 19:47:44 2018(r332145)
@@ -1119,7 +1119,8 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
 * supported" (0x25) error.
 */
if ((have_sense) && (asc != 0x25)
-&& (error_code == SSD_CURRENT_ERROR)) {
+&& (error_code == SSD_CURRENT_ERROR
+ || error_code == SSD_DESC_CURRENT_ERROR)) {
const char *sense_key_desc;
const char *asc_desc;
 

Modified: head/sys/cam/scsi/scsi_da.c
==
--- head/sys/cam/scsi/scsi_da.c Fri Apr  6 19:47:07 2018(r332144)
+++ head/sys/cam/scsi/scsi_da.c Fri Apr  6 19:47:44 2018(r332145)
@@ -4649,7 +4649,8 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
(((csio->ccb_h.status & CAM_STATUS_MASK) ==
CAM_REQ_INVALID) ||
 ((have_sense) &&
- (error_code == SSD_CURRENT_ERROR) &&
+ (error_code == SSD_CURRENT_ERROR ||
+  error_code == SSD_DESC_CURRENT_ERROR) &&
  (sense_key == SSD_KEY_ILLEGAL_REQUEST 
{
cam_periph_lock(periph);
softc->flags &= ~DA_FLAG_CAN_RC16;
@@ -4674,7 +4675,8 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
 */
if ((have_sense)
 && (asc != 0x25) && (asc != 0x44)
-&& (error_code == SSD_CURRENT_ERROR)) {
+&& (error_code == SSD_CURRENT_ERROR
+ || error_code == SSD_DESC_CURRENT_ERROR)) {
const char *sense_key_desc;
const char *asc_desc;
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332146 - head/share/mk

2018-04-06 Thread Kyle Evans
Author: kevans
Date: Fri Apr  6 19:49:57 2018
New Revision: 332146
URL: https://svnweb.freebsd.org/changeset/base/332146

Log:
  Re-sort LOADER options
  
  These have become unsorted from everything else. This is desync'd from
  stable/11 due to some hand-merging that was done there, so the MFC of this
  will look slightly different.
  
  MFC after:3 days

Modified:
  head/share/mk/src.opts.mk

Modified: head/share/mk/src.opts.mk
==
--- head/share/mk/src.opts.mk   Fri Apr  6 19:47:44 2018(r332145)
+++ head/share/mk/src.opts.mk   Fri Apr  6 19:49:57 2018(r332146)
@@ -129,14 +129,14 @@ __DEFAULT_YES_OPTIONS = \
 LIBPTHREAD \
 LIBTHR \
 LLVM_COV \
+LOADER_GELI \
+LOADER_OFW \
+LOADER_UBOOT \
 LOCALES \
 LOCATE \
 LPR \
 LS_COLORS \
 LZMA_SUPPORT \
-LOADER_GELI \
-LOADER_OFW \
-LOADER_UBOOT \
 MAIL \
 MAILWRAPPER \
 MAKE \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332151 - head/sys/net

2018-04-06 Thread Brooks Davis
Author: brooks
Date: Fri Apr  6 20:26:56 2018
New Revision: 332151
URL: https://svnweb.freebsd.org/changeset/base/332151

Log:
  ifconf(): correct handling of sockaddrs smaller than struct sockaddr.
  
  Portable programs that use SIOCGIFCONF (e.g. traceroute) assume
  that each pseudo ifreq is of length MAX(sizeof(struct ifreq),
  sizeof(ifr_name) + ifr_addr.sa_len).  For short sockaddrs we copied
  too much from the source sockaddr resulting in a heap leak.
  
  I believe only one such sockaddr exists (struct sockaddr_sco which
  is 8 bytes) and it is unclear if such sockaddrs end up on interfaces
  in practice.  If it did, the result would be an 8 byte heap leak on
  current architectures.
  
  admbugs:  869
  Reviewed by:  kib
  Obtained from:CheriBSD
  MFC after:3 days
  Security: kernel heap leak
  Sponsored by: DARPA, AFRL
  Differential Revision:https://reviews.freebsd.org/D14981

Modified:
  head/sys/net/if.c

Modified: head/sys/net/if.c
==
--- head/sys/net/if.c   Fri Apr  6 20:24:50 2018(r332150)
+++ head/sys/net/if.c   Fri Apr  6 20:26:56 2018(r332151)
@@ -3191,7 +3191,13 @@ again:
continue;
addrs++;
if (sa->sa_len <= sizeof(*sa)) {
-   ifr.ifr_addr = *sa;
+   if (sa->sa_len < sizeof(*sa)) {
+   memset(&ifr.ifr_ifru.ifru_addr, 0,
+   sizeof(ifr.ifr_ifru.ifru_addr));
+   memcpy(&ifr.ifr_ifru.ifru_addr, sa,
+   sa->sa_len);
+   } else
+   ifr.ifr_ifru.ifru_addr = *sa;
sbuf_bcat(sb, &ifr, sizeof(ifr));
max_len += sizeof(ifr);
} else {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332157 - in head: lib/libvmmapi sys/amd64/include sys/amd64/vmm sys/amd64/vmm/amd sys/amd64/vmm/intel

2018-04-06 Thread John Baldwin
Author: jhb
Date: Fri Apr  6 22:03:43 2018
New Revision: 332157
URL: https://svnweb.freebsd.org/changeset/base/332157

Log:
  Add a way to temporarily suspend and resume virtual CPUs.
  
  This is used as part of implementing run control in bhyve's debug
  server.  The hypervisor now maintains a set of "debugged" CPUs.
  Attempting to run a debugged CPU will fail to execute any guest
  instructions and will instead report a VM_EXITCODE_DEBUG exit to
  the userland hypervisor.  Virtual CPUs are placed into the debugged
  state via vm_suspend_cpu() (implemented via a new VM_SUSPEND_CPU ioctl).
  Virtual CPUs can be resumed via vm_resume_cpu() (VM_RESUME_CPU ioctl).
  
  The debug server suspends virtual CPUs when it wishes them to stop
  executing in the guest (for example, when a debugger attaches to the
  server).  The debug server can choose to resume only a subset of CPUs
  (for example, when single stepping) or it can choose to resume all
  CPUs.  The debug server must explicitly mark a CPU as resumed via
  vm_resume_cpu() before the virtual CPU will successfully execute any
  guest instructions.
  
  Reviewed by:  avg, grehan
  Tested on:Intel (jhb), AMD (avg)
  Differential Revision:https://reviews.freebsd.org/D14466

Modified:
  head/lib/libvmmapi/vmmapi.c
  head/lib/libvmmapi/vmmapi.h
  head/sys/amd64/include/vmm.h
  head/sys/amd64/include/vmm_dev.h
  head/sys/amd64/vmm/amd/svm.c
  head/sys/amd64/vmm/intel/vmx.c
  head/sys/amd64/vmm/vmm.c
  head/sys/amd64/vmm/vmm_dev.c

Modified: head/lib/libvmmapi/vmmapi.c
==
--- head/lib/libvmmapi/vmmapi.c Fri Apr  6 21:50:09 2018(r332156)
+++ head/lib/libvmmapi/vmmapi.c Fri Apr  6 22:03:43 2018(r332157)
@@ -1374,6 +1374,13 @@ vm_suspended_cpus(struct vmctx *ctx, cpuset_t *cpus)
 }
 
 int
+vm_debug_cpus(struct vmctx *ctx, cpuset_t *cpus)
+{
+
+   return (vm_get_cpus(ctx, VM_DEBUG_CPUS, cpus));
+}
+
+int
 vm_activate_cpu(struct vmctx *ctx, int vcpu)
 {
struct vm_activate_cpu ac;
@@ -1386,6 +1393,30 @@ vm_activate_cpu(struct vmctx *ctx, int vcpu)
 }
 
 int
+vm_suspend_cpu(struct vmctx *ctx, int vcpu)
+{
+   struct vm_activate_cpu ac;
+   int error;
+
+   bzero(&ac, sizeof(struct vm_activate_cpu));
+   ac.vcpuid = vcpu;
+   error = ioctl(ctx->fd, VM_SUSPEND_CPU, &ac);
+   return (error);
+}
+
+int
+vm_resume_cpu(struct vmctx *ctx, int vcpu)
+{
+   struct vm_activate_cpu ac;
+   int error;
+
+   bzero(&ac, sizeof(struct vm_activate_cpu));
+   ac.vcpuid = vcpu;
+   error = ioctl(ctx->fd, VM_RESUME_CPU, &ac);
+   return (error);
+}
+
+int
 vm_get_intinfo(struct vmctx *ctx, int vcpu, uint64_t *info1, uint64_t *info2)
 {
struct vm_intinfo vmii;
@@ -1501,7 +1532,8 @@ vm_get_ioctls(size_t *len)
VM_SET_X2APIC_STATE, VM_GET_X2APIC_STATE,
VM_GET_HPET_CAPABILITIES, VM_GET_GPA_PMAP, VM_GLA2GPA,
VM_GLA2GPA_NOFAULT,
-   VM_ACTIVATE_CPU, VM_GET_CPUS, VM_SET_INTINFO, VM_GET_INTINFO,
+   VM_ACTIVATE_CPU, VM_GET_CPUS, VM_SUSPEND_CPU, VM_RESUME_CPU,
+   VM_SET_INTINFO, VM_GET_INTINFO,
VM_RTC_WRITE, VM_RTC_READ, VM_RTC_SETTIME, VM_RTC_GETTIME,
VM_RESTART_INSTRUCTION };
 

Modified: head/lib/libvmmapi/vmmapi.h
==
--- head/lib/libvmmapi/vmmapi.h Fri Apr  6 21:50:09 2018(r332156)
+++ head/lib/libvmmapi/vmmapi.h Fri Apr  6 22:03:43 2018(r332157)
@@ -216,7 +216,10 @@ intvcpu_reset(struct vmctx *ctx, int vcpu);
 
 intvm_active_cpus(struct vmctx *ctx, cpuset_t *cpus);
 intvm_suspended_cpus(struct vmctx *ctx, cpuset_t *cpus);
+intvm_debug_cpus(struct vmctx *ctx, cpuset_t *cpus);
 intvm_activate_cpu(struct vmctx *ctx, int vcpu);
+intvm_suspend_cpu(struct vmctx *ctx, int vcpu);
+intvm_resume_cpu(struct vmctx *ctx, int vcpu);
 
 /*
  * FreeBSD specific APIs

Modified: head/sys/amd64/include/vmm.h
==
--- head/sys/amd64/include/vmm.hFri Apr  6 21:50:09 2018
(r332156)
+++ head/sys/amd64/include/vmm.hFri Apr  6 22:03:43 2018
(r332157)
@@ -231,8 +231,11 @@ int vm_get_x2apic_state(struct vm *vm, int vcpu, enum 
 int vm_set_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state state);
 int vm_apicid2vcpuid(struct vm *vm, int apicid);
 int vm_activate_cpu(struct vm *vm, int vcpu);
+int vm_suspend_cpu(struct vm *vm, int vcpu);
+int vm_resume_cpu(struct vm *vm, int vcpu);
 struct vm_exit *vm_exitinfo(struct vm *vm, int vcpuid);
 void vm_exit_suspended(struct vm *vm, int vcpuid, uint64_t rip);
+void vm_exit_debug(struct vm *vm, int vcpuid, uint64_t rip);
 void vm_exit_rendezvous(struct vm *vm, int vcpuid, uint64_t rip);
 void vm_exit_astpending(struct vm *vm, int vcpuid, uint64_t rip);
 void vm_exit_reqidle(struct vm *vm, int v

Re: svn commit: r332133 - head/sys/conf

2018-04-06 Thread John Baldwin
On Friday, April 06, 2018 07:11:22 PM Brooks Davis wrote:
> Author: brooks
> Date: Fri Apr  6 19:11:22 2018
> New Revision: 332133
> URL: https://svnweb.freebsd.org/changeset/base/332133
> 
> Log:
>   Add an unused _COMPAT_LINUX32 option to ensure opt_compat.h exists on
>   platforms without COMPAT_LINUX32.

I wonder if it wouldn't be cleaner to just move COMPAT_LINUX32 itself to
sys/conf/options?

-- 
John Baldwin
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r332158 - head/sys/net

2018-04-06 Thread Brooks Davis
Author: brooks
Date: Fri Apr  6 23:25:54 2018
New Revision: 332158
URL: https://svnweb.freebsd.org/changeset/base/332158

Log:
  Remove the thread argument from ifr_buffer_*() accessors.
  
  They are always used in a context where curthread is the correct thread.
  This makes them more similar to the ifr_data_get_ptr() accessor.

Modified:
  head/sys/net/if.c

Modified: head/sys/net/if.c
==
--- head/sys/net/if.c   Fri Apr  6 22:03:43 2018(r332157)
+++ head/sys/net/if.c   Fri Apr  6 23:25:54 2018(r332158)
@@ -2403,13 +2403,13 @@ ifunit(const char *name)
 }
 
 static void *
-ifr_buffer_get_buffer(struct thread *td, void *data)
+ifr_buffer_get_buffer(void *data)
 {
union ifreq_union *ifrup;
 
ifrup = data;
 #ifdef COMPAT_FREEBSD32
-   if (SV_PROC_FLAG(td->td_proc, SV_ILP32))
+   if (SV_CURPROC_FLAG(SV_ILP32))
return ((void *)(uintptr_t)
ifrup->ifr32.ifr_ifru.ifru_buffer.buffer);
 #endif
@@ -2417,13 +2417,13 @@ ifr_buffer_get_buffer(struct thread *td, void *data)
 }
 
 static void
-ifr_buffer_set_buffer_null(struct thread *td, void *data)
+ifr_buffer_set_buffer_null(void *data)
 {
union ifreq_union *ifrup;
 
ifrup = data;
 #ifdef COMPAT_FREEBSD32
-   if (SV_PROC_FLAG(td->td_proc, SV_ILP32))
+   if (SV_CURPROC_FLAG(SV_ILP32))
ifrup->ifr32.ifr_ifru.ifru_buffer.buffer = 0;
else
 #endif
@@ -2431,26 +2431,26 @@ ifr_buffer_set_buffer_null(struct thread *td, void *da
 }
 
 static size_t
-ifr_buffer_get_length(struct thread *td, void *data)
+ifr_buffer_get_length(void *data)
 {
union ifreq_union *ifrup;
 
ifrup = data;
 #ifdef COMPAT_FREEBSD32
-   if (SV_PROC_FLAG(td->td_proc, SV_ILP32))
+   if (SV_CURPROC_FLAG(SV_ILP32))
return (ifrup->ifr32.ifr_ifru.ifru_buffer.length);
 #endif
return (ifrup->ifr.ifr_ifru.ifru_buffer.length);
 }
 
 static void
-ifr_buffer_set_length(struct thread *td, void *data, size_t len)
+ifr_buffer_set_length(void *data, size_t len)
 {
union ifreq_union *ifrup;
 
ifrup = data;
 #ifdef COMPAT_FREEBSD32
-   if (SV_PROC_FLAG(td->td_proc, SV_ILP32))
+   if (SV_CURPROC_FLAG(SV_ILP32))
ifrup->ifr32.ifr_ifru.ifru_buffer.length = len;
else
 #endif
@@ -2531,12 +2531,12 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data,
else {
/* space for terminating nul */
descrlen = strlen(ifp->if_description) + 1;
-   if (ifr_buffer_get_length(td, ifr) < descrlen)
-   ifr_buffer_set_buffer_null(td, ifr);
+   if (ifr_buffer_get_length(ifr) < descrlen)
+   ifr_buffer_set_buffer_null(ifr);
else
error = copyout(ifp->if_description,
-   ifr_buffer_get_buffer(td, ifr), descrlen);
-   ifr_buffer_set_length(td, ifr, descrlen);
+   ifr_buffer_get_buffer(ifr), descrlen);
+   ifr_buffer_set_length(ifr, descrlen);
}
sx_sunlock(&ifdescr_sx);
break;
@@ -2552,15 +2552,15 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data,
 * length parameter is supposed to count the
 * terminating nul in.
 */
-   if (ifr_buffer_get_length(td, ifr) > ifdescr_maxlen)
+   if (ifr_buffer_get_length(ifr) > ifdescr_maxlen)
return (ENAMETOOLONG);
-   else if (ifr_buffer_get_length(td, ifr) == 0)
+   else if (ifr_buffer_get_length(ifr) == 0)
descrbuf = NULL;
else {
-   descrbuf = malloc(ifr_buffer_get_length(td, ifr),
+   descrbuf = malloc(ifr_buffer_get_length(ifr),
M_IFDESCR, M_WAITOK | M_ZERO);
-   error = copyin(ifr_buffer_get_buffer(td, ifr), descrbuf,
-   ifr_buffer_get_length(td, ifr) - 1);
+   error = copyin(ifr_buffer_get_buffer(ifr), descrbuf,
+   ifr_buffer_get_length(ifr) - 1);
if (error) {
free(descrbuf, M_IFDESCR);
break;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"