Re: ls(1): Missing fts_close(3)

2015-06-23 Thread Ingo Schwarze
Ouch.

Theo de Raadt wrote on Tue, Jun 23, 2015 at 09:40:57PM -0600:
> Ingo Schwarze wrote:

>> the file ls/main.c is a joke.
>> Minus one file, minus 15 lines of code, no functional change.
>> OK?

> No, because commiting that would break the tree. 
> Get ready for a shock.

Indeed: /usr/src/libexec/ftpd/{Makefile,popen.c}

Sorry for the noise.
  Ingo


Index: main.c
===
RCS file: /cvs/src/bin/ls/main.c,v
retrieving revision 1.4
diff -u -p -r1.4 main.c
--- main.c  4 Dec 2012 02:27:00 -   1.4
+++ main.c  24 Jun 2015 04:06:56 -
@@ -2,6 +2,8 @@
 
 /*
  * Public domain - no warranty.
+ *
+ * Needed because /usr/src/libexec/ftpd/popen.c calls ls_main(), too.
  */
 
 int ls_main(int argc, char **argv);



Re: ls(1): Missing fts_close(3)

2015-06-23 Thread Theo de Raadt
> the file ls/main.c is a joke.
> 
> Minus one file, minus 15 lines of code, no functional change.
> 
> OK?

No, because commiting that would break the tree. 

Get ready for a shock.



Re: ls(1): Missing fts_close(3)

2015-06-23 Thread Theo de Raadt
> Masao Uebayashi wrote on Wed, Jun 24, 2015 at 12:16:35PM +0900:
> 
> > ls(1) omits fts_close(3) after fts_open(3), resulting in an FD leak.
> > Found by Valgrind.
> 
> As far as i can see, the code is correct, there doesn't seem to be
> a leak.

There is an ABI misuse; which creates what is a leak-on-the-way-to-exit

> The function traverse() is static and only called at the
> very end of ls_main().  The function ls_main() is only called at
> the very end of main(), file main.c.  So your patch would close
> the file descriptor right before exit.

And free memory, too.

I have ok'd his change, because it is not worse.  Really better if
people to clarify discoveries of "it is a leak!" seperately from
the class of "this is a momentary leak just before exit".  Such a
small shortcut will reduce the converstation..



Re: ls(1): Missing fts_close(3)

2015-06-23 Thread Ingo Schwarze
Hi,

the file ls/main.c is a joke.

Minus one file, minus 15 lines of code, no functional change.

OK?
  Ingo


Index: Makefile
===
RCS file: /cvs/src/bin/ls/Makefile,v
retrieving revision 1.7
diff -u -p -r1.7 Makefile
--- Makefile6 Aug 2003 19:09:09 -   1.7
+++ Makefile24 Jun 2015 03:35:00 -
@@ -1,7 +1,7 @@
 #  $OpenBSD: Makefile,v 1.7 2003/08/06 19:09:09 tedu Exp $
 
 PROG=  ls
-SRCS=  cmp.c ls.c main.c print.c util.c
+SRCS=  cmp.c ls.c print.c util.c
 DPADD= ${LIBUTIL}
 LDADD= -lutil
 
Index: ls.c
===
RCS file: /cvs/src/bin/ls/ls.c,v
retrieving revision 1.40
diff -u -p -r1.40 ls.c
--- ls.c18 Apr 2015 18:28:36 -  1.40
+++ ls.c24 Jun 2015 03:35:00 -
@@ -95,7 +95,7 @@ int f_typedir;/* add type character f
 int rval;
 
 int
-ls_main(int argc, char *argv[])
+main(int argc, char *argv[])
 {
static char dot[] = ".", *dotav[] = { dot, NULL };
struct winsize win;
Index: ls.h
===
RCS file: /cvs/src/bin/ls/ls.h,v
retrieving revision 1.9
diff -u -p -r1.9 ls.h
--- ls.h30 May 2013 16:34:32 -  1.9
+++ ls.h24 Jun 2015 03:35:00 -
@@ -73,5 +73,3 @@ typedef struct {
char *flags;
char data[1];
 } NAMES;
-
-intls_main(int, char *[]);
Index: main.c
===
RCS file: main.c
diff -N main.c
--- main.c  4 Dec 2012 02:27:00 -   1.4
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,13 +0,0 @@
-/* $OpenBSD: main.c,v 1.4 2012/12/04 02:27:00 deraadt Exp $*/
-
-/*
- * Public domain - no warranty.
- */
-
-int ls_main(int argc, char **argv);
-
-int
-main(int argc, char *argv[])
-{
-   return ls_main(argc, argv);
-}



Re: ls(1): Missing fts_close(3)

2015-06-23 Thread Ingo Schwarze
Hi,

Masao Uebayashi wrote on Wed, Jun 24, 2015 at 12:16:35PM +0900:

> ls(1) omits fts_close(3) after fts_open(3), resulting in an FD leak.
> Found by Valgrind.

As far as i can see, the code is correct, there doesn't seem to be
a leak.  The function traverse() is static and only called at the
very end of ls_main().  The function ls_main() is only called at
the very end of main(), file main.c.  So your patch would close
the file descriptor right before exit.

Yours,
  Ingo


> Index: bin/ls/ls.c
> ===
> RCS file: /cvs/src/bin/ls/ls.c,v
> retrieving revision 1.40
> diff -u -p -r1.40 ls.c
> --- bin/ls/ls.c   18 Apr 2015 18:28:36 -  1.40
> +++ bin/ls/ls.c   24 Jun 2015 03:10:47 -
> @@ -403,6 +403,8 @@ traverse(int argc, char *argv[], int opt
>   }
>   if (errno)
>   err(1, "fts_read");
> +
> + fts_close(ftsp);
>  }
>  
>  /*



ls(1): Missing fts_close(3)

2015-06-23 Thread Masao Uebayashi
ls(1) omits fts_close(3) after fts_open(3), resulting in an FD leak.
Found by Valgrind.

Index: bin/ls/ls.c
===
RCS file: /cvs/src/bin/ls/ls.c,v
retrieving revision 1.40
diff -u -p -r1.40 ls.c
--- bin/ls/ls.c 18 Apr 2015 18:28:36 -  1.40
+++ bin/ls/ls.c 24 Jun 2015 03:10:47 -
@@ -403,6 +403,8 @@ traverse(int argc, char *argv[], int opt
}
if (errno)
err(1, "fts_read");
+
+   fts_close(ftsp);
 }
 
 /*



Re: pkg_info: print used repos

2015-06-23 Thread Theo de Raadt
-   $state->handle_options('cCdfF:hIKLmPQ:qr:RsSUe:E:Ml:aAt',
+   $state->handle_options('cCdfF:hIKLmpPQ:qr:RsSUe:E:Ml:aAt',

Starting to look a lot like ls.

It would be really nice if -- when something is added -- something
extra and unused is excised at the same time...





pkg_info: print used repos

2015-06-23 Thread Jean-Philippe Ouellet
This adds a -p option to pkg_info to show the PackageRepositorys
being used.

Inspired by trying to parse /etc/pkg.conf with some awk and quickly
realized that was the wrong way to solve my problem. I then wrote
some perl that reached into OpenBSD:: internals, but concluded it'd
be much cleaner for external consumers to just invoke pkg_info.


Index: pkg_info.1
===
RCS file: /cvs/src/usr.sbin/pkg_add/pkg_info.1,v
retrieving revision 1.50
diff -u -p -d -r1.50 pkg_info.1
--- pkg_info.1  8 Sep 2014 01:27:55 -   1.50
+++ pkg_info.1  23 Jun 2015 22:05:53 -
@@ -24,7 +24,7 @@
 .Sh SYNOPSIS
 .Nm pkg_info
 .Bk -words
-.Op Fl AaCcdfIKLMmPqRSstUv
+.Op Fl AaCcdfIKLMmPpqRSstUv
 .Op Fl E Ar filename
 .Op Fl e Ar pkg-name
 .Op Fl l Ar str
@@ -151,6 +151,8 @@ Show the
 .Xr pkgpath 7
 for each package.
 You can easily build a subdirlist with this.
+.It Fl p
+Show the actual package paths being used.
 .It Fl Q Ar query
 Show all packages in $PKG_PATH which match the given
 .Ar query .
Index: OpenBSD/PackageRepositoryList.pm
===
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm,v
retrieving revision 1.29
diff -u -p -d -r1.29 PackageRepositoryList.pm
--- OpenBSD/PackageRepositoryList.pm3 Feb 2015 10:26:29 -   1.29
+++ OpenBSD/PackageRepositoryList.pm23 Jun 2015 22:06:49 -
@@ -100,4 +100,14 @@ sub print_without_src
return join(':', @l);
 }
 
+sub print
+{
+   my $self = shift;
+   my @l = ();
+   for my $repo (@{$self->{l}}) {
+   push(@l, $repo->url);
+   }
+   return join("\n", @l);
+}
+
 1;
Index: OpenBSD/PkgInfo.pm
===
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm,v
retrieving revision 1.35
diff -u -p -d -r1.35 PkgInfo.pm
--- OpenBSD/PkgInfo.pm  6 Apr 2015 12:19:35 -   1.35
+++ OpenBSD/PkgInfo.pm  23 Jun 2015 22:05:53 -
@@ -557,7 +557,7 @@ sub parse_and_run
}
};
$state->{no_exports} = 1;
-   $state->handle_options('cCdfF:hIKLmPQ:qr:RsSUe:E:Ml:aAt',
+   $state->handle_options('cCdfF:hIKLmpPQ:qr:RsSUe:E:Ml:aAt',
'[-AaCcdfIKLMmPqRSstUv] [-D nolock][-E filename] [-e pkg-name] ',
'[-l str] [-Q query] [-r pkgspec] [pkg-name] [...]');
 
@@ -610,6 +609,13 @@ sub parse_and_run
is_installed($p) ? "#1 (installed)" : "#1", $p);
}
 
+   return 0;
+   }
+
+   if ($state->opt('p')) {
+   require OpenBSD::PackageLocator;
+   OpenBSD::PackageLocator->build_default_path($state);
+   $state->say(OpenBSD::PackageLocator->default_path()->print());
return 0;
}
 



PackageRepositoryList - kill dead code

2015-06-23 Thread Jean-Philippe Ouellet
This is no longer used anywhere, and even crashes if you try to call it.
Besides, OpenBSD::PackageRepository::Source was removed almost a year ago.

Index: PackageRepositoryList.pm
===
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PackageRepositoryList.pm,v
retrieving revision 1.29
diff -u -p -d -r1.29 PackageRepositoryList.pm
--- PackageRepositoryList.pm3 Feb 2015 10:26:29 -   1.29
+++ PackageRepositoryList.pm23 Jun 2015 21:51:18 -
@@ -89,15 +89,4 @@ sub match_locations
return [];
 }
 
-sub print_without_src
-{
-   my $self = shift;
-   my @l = ();
-   for my $repo (@$self) {
-   next if $repo->isa("OpenBSD::PackageRepository::Source");
-   push(@l, $repo->url);
-   }
-   return join(':', @l);
-}
-
 1;



Remove broken and wrong PKG_PATH output from pkg_info -vQ

2015-06-23 Thread Jean-Philippe Ouellet
The idea was to print the package repository used followed by the stuff
found in it, but that doesn't work:
  $ pkg_info -vQ foo
  Use of uninitialized value $ENV{"PKG_PATH"} in concatenation (.) or string at 
/usr/libdata/perl5/OpenBSD/PkgInfo.pm line 604.
  PKG_PATH=
  foo2zjs-20140627
  foobillard-3.0ap0
  fookebox-0.7.1p1
  foomatic-db-4.0.20150415
  foomatic-db-engine-4.0.12p0

The value it was trying to print is wrong anyway since PackageRepositoryList
is influenced by more than just $ENV, and isn't necessarily a single value
anyway since pkg.conf can have
  installpath = repo1
  installpath += repo2
and rarely actually is a single value since we implicitly prepend file:./

This patch removes the broken behavior. I plan to separately introduce
a more robust way of enumerating the used package repositories in a
following patch.


Index: PkgInfo.pm
===
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm,v
retrieving revision 1.35
diff -u -p -d -r1.35 PkgInfo.pm
--- PkgInfo.pm  6 Apr 2015 12:19:35 -   1.35
+++ PkgInfo.pm  23 Jun 2015 19:59:26 -
@@ -601,7 +601,6 @@ sub parse_and_run
if ($state->opt('Q')) {
require OpenBSD::Search;
 
-   print "PKG_PATH=$ENV{PKG_PATH}\n" if $state->verbose;
my $partial = 
OpenBSD::Search::PartialStem->new($state->opt('Q'));
my $r = $state->repo->match_locations($partial);
 



Re: interfaces and priorities for relayd routers

2015-06-23 Thread David Gwynne

> On 22 Jun 2015, at 18:20, Reyk Floeter  wrote:
> 
> Hi,
> 
> On Thu, May 14, 2015 at 09:44:22PM +1000, David Gwynne wrote:
>> i want relayd to check teh availability of some services and inject
>> routes when the service is available. if it is available, i want
>> to advertise the routes using ospfd, but i also want the local
>> machine to be able to contact the service even if it isnt the carp
>> master.
>> 
>> to do that i need to inject the routes twice, once on my real
>> interface and again on my carp interfaces. the route on the real
>> interface needs to be a higher priority than the carp route.
>> 
>> this shuffles relayd to accomodate this.
>> 
>> it mostly adds stuff to the route statements in routers, but i also
>> take priorities away from hosts in tables so i can specify them on
>> routes.
>> 
> 
> I'm generally ok with extending the use cases of router, but it seems
> that you're replacing one narrow use case with another one.
> 
> The router code was mostly done for something like "link balancing",
> you have two or more uplink gateways and want to select the route
> based on their availability.  I'm afraid that moving the priority from
> hosts to routes, and changing the semantics, breaks this original use
> case somehow.
> 
>   table  {
>   $gw1 ip ttl 1 priority 8,
>   $gw2 ip ttl 1 priority 52
>   }
>   router "uplinks" {
>   route 0.0.0.0/0
>   forward to  check icmp
>   }
> 
> But maybe even multiple routes for something internal:
> 
>   router "srvlan" {
>   route 10.10.0.0/16
>   route 10.40.0.0/16
>   forward to  check icmp
>   }
> 
> Sometimes different gateways can even be connected via the same interface!
> (e.g. with an intermediate switch and a single cable to the OpenBSD box)
> 
>> this is an example config:
>> 
>>  rns_nogal=130.102.71.227
>>  rns_neem=130.102.71.229
>> 
>>  table  { $rns_nogal ip ttl 1, $rns_neem ip ttl 1 } 
>> 
>>  router "rns" { 
>>  route 130.102.71.160/31 interface vlan888 priority 8
>>  route 130.102.71.160/31 interface carp40888 priority 16
>>  forward to  check icmp 
>>  }
>> 
> 
> I'm wondering, how would you translate my examples above?

hrm.

we could allow priorities on both the route statements and on the host 
statements in the table and combine them somehow when the actual routes are 
inserted into the kernel. or allow a relative priorities to be specified with a 
+ or - prefix. eg:

table  {
  $gw1 priority +1,
  $gw2
}

router "uplinks" {
  route 0.0.0.0/0 priority 16
  forward to  check icmp
}

if you add increase the priority of a route, should its numeric value get 
higher or lower?

anyway, allowing priorities in both tables and router blocks would cover both 
use cases i think.

> 
>>  redirect "dns" {
>>  listen on 130.102.71.160 tcp port 53
>>  listen on 130.102.71.160 udp port 53
>>  listen on 130.102.71.161 tcp port 53
>>  listen on 130.102.71.161 udp port 53
>> 
>>  match pftag rns
>>  forward to  port 53 check icmp
>>  }
>> 
>> i wish redirects took a prefix. maybe thats a diff for another day.
>> 
> 
> Would make sense.
> 
>> anyway, here's the diff.
>> 
>> thoughts? tweaks? ok?
>> 
> 
> In addition to my general concern, see comments inline below.
> 
> Reyk
> 
>> Index: parse.y
>> ===
>> RCS file: /cvs/src/usr.sbin/relayd/parse.y,v
>> retrieving revision 1.204
>> diff -u -p -r1.204 parse.y
>> --- parse.y  2 May 2015 13:15:24 -   1.204
>> +++ parse.y  14 May 2015 11:30:28 -
>> @@ -173,6 +173,7 @@ typedef struct {
>> %token   ROUTER RTLABEL TRANSPARENT TRAP UPDATES URL VIRTUAL WITH TTL 
>> RTABLE
>> %token   MATCH PARAMS RANDOM LEASTSTATES SRCHASH KEY CERTIFICATE 
>> PASSWORD ECDH
>> %token   EDH CURVE
>> +%token  NONE LOCAL CONNECTED STATIC OSPF ISIS RIP BGP DEFAULT
> 
> A lot of keywords for basically an "enum".  See below.
> 
>> %token STRING
>> %token NUMBER
>> %type  hostname interface table value optstring
>> @@ -182,6 +183,7 @@ typedef struct {
>> %type  redirect_proto relay_proto match
>> %type  action ruleaf key_option
>> %type  tlsdhparams tlsecdhcurve
>> +%type rtprio
>> %typeport
>> %typehost
>> %typeaddress
>> @@ -1864,8 +1866,8 @@ router : ROUTER STRING {
>>  router = rt;
>> 
>>  tableport = -1;
>> -} '{' optnl routeopts_l '}' {
>> -if (!router->rt_conf.nroutes) {
>> +} '{' optnl routeropts_l '}'{
>> +if (TAILQ_EMPTY(&router->rt_netroutes)) {
>>  yyerror("router %s without routes",
>>   

Re: [diff] trivia: change xorl => xorq

2015-06-23 Thread Mike Larkin
On Tue, Jun 23, 2015 at 02:33:51PM -0700, Philip Guenther wrote:
> On Tue, Jun 23, 2015 at 1:18 PM, Mike Larkin  wrote:
> > On Tue, Jun 23, 2015 at 09:49:26AM +0300, Alexey Dobriyan wrote:
> >> Clearing 32-bit register clears whole register, save REX prefix.
> >
> > I see nothing documented in the Intel SDM that says this. Can you cite
> > a reference to support this claim?
> 
> It's true.  Volume 1, section 3.4.1 says this:
> 
>   When in 64-bit mode, operand size determines the number of valid
> bits in the destination general-purpose register:
> 
> ?? 64-bit operands generate a 64-bit result in the destination
> general-purpose register.
> ?? 32-bit operands generate a 32-bit result, zero-extended to a 64-bit
> result in the destination general-purpose register.
> ?? 8-bit and 16-bit operands generate an 8-bit or 16-bit result. The
> upper 56 bits or 48 bits (respectively) of the
>  destination general-purpose register are not modified by the
> operation. If the result of an 8-bit or 16-bit
>  operation is intended for 64-bit address calculation, explicitly
> sign-extend the register to the full 64-bits.
> 
> 
> It's also mentioned in the optimization guide:
> 
> 9.2.1 Use Legacy 32-Bit Instructions When Data Size Is 32 Bits
> 
> 64-bit mode makes 16 general purpose 64-bit registers available to
> applications. If application data size
> is 32 bits, there is no need to use 64-bit registers or 64-bit arithmetic.
> 
> The default operand size for most instructions is 32 bits. The
> behavior of those instructions is to make
> the upper 32 bits all zeros. For example, when zeroing out a register,
> the following two instruction
> streams do the same thing, but the 32-bit version saves one instruction byte:
> 32-bit version:
> xor eax, eax; Performs xor on lower 32bits and zeroes the upper 32 
> bits.
> 
> 64-bit version:
> xor rax, rax; Performs xor on all 64 bits.
> 
> 
> 
> > An aside - even if this were true, I still prefer xorq and the extra
> > rex prefix byte because it more correctly conveys the intent of the
> > programmer.
> 
> I disagree.
> 
> 
> Philip Guenther
> 

Then please go ahead and commit the change. No further objection from me.

-ml



Re: [diff] trivia: change xorl => xorq

2015-06-23 Thread Philip Guenther
On Tue, Jun 23, 2015 at 1:18 PM, Mike Larkin  wrote:
> On Tue, Jun 23, 2015 at 09:49:26AM +0300, Alexey Dobriyan wrote:
>> Clearing 32-bit register clears whole register, save REX prefix.
>
> I see nothing documented in the Intel SDM that says this. Can you cite
> a reference to support this claim?

It's true.  Volume 1, section 3.4.1 says this:

  When in 64-bit mode, operand size determines the number of valid
bits in the destination general-purpose register:

· 64-bit operands generate a 64-bit result in the destination
general-purpose register.
· 32-bit operands generate a 32-bit result, zero-extended to a 64-bit
result in the destination general-purpose register.
· 8-bit and 16-bit operands generate an 8-bit or 16-bit result. The
upper 56 bits or 48 bits (respectively) of the
 destination general-purpose register are not modified by the
operation. If the result of an 8-bit or 16-bit
 operation is intended for 64-bit address calculation, explicitly
sign-extend the register to the full 64-bits.


It's also mentioned in the optimization guide:

9.2.1 Use Legacy 32-Bit Instructions When Data Size Is 32 Bits

64-bit mode makes 16 general purpose 64-bit registers available to
applications. If application data size
is 32 bits, there is no need to use 64-bit registers or 64-bit arithmetic.

The default operand size for most instructions is 32 bits. The
behavior of those instructions is to make
the upper 32 bits all zeros. For example, when zeroing out a register,
the following two instruction
streams do the same thing, but the 32-bit version saves one instruction byte:
32-bit version:
xor eax, eax; Performs xor on lower 32bits and zeroes the upper 32 bits.

64-bit version:
xor rax, rax; Performs xor on all 64 bits.



> An aside - even if this were true, I still prefer xorq and the extra
> rex prefix byte because it more correctly conveys the intent of the
> programmer.

I disagree.


Philip Guenther



Re: [diff] trivia: change xorl => xorq

2015-06-23 Thread Mike Larkin
On Tue, Jun 23, 2015 at 09:49:26AM +0300, Alexey Dobriyan wrote:
> Clearing 32-bit register clears whole register, save REX prefix.

I see nothing documented in the Intel SDM that says this. Can you cite
a reference to support this claim?

An aside - even if this were true, I still prefer xorq and the extra
rex prefix byte because it more correctly conveys the intent of the
programmer.

-ml

> 
> Index: arch/amd64/amd64/acpi_wakecode.S
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/acpi_wakecode.S,v
> retrieving revision 1.35
> diff -u -p -u -r1.35 acpi_wakecode.S
> --- arch/amd64/amd64/acpi_wakecode.S  8 Dec 2014 07:12:37 -   1.35
> +++ arch/amd64/amd64/acpi_wakecode.S  20 Jun 2015 17:56:47 -
> @@ -307,7 +307,7 @@ _C_LABEL(acpi_long_mode_resume):
>   lidtacpi_saved_idt
>  
>   /* Restore the saved task register */
> - xorq%rcx, %rcx
> + xorl%ecx, %ecx
>   movwacpi_saved_tr, %cx
>   movqacpi_saved_gdt+2, %rax
>   andb$0xF9, 5(%rax,%rcx)
> @@ -337,7 +337,7 @@ _C_LABEL(acpi_long_mode_resume):
>   movqacpi_saved_cr3, %rax
>   movq%rax, %cr3
>  
> - xorq%rax, %rax  
> + xorl%eax, %eax
>   jmp *acpi_saved_ret
>  
>  #ifdef HIBERNATE
> Index: arch/amd64/amd64/copy.S
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/copy.S,v
> retrieving revision 1.6
> diff -u -p -u -r1.6 copy.S
> --- arch/amd64/amd64/copy.S   16 Jan 2015 10:17:51 -  1.6
> +++ arch/amd64/amd64/copy.S   20 Jun 2015 17:56:47 -
> @@ -93,7 +93,7 @@ ENTRY(kcopy)
>  
>   movqCPUVAR(CURPCB),%rdx
>   popqPCB_ONFAULT(%rdx)
> - xorq%rax,%rax
> + xorl%eax,%eax
>   ret
>  
>  1:   addq%rcx,%rdi   # copy backward
> @@ -114,7 +114,7 @@ ENTRY(kcopy)
>  
>   movqCPUVAR(CURPCB),%rdx
>   popqPCB_ONFAULT(%rdx)
> - xorq%rax,%rax
> + xorl%eax,%eax
>   ret
>  
>  ENTRY(copyout)
> @@ -222,7 +222,7 @@ ENTRY(copyoutstr)
>  
>   /* Success -- 0 byte reached. */
>   decq%rdx
> - xorq%rax,%rax
> + xorl%eax,%eax
>   jmp copystr_return
>  
>  2:   /* rdx is zero -- return EFAULT or ENAMETOOLONG. */
> @@ -265,7 +265,7 @@ ENTRY(copyinstr)
>  
>   /* Success -- 0 byte reached. */
>   decq%rdx
> - xorq%rax,%rax
> + xorl%eax,%eax
>   jmp copystr_return
>  
>  2:   /* edx is zero -- return EFAULT or ENAMETOOLONG. */
> Index: arch/amd64/amd64/locore.S
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/locore.S,v
> retrieving revision 1.62
> diff -u -p -u -r1.62 locore.S
> --- arch/amd64/amd64/locore.S 16 Jan 2015 10:17:51 -  1.62
> +++ arch/amd64/amd64/locore.S 20 Jun 2015 17:56:47 -
> @@ -732,7 +732,7 @@ longmode_hi:
>   movq%rax,_C_LABEL(proc0paddr)(%rip)
>   leaq(USPACE-FRAMESIZE)(%rax),%rsp
>   movq%rsi,PCB_CR3(%rax)  # pcb->pcb_cr3
> - xorq%rbp,%rbp   # mark end of frames
> + xorl%ebp,%ebp   # mark end of frames
>  
>   xorw%ax,%ax
>   movw%ax,%gs
> @@ -1071,7 +1071,7 @@ syscall_return:
>   movlTF_RDI(%rsp),%edx
>   movl%ebx,%ecx
>   movlCPUVAR(ILEVEL),%r8d
> - xorq%rax,%rax
> + xorl%eax,%eax
>   call_C_LABEL(printf)
>  #ifdef DDB
>   int $3
> @@ -1143,7 +1143,7 @@ _C_LABEL(doreti_iret):
>  #ifdef DIAGNOSTIC
>  3:   sti
>   movabsq $4f, %rdi
> - xorq%rax,%rax
> + xorl%eax,%eax
>   call_C_LABEL(printf)
>  #ifdef DDB
>   int $3
> @@ -1157,7 +1157,7 @@ _C_LABEL(doreti_iret):
>  ENTRY(pagezero)
>   movq$-PAGE_SIZE,%rdx
>   subq%rdx,%rdi
> - xorq%rax,%rax
> + xorl%eax,%eax
>  1:
>   movnti  %rax,(%rdi,%rdx)
>   movnti  %rax,8(%rdi,%rdx)
> Index: arch/amd64/amd64/mptramp.S
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/mptramp.S,v
> retrieving revision 1.11
> diff -u -p -u -r1.11 mptramp.S
> --- arch/amd64/amd64/mptramp.S8 Dec 2014 07:49:17 -   1.11
> +++ arch/amd64/amd64/mptramp.S20 Jun 2015 17:56:47 -
> @@ -189,7 +189,7 @@ _TRMP_LABEL(mptramp_longmode)
>  _C_LABEL(cpu_spinup_trampoline_end): #end of code copied to MP_TRAMPOLINE
>   movl_C_LABEL(local_apic)+LAPIC_ID,%eax
>   shrl$LAPIC_ID_SHIFT,%eax
> - xorq%rcx,%rcx
> + xorl%ecx,%ecx
>  1:
>   movq_C_LABEL(cpu_info)(,%rcx,8),%rdi
>   incq%rcx
> Index: arch/amd64/amd64/mutex.S
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/mutex.S,v
> retrieving revision 1.9
> diff -u -p -u -r1.9 mutex.S
> --- arch/amd64/amd64/mutex.S  2 Jun 2013 01:55:52 -

Re: httpd rewrites with Lua's pattern matching

2015-06-23 Thread Reyk Floeter
On Tue, Jun 23, 2015 at 02:40:48PM -0400, Jean-Philippe Ouellet wrote:
> On Sat, Jun 20, 2015 at 03:01:18PM +0200, Reyk Floeter wrote:
> > there is some great interest in getting support for rewrites
> 
> What do people think of something like our tftpd(8)'s -r
> 
>-r socket
>  Issue filename rewrite requests to the specified UNIX domain
>  socket.  tftpd will write lines in the format "IP OP filename",
>  terminated by a newline, where IP is the client's IP address, and
>  OP is one of "read" or "write".  tftpd expects replies in the
>  format "filename" terminated by a newline.  All rewrite requests
>  from the daemon must be answered (even if it is with the original
>  filename) before the TFTP request will continue.  By default
>  tftpd does not use filename rewriting.
> 
> I was working on a patch to bring it to httpd but ran out of free time.
> Thought I'd pass the idea by you anyway.
> 
> I think it's a sweet spot of a minimum incrase in complexity and maximum
> incrase in flexibility. Then people could plug in whatever they wanted:
> be it trivial string substitutions, guaranteed safe regexes with re2[1],
> potentially unsafe regexes with pcre, or even database lookups or whatever.
> 
> [1]: https://swtch.com/~rsc/regexp/regexp3.html
> 

I have no oppinion about the use in tftpd,
but it would sound weird for httpd.

The use of patterns.c was intended to have one reasonably simple
implementation, not a button for a "maximum increase of flexibility".
The real question is: what do people _have to_ do and can they also do
it with the new patterns?

>
> Reyk: Sorry for the duplicate, meant to reply to the list.

no problem, I have thousands of openbsd emails, this one won't hurt ;)

Reyk



Re: explicit_bzero in pkcs5_pbkdf2

2015-06-23 Thread Jean-Philippe Ouellet
I now realize this may have been ignored simply because the clock
on the sending machine was horribly off and many people sort mail
by date. So... Should this go in? Am I missing something?

On Thu, Apr 30, 2015 at 06:03:23PM -0400, Jean-Philippe Ouellet wrote:
> The intermediate values calculated in hmac_sha1 as part of
> pkcs5_pbkdf2 are not zeroed afterwards, so we leak a single-hashed
> version of the key on the stack in tk[].
> 
> Also, the correct RFC defining this is
> RFC 2104 - HMAC: Keyed-Hashing for Message Authentication
> not
> RFC 2202 - Test Cases for HMAC-MD5 and HMAC-SHA-1
> 
> From RFC 2104, section 4, paragraph 2:
> "We stress that the stored intermediate values need to
>  be treated and protected the same as secret keys."
> So it's not just best-practice dictating that these should be
> bzeroed.
> 
> Here is a patch for the same code in libutil and libsa.
> 
> Index: lib/libutil/pkcs5_pbkdf2.c
> ===
> RCS file: /cvs/src/lib/libutil/pkcs5_pbkdf2.c,v
> retrieving revision 1.9
> diff -u -p -d -r1.9 pkcs5_pbkdf2.c
> --- lib/libutil/pkcs5_pbkdf2.c5 Feb 2015 12:59:57 -   1.9
> +++ lib/libutil/pkcs5_pbkdf2.c10 Jun 2015 19:59:09 -
> @@ -28,7 +28,7 @@
>  #define  MINIMUM(a,b) (((a) < (b)) ? (a) : (b))
>  
>  /*
> - * HMAC-SHA-1 (from RFC 2202).
> + * HMAC-SHA-1 (from RFC 2104).
>   */
>  static void
>  hmac_sha1(const u_int8_t *text, size_t text_len, const u_int8_t *key,
> @@ -67,6 +67,10 @@ hmac_sha1(const u_int8_t *text, size_t t
>   SHA1Update(&ctx, k_pad, SHA1_BLOCK_LENGTH);
>   SHA1Update(&ctx, digest, SHA1_DIGEST_LENGTH);
>   SHA1Final(digest, &ctx);
> +
> + explicit_bzero(&ctx, sizeof(ctx));
> + explicit_bzero(k_pad, sizeof(k_pad));
> + explicit_bzero(tk, sizeof(tk));
>  }
>  
>  /*
> Index: sys/lib/libsa/hmac_sha1.c
> ===
> RCS file: /cvs/src/sys/lib/libsa/hmac_sha1.c,v
> retrieving revision 1.1
> diff -u -p -d -r1.1 hmac_sha1.c
> --- sys/lib/libsa/hmac_sha1.c 9 Oct 2012 12:36:50 -   1.1
> +++ sys/lib/libsa/hmac_sha1.c 10 Jun 2015 19:58:39 -
> @@ -23,7 +23,7 @@
>  #include "hmac_sha1.h"
>  
>  /*
> - * HMAC-SHA-1 (from RFC 2202).
> + * HMAC-SHA-1 (from RFC 2104).
>   */
>  void
>  hmac_sha1(const u_int8_t *text, size_t text_len, const u_int8_t *key,
> @@ -62,4 +62,8 @@ hmac_sha1(const u_int8_t *text, size_t t
>   SHA1Update(&ctx, k_pad, SHA1_BLOCK_LENGTH);
>   SHA1Update(&ctx, digest, SHA1_DIGEST_LENGTH);
>   SHA1Final(digest, &ctx);
> +
> + explicit_bzero(&ctx, sizeof(ctx));
> + explicit_bzero(k_pad, sizeof(k_pad));
> + explicit_bzero(tk, sizeof(tk));
>  }
> 



Re: httpd rewrites with Lua's pattern matching

2015-06-23 Thread Jean-Philippe Ouellet
On Sat, Jun 20, 2015 at 03:01:18PM +0200, Reyk Floeter wrote:
> there is some great interest in getting support for rewrites

What do people think of something like our tftpd(8)'s -r

   -r socket
 Issue filename rewrite requests to the specified UNIX domain
 socket.  tftpd will write lines in the format "IP OP filename",
 terminated by a newline, where IP is the client's IP address, and
 OP is one of "read" or "write".  tftpd expects replies in the
 format "filename" terminated by a newline.  All rewrite requests
 from the daemon must be answered (even if it is with the original
 filename) before the TFTP request will continue.  By default
 tftpd does not use filename rewriting.

I was working on a patch to bring it to httpd but ran out of free time.
Thought I'd pass the idea by you anyway.

I think it's a sweet spot of a minimum incrase in complexity and maximum
incrase in flexibility. Then people could plug in whatever they wanted:
be it trivial string substitutions, guaranteed safe regexes with re2[1],
potentially unsafe regexes with pcre, or even database lookups or whatever.

[1]: https://swtch.com/~rsc/regexp/regexp3.html


Reyk: Sorry for the duplicate, meant to reply to the list.



Re: [patch] httpd: escape matched substring

2015-06-23 Thread Reyk Floeter
On Tue, Jun 23, 2015 at 06:03:48PM +0200, Sebastien Marie wrote:
> On Tue, Jun 23, 2015 at 04:54:22PM +0200, Sebastien Marie wrote:
> > 
> > the matched substrings should be escaped with url_encoded() before
> > expansion.
> > 
> 
> Here the patch to address the escaping problem.
> 
> OK?
> 

Yes, OK

Reyk

> -- 
> Sebastien Marie
> 
> Index: server_http.c
> ===
> RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
> retrieving revision 1.83
> diff -u -p -r1.83 server_http.c
> --- server_http.c 23 Jun 2015 15:23:14 -  1.83
> +++ server_http.c 23 Jun 2015 16:00:40 -
> @@ -911,8 +911,11 @@ server_expand_http(struct client *clt, c
>   return (NULL);
>  
>   /* Expand variable with matched value */
> - if (expand_string(buf, len, ibuf,
> - clt->clt_srv_match.sm_match[n]) != 0)
> + if ((str = url_encode(clt->clt_srv_match.sm_match[n])) == NULL)
> + return (NULL);
> + ret = expand_string(buf, len, ibuf, str);
> + free(str);
> + if (ret != 0)
>   return (NULL);
>   }
>   if (strstr(val, "$DOCUMENT_URI") != NULL) {

-- 



[patch] httpd: escape matched substring

2015-06-23 Thread Sebastien Marie
On Tue, Jun 23, 2015 at 04:54:22PM +0200, Sebastien Marie wrote:
> 
> the matched substrings should be escaped with url_encoded() before
> expansion.
> 

Here the patch to address the escaping problem.

OK?

-- 
Sebastien Marie

Index: server_http.c
===
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.83
diff -u -p -r1.83 server_http.c
--- server_http.c   23 Jun 2015 15:23:14 -  1.83
+++ server_http.c   23 Jun 2015 16:00:40 -
@@ -911,8 +911,11 @@ server_expand_http(struct client *clt, c
return (NULL);
 
/* Expand variable with matched value */
-   if (expand_string(buf, len, ibuf,
-   clt->clt_srv_match.sm_match[n]) != 0)
+   if ((str = url_encode(clt->clt_srv_match.sm_match[n])) == NULL)
+   return (NULL);
+   ret = expand_string(buf, len, ibuf, str);
+   free(str);
+   if (ret != 0)
return (NULL);
}
if (strstr(val, "$DOCUMENT_URI") != NULL) {



Re: [patch]rcs: mark unlink as (void)

2015-06-23 Thread Fritjof Bornebusch
On Mon, Jun 15, 2015 at 09:56:18PM +0200, Fritjof Bornebusch wrote:

Ping 

> Hi tech@,
> 
> mark this unlink(2) call as *(void)*, as there is no need to check the return 
> value.
> This makes it more consistent to all other unlink(2) calls, since they are 
> marked as *(void)* as
> well.
> 
> Regards,
> --F.
> 
> 
> Index: co.c
> ===
> RCS file: /cvs/src/usr.bin/rcs/co.c,v
> retrieving revision 1.121
> diff -u -p -r1.121 co.c
> --- co.c  13 Jun 2015 20:15:21 -  1.121
> +++ co.c  15 Jun 2015 19:50:12 -
> @@ -553,7 +553,7 @@ checkout_file_has_diffs(RCSFILE *rfp, RC
>   ret = diffreg(dst, tempfile, bp, D_FORCEASCII);
>  
>   buf_free(bp);
> - unlink(tempfile);
> + (void)unlink(tempfile);
>   free(tempfile);
>  
>   return (ret);
> 



Re: [patch]rcs: usage functions above the main ones

2015-06-23 Thread Fritjof Bornebusch
On Mon, Jun 15, 2015 at 11:42:10AM +0100, Nicholas Marriott wrote:
> 
> this seems fine to me
>

Ping 
 
> 
> On Sun, Jun 14, 2015 at 10:38:40PM +0200, Fritjof Bornebusch wrote:
> > Hi tech@,
> > 
> > most of the tools implements the *usage* function above the *main* function.
> > This patch makes it more consistent to these tools and where the different 
> > *usage*
> > functions are implemented in rcs in general.
> > 
> > Any comments?
> > 
> > Regards,
> > --F.
> > 
> > 
> > Index: co.c
> > ===
> > RCS file: /cvs/src/usr.bin/rcs/co.c,v
> > retrieving revision 1.121
> > diff -u -p -r1.121 co.c
> > --- co.c13 Jun 2015 20:15:21 -  1.121
> > +++ co.c14 Jun 2015 20:21:41 -
> > @@ -43,6 +43,17 @@ static void  checkout_err_nobranch(RCSFIL
> >  const char *, int);
> >  static int checkout_file_has_diffs(RCSFILE *, RCSNUM *, const char *);
> >  
> > +__dead void
> > +checkout_usage(void)
> > +{
> > +   fprintf(stderr,
> > +   "usage: co [-TV] [-ddate] [-f[rev]] [-I[rev]] [-kmode] [-l[rev]]\n"
> > +   "  [-M[rev]] [-p[rev]] [-q[rev]] [-r[rev]] [-sstate]\n"
> > +   "  [-u[rev]] [-w[user]] [-xsuffixes] [-ztz] file ...\n");
> > +   
> > +   exit(1);
> > +}
> > +
> >  int
> >  checkout_main(int argc, char **argv)
> >  {
> > @@ -216,17 +227,6 @@ checkout_main(int argc, char **argv)
> > }
> >  
> > return (ret);
> > -}
> > -
> > -__dead void
> > -checkout_usage(void)
> > -{
> > -   fprintf(stderr,
> > -   "usage: co [-TV] [-ddate] [-f[rev]] [-I[rev]] [-kmode] [-l[rev]]\n"
> > -   "  [-M[rev]] [-p[rev]] [-q[rev]] [-r[rev]] [-sstate]\n"
> > -   "  [-u[rev]] [-w[user]] [-xsuffixes] [-ztz] file ...\n");
> > -   
> > -   exit(1);
> >  }
> >  
> >  /*
> > Index: ident.c
> > ===
> > RCS file: /cvs/src/usr.bin/rcs/ident.c,v
> > retrieving revision 1.30
> > diff -u -p -r1.30 ident.c
> > --- ident.c 2 Oct 2014 06:23:15 -   1.30
> > +++ ident.c 14 Jun 2015 20:21:41 -
> > @@ -41,6 +41,14 @@ static int flags = 0;
> >  static voidident_file(const char *, FILE *);
> >  static voidident_line(FILE *);
> >  
> > +__dead void
> > +ident_usage(void)
> > +{
> > +   fprintf(stderr, "usage: ident [-qV] [file ...]\n");
> > +   
> > +   exit(1);
> > +}
> > +
> >  int
> >  ident_main(int argc, char **argv)
> >  {
> > @@ -158,12 +166,4 @@ ident_line(FILE *fp)
> >  out:
> > if (bp != NULL)
> > buf_free(bp);
> > -}
> > -
> > -__dead void
> > -ident_usage(void)
> > -{
> > -   fprintf(stderr, "usage: ident [-qV] [file ...]\n");
> > -   
> > -   exit(1);
> >  }
> > Index: merge.c
> > ===
> > RCS file: /cvs/src/usr.bin/rcs/merge.c,v
> > retrieving revision 1.9
> > diff -u -p -r1.9 merge.c
> > --- merge.c 10 Oct 2014 08:15:25 -  1.9
> > +++ merge.c 14 Jun 2015 20:21:41 -
> > @@ -32,6 +32,15 @@
> >  #include "rcsprog.h"
> >  #include "diff.h"
> >  
> > +__dead void
> > +merge_usage(void)
> > +{
> > +   fprintf(stderr,
> > +   "usage: merge [-EepqV] [-L label] file1 file2 file3\n");
> > +
> > +   exit(D_ERROR);
> > +}
> > +
> >  int
> >  merge_main(int argc, char **argv)
> >  {
> > @@ -108,13 +117,4 @@ merge_main(int argc, char **argv)
> > buf_free(bp);
> >  
> > return (status);
> > -}
> > -
> > -__dead void
> > -merge_usage(void)
> > -{
> > -   (void)fprintf(stderr,
> > -   "usage: merge [-EepqV] [-L label] file1 file2 file3\n");
> > -
> > -   exit(D_ERROR);
> >  }
> > Index: rcsclean.c
> > ===
> > RCS file: /cvs/src/usr.bin/rcs/rcsclean.c,v
> > retrieving revision 1.54
> > diff -u -p -r1.54 rcsclean.c
> > --- rcsclean.c  16 Jan 2015 06:40:11 -  1.54
> > +++ rcsclean.c  14 Jun 2015 20:21:41 -
> > @@ -43,6 +43,16 @@ static int uflag = 0;
> >  static int flags = 0;
> >  static char *locker = NULL;
> >  
> > +__dead void
> > +rcsclean_usage(void)
> > +{
> > +   fprintf(stderr,
> > +   "usage: rcsclean [-TV] [-kmode] [-n[rev]] [-q[rev]] [-r[rev]]\n"
> > +   "[-u[rev]] [-xsuffixes] [-ztz] [file ...]\n");
> > +
> > +   exit(1);
> > +}
> > +
> >  int
> >  rcsclean_main(int argc, char **argv)
> >  {
> > @@ -116,16 +126,6 @@ rcsclean_main(int argc, char **argv)
> > rcsclean_file(argv[i], rev_str);
> >  
> > return (0);
> > -}
> > -
> > -__dead void
> > -rcsclean_usage(void)
> > -{
> > -   fprintf(stderr,
> > -   "usage: rcsclean [-TV] [-kmode] [-n[rev]] [-q[rev]] [-r[rev]]\n"
> > -   "[-u[rev]] [-xsuffixes] [-ztz] [file ...]\n");
> > -
> > -   exit(1);
> >  }
> >  
> >  static void
> > Index: rcsdiff.c
> > ===
> > RCS file: /cvs/src/usr.bin/rcs/rcsdiff.c,v
> > retrieving revision 1.83
> > dif

Re: httpd rewrites with Lua's pattern matching

2015-06-23 Thread trondd
On Tue, June 23, 2015 11:28 am, Reyk Floeter wrote:
> It is just not done yet.  As I said, we're improving the interface.
> But this doesn't affect the initial implementation itself.
>
> Reyk
>

Ok, thanks.  I think I have a 'location match' use case I can play with, too.

Tim.



Re: httpd rewrites with Lua's pattern matching

2015-06-23 Thread Sebastien Marie
On Tue, Jun 23, 2015 at 04:20:58PM +0200, Reyk Floeter wrote:
> On Sat, Jun 20, 2015 at 03:01:18PM +0200, Reyk Floeter wrote:
> > Comments? OK?
> > 
> 
> This diff includes some fixes from semarie@.  We also have regress
> tests that will go in separately.  We'd like to continue in the tree.
> 
> OK?
> 
> Reyk
> 

Some comments below, but I think they could be addressed in tree.
ok semarie@


[...]

> Index: patterns.c
> ===
> RCS file: patterns.c
> diff -N patterns.c
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ patterns.c23 Jun 2015 14:07:16 -
> @@ -0,0 +1,715 @@
> +/*   $OpenBSD$   */
> +
> +/*
> + * Copyright (c) 2015 Reyk Floeter 
> + * Copyright (C) 1994-2015 Lua.org, PUC-Rio.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining
> + * a copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sublicense, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be
> + * included in all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
> + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +/*
> + * Derived from Lua 5.3.1:
> + * $Id: lstrlib.c,v 1.229 2015/05/20 17:39:23 roberto Exp $
> + * Standard library for string operations and pattern-matching
> + */
> +

[...]

> +static int
> +match_class(int c, int cl)
> +{
> + int res;
> + switch (tolower(cl)) {
> + case 'a':
> + res = isalpha(c);
> + break;
> + case 'c':
> + res = iscntrl(c);
> + break;
> + case 'd':
> + res = isdigit(c);
> + break;
> + case 'g':
> + res = isgraph(c);
> + break;
> + case 'l':
> + res = islower(c);
> + break;
> + case 'p':
> + res = ispunct(c);
> + break;
> + case 's':
> + res = isspace(c);
> + break;
> + case 'u':
> + res = isupper(c);
> + break;
> + case 'w':
> + res = isalnum(c);
> + break;
> + case 'x':
> + res = isxdigit(c);
> + break;
> + case 'z':
> + res = (c == 0);
> + break;  /* deprecated option */

I think this deprecated option should be removed. It is deprecated in
lua, but here, the code is new. The documentation don't mention it
either.

> + default:
> + return (cl == c);
> + }
> + return (islower(cl) ? res : !res);
> +}
> +

[...]

> Index: server_http.c
> ===
> RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
> retrieving revision 1.82
> diff -u -p -u -p -r1.82 server_http.c
> --- server_http.c 22 Jun 2015 11:46:06 -  1.82
> +++ server_http.c 23 Jun 2015 14:07:16 -
> @@ -29,14 +29,16 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
>  #include 
> -#include 
> +#include 
>  
>  #include "httpd.h"
>  #include "http.h"
> +#include "patterns.h"
>  
>  static intserver_httpmethod_cmp(const void *, const void *);
>  static intserver_httperror_cmp(const void *, const void *);

[...]

> @@ -882,11 +887,34 @@ server_expand_http(struct client *clt, c
>   struct http_descriptor  *desc = clt->clt_descreq;
>   struct server_config*srv_conf = clt->clt_srv_conf;
>   char ibuf[128], *str, *path, *query;
> - int  ret;
> + const char  *errstr = NULL, *p;
> + size_t   size;
> + int  n, ret;
>  
>   if (strlcpy(buf, val, len) >= len)
>   return (NULL);
>  
> + /* Find previously matched substrings by index */
> + for (p = val; clt->clt_srv_match.sm_nmatch &&
> + (p = strstr(p, "%")) != NULL; p++) {
> + if (!isdigit(*(p + 1)))
> + continue;
> +
> + /* Copy number, leading '%' char and add trailing \0 */
> + size = strspn(p + 1, "0123456789") + 2;
> + if (size  >= sizeof(ibuf))
> + return (NULL);
> + (void)strl

Re: httpd rewrites with Lua's pattern matching

2015-06-23 Thread Reyk Floeter
On Tue, Jun 23, 2015 at 10:25:36AM -0400, trondd wrote:
> On Sun, June 21, 2015 10:01 am, Reyk Floeter wrote:
> >>
> >> location match '^/page/(%d+)' {
> >> block return 302 "/index.cgi?page=%1'
> >> }
> >>
> 
> So I was playing with the below config, then figured out it's not coded to
> capture on 'server match'.  I want to redirect anything I get to use https
> and add the FQDN without having to care which domain they are trying to
> get to.
> 
> A simplified config:
> 
> server match '^(.*)$' {
> listen on em0 port 80
> block return 301 'https://%1.my.fqdn.com/'
> }
> 
> Is there a way to do it?  Any reason to not capture on 'server match'?
> 

It is just not done yet.  As I said, we're improving the interface.
But this doesn't affect the initial implementation itself. 

Reyk



Re: Stop G/C mbufs in if_detach()

2015-06-23 Thread Claudio Jeker
On Tue, Jun 23, 2015 at 03:01:54PM +0200, Martin Pieuchot wrote:
> When an interface is detached or destroyed the CPU executing if_detach()
> removes all the mbufs received by this interface on three queues:
> ARP, IPv4 and IPv6 protocol queues.
> 
> This made sense to avoid referencing a dangling "rcvif" pointer. But now
> mbufs contain unique interface indexes and protocol interrupt routines
> handle just fine the case where if_get() returns a NULL pointer.
> 
> So I'd like to get rid of this explicit garbage collection.  Note that
> this will leave mbufs on the protocol queues until the next netisr is
> executed for the corresponding queue.  This is a functional change but
> I don't think it's a problem.  It only matters if you destroy your only
> pseudo interface or unplug your single USB interface without replugging
> it.
> 
> Comments, oks?

OK claudio@ (there are many more queues that would need to be cleaned if
we wanted this)
 
> Index: net/if.c
> ===
> RCS file: /cvs/src/sys/net/if.c,v
> retrieving revision 1.341
> diff -u -p -r1.341 if.c
> --- net/if.c  23 Jun 2015 09:42:23 -  1.341
> +++ net/if.c  23 Jun 2015 10:54:04 -
> @@ -128,8 +128,6 @@ void  if_attachsetup(struct ifnet *);
>  void if_attachdomain1(struct ifnet *);
>  void if_attach_common(struct ifnet *);
>  
> -int  if_detach_filter(void *, const struct mbuf *);
> -void if_detach_queues(struct ifnet *, struct niqueue *);
>  void if_detached_start(struct ifnet *);
>  int  if_detached_ioctl(struct ifnet *, u_long, caddr_t);
>  
> @@ -644,23 +642,6 @@ if_detach(struct ifnet *ifp)
>   pfi_detach_ifnet(ifp);
>  #endif
>  
> - /*
> -  * remove packets came from ifp, from software interrupt queues.
> -  * net/netisr_dispatch.h is not usable, as some of them use
> -  * strange queue names.
> -  */
> -#define IF_DETACH_QUEUES(x) \
> -do { \
> - extern struct niqueue x; \
> - if_detach_queues(ifp, & x); \
> -} while (0)
> - IF_DETACH_QUEUES(arpintrq);
> - IF_DETACH_QUEUES(ipintrq);
> -#ifdef INET6
> - IF_DETACH_QUEUES(ip6intrq);
> -#endif
> -#undef IF_DETACH_QUEUES
> -
>   /* Remove the interface from the list of all interfaces.  */
>   TAILQ_REMOVE(&ifnet, ifp, if_list);
>   if (ISSET(ifp->if_xflags, IFXF_TXREADY))
> @@ -701,34 +682,6 @@ do { \
>  
>   ifindex2ifnet[ifp->if_index] = NULL;
>   splx(s);
> -}
> -
> -int
> -if_detach_filter(void *ctx, const struct mbuf *m)
> -{
> - struct ifnet *ifp = ctx;
> -
> -#ifdef DIAGNOSTIC
> - if ((m->m_flags & M_PKTHDR) == 0)
> - return (0);
> -#endif
> -
> - return (m->m_pkthdr.ph_ifidx == ifp->if_index);
> -}
> -
> -void
> -if_detach_queues(struct ifnet *ifp, struct niqueue *niq)
> -{
> - struct mbuf *m0, *m;
> -
> - m0 = niq_filter(niq, if_detach_filter, ifp);
> - while (m0 != NULL) {
> - m = m0;
> - m0 = m->m_nextpkt;
> -
> - m->m_nextpkt = NULL;
> - m_freem(m);
> - }
>  }
>  
>  /*
> 

-- 
:wq Claudio



Re: httpd rewrites with Lua's pattern matching

2015-06-23 Thread trondd
On Sun, June 21, 2015 10:01 am, Reyk Floeter wrote:
>>
>> location match '^/page/(%d+)' {
>> block return 302 "/index.cgi?page=%1'
>> }
>>

So I was playing with the below config, then figured out it's not coded to
capture on 'server match'.  I want to redirect anything I get to use https
and add the FQDN without having to care which domain they are trying to
get to.

A simplified config:

server match '^(.*)$' {
listen on em0 port 80
block return 301 'https://%1.my.fqdn.com/'
}

Is there a way to do it?  Any reason to not capture on 'server match'?

Tim.



Re: httpd rewrites with Lua's pattern matching

2015-06-23 Thread Reyk Floeter
On Sat, Jun 20, 2015 at 03:01:18PM +0200, Reyk Floeter wrote:
> Comments? OK?
> 

This diff includes some fixes from semarie@.  We also have regress
tests that will go in separately.  We'd like to continue in the tree.

OK?

Reyk

Index: Makefile
===
RCS file: /cvs/src/usr.sbin/httpd/Makefile,v
retrieving revision 1.27
diff -u -p -u -p -r1.27 Makefile
--- Makefile23 Feb 2015 10:39:10 -  1.27
+++ Makefile23 Jun 2015 14:07:14 -
@@ -6,6 +6,9 @@ SRCS+=  config.c control.c httpd.c log.c
 SRCS+= server.c server_http.c server_file.c server_fcgi.c
 MAN=   httpd.8 httpd.conf.5
 
+SRCS+= patterns.c
+MAN+=  patterns.7
+
 LDADD= -levent -ltls -lssl -lcrypto -lutil
 DPADD= ${LIBEVENT} ${LIBTLS} ${LIBSSL} ${LIBCRYPTO} ${LIBUTIL}
 #DEBUG=-g -DDEBUG=3 -O0
Index: httpd.conf.5
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
retrieving revision 1.61
diff -u -p -u -p -r1.61 httpd.conf.5
--- httpd.conf.528 May 2015 19:29:40 -  1.61
+++ httpd.conf.523 Jun 2015 14:07:14 -
@@ -131,14 +131,38 @@ The configured web servers.
 .Pp
 Each
 .Ic server
-must have a
-.Ar name
-and include one or more lines of the following syntax:
+section starts with a declaration of the server
+.Ar name :
+.Bl -tag -width Ds
+.It Ic server Ar name Brq ...
+Match the server name using shell globbing rules.
+This can be an explicit name,
+.Ar www.example.com ,
+or a name including wildcards,
+.Ar *.example.com .
+.It Ic server match Ar name Brq ...
+Match the server name using pattern matching,
+see
+.Xr patterns 7 .
+.El
+.Pp
+Followed by a block of options that is enclosed in curly brackets:
 .Bl -tag -width Ds
 .It Ic alias Ar name
 Specify an additional alias
 .Ar name
 for this server.
+.It Ic alias match Ar name
+Like the
+.Ic alias
+option,
+but
+.Ic match
+the
+.Ar name
+using pattern matching instead of shell globbing rules,
+see
+.Xr patterns 7 .
 .It Oo Ic no Oc Ic authenticate Oo Ar realm Oc Ic with Pa htpasswd
 Authenticate a remote user for
 .Ar realm
@@ -188,6 +212,12 @@ The configured IP address of the server.
 The configured TCP server port of the server.
 .It Ic $SERVER_NAME
 The name of the server.
+.It Ic Pf % Ar n
+The capture index
+.Ar n
+of a string that was captured by the enclosing
+.Ic location match
+option.
 .El
 .It Ic connection Ar option
 Set the specified options and limits for HTTP connections.
@@ -247,6 +277,22 @@ except
 .Ic location
 and
 .Ic tcp .
+.It Ic location match Ar path Brq ...
+Like the
+.Ic location
+option,
+but
+.Ic match
+the
+.Ar path
+using pattern matching instead of shell globbing rules,
+see
+.Xr patterns 7 .
+The pattern may contain captures that can be used in the
+.Ar uri
+of an enclosed
+.Ic block return
+option.
 .It Oo Ic no Oc Ic log Op Ar option
 Set the specified logging options.
 Logging is enabled by default using the standard
@@ -516,6 +562,7 @@ server "www.example.com" {
 .Ed
 .Sh SEE ALSO
 .Xr htpasswd 1 ,
+.Xr patterns 7 ,
 .Xr httpd 8 ,
 .Xr slowcgi 8
 .Sh AUTHORS
Index: httpd.h
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v
retrieving revision 1.83
diff -u -p -u -p -r1.83 httpd.h
--- httpd.h 20 May 2015 09:28:47 -  1.83
+++ httpd.h 23 Jun 2015 14:07:15 -
@@ -35,6 +35,8 @@
 #include 
 #include 
 
+#include "patterns.h"
+
 #define CONF_FILE  "/etc/httpd.conf"
 #define HTTPD_SOCKET   "/var/run/httpd.sock"
 #define HTTPD_USER "www"
@@ -278,6 +280,7 @@ struct client {
void*clt_srv_conf;
u_int32_tclt_srv_id;
struct sockaddr_storage  clt_srv_ss;
+   struct str_match clt_srv_match;
 
int  clt_s;
in_port_tclt_port;
@@ -341,12 +344,15 @@ SPLAY_HEAD(client_tree, client);
 #define SRVFLAG_NO_AUTH0x0002
 #define SRVFLAG_BLOCK  0x0004
 #define SRVFLAG_NO_BLOCK   0x0008
+#define SRVFLAG_LOCATION_MATCH 0x0010
+#define SRVFLAG_SERVER_MATCH   0x0020
 
 #define SRVFLAG_BITS   \
"\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX"   \
"\05ROOT\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG\13SOCKET"   \
"\14SYSLOG\15NO_SYSLOG\16TLS\17ACCESS_LOG\20ERROR_LOG"  \
-   "\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK"
+   "\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK\25LOCATION_MATCH" \
+   "\26SERVER_MATCH"
 
 #define TCPFLAG_NODELAY0x01
 #define TCPFLAG_NNODELAY   0x02
Index: parse.y
===
RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
retrieving revision 1.67
diff -u -p -u -p -r1.67 parse.y
--- parse.y 1 Apr

Stop G/C mbufs in if_detach()

2015-06-23 Thread Martin Pieuchot
When an interface is detached or destroyed the CPU executing if_detach()
removes all the mbufs received by this interface on three queues:
ARP, IPv4 and IPv6 protocol queues.

This made sense to avoid referencing a dangling "rcvif" pointer. But now
mbufs contain unique interface indexes and protocol interrupt routines
handle just fine the case where if_get() returns a NULL pointer.

So I'd like to get rid of this explicit garbage collection.  Note that
this will leave mbufs on the protocol queues until the next netisr is
executed for the corresponding queue.  This is a functional change but
I don't think it's a problem.  It only matters if you destroy your only
pseudo interface or unplug your single USB interface without replugging
it.

Comments, oks?

Index: net/if.c
===
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.341
diff -u -p -r1.341 if.c
--- net/if.c23 Jun 2015 09:42:23 -  1.341
+++ net/if.c23 Jun 2015 10:54:04 -
@@ -128,8 +128,6 @@ voidif_attachsetup(struct ifnet *);
 void   if_attachdomain1(struct ifnet *);
 void   if_attach_common(struct ifnet *);
 
-intif_detach_filter(void *, const struct mbuf *);
-void   if_detach_queues(struct ifnet *, struct niqueue *);
 void   if_detached_start(struct ifnet *);
 intif_detached_ioctl(struct ifnet *, u_long, caddr_t);
 
@@ -644,23 +642,6 @@ if_detach(struct ifnet *ifp)
pfi_detach_ifnet(ifp);
 #endif
 
-   /*
-* remove packets came from ifp, from software interrupt queues.
-* net/netisr_dispatch.h is not usable, as some of them use
-* strange queue names.
-*/
-#define IF_DETACH_QUEUES(x) \
-do { \
-   extern struct niqueue x; \
-   if_detach_queues(ifp, & x); \
-} while (0)
-   IF_DETACH_QUEUES(arpintrq);
-   IF_DETACH_QUEUES(ipintrq);
-#ifdef INET6
-   IF_DETACH_QUEUES(ip6intrq);
-#endif
-#undef IF_DETACH_QUEUES
-
/* Remove the interface from the list of all interfaces.  */
TAILQ_REMOVE(&ifnet, ifp, if_list);
if (ISSET(ifp->if_xflags, IFXF_TXREADY))
@@ -701,34 +682,6 @@ do { \
 
ifindex2ifnet[ifp->if_index] = NULL;
splx(s);
-}
-
-int
-if_detach_filter(void *ctx, const struct mbuf *m)
-{
-   struct ifnet *ifp = ctx;
-
-#ifdef DIAGNOSTIC
-   if ((m->m_flags & M_PKTHDR) == 0)
-   return (0);
-#endif
-
-   return (m->m_pkthdr.ph_ifidx == ifp->if_index);
-}
-
-void
-if_detach_queues(struct ifnet *ifp, struct niqueue *niq)
-{
-   struct mbuf *m0, *m;
-
-   m0 = niq_filter(niq, if_detach_filter, ifp);
-   while (m0 != NULL) {
-   m = m0;
-   m0 = m->m_nextpkt;
-
-   m->m_nextpkt = NULL;
-   m_freem(m);
-   }
 }
 
 /*



Re: Machine hangs on boot with snapshots 5.8-beta

2015-06-23 Thread Mark Kettenis
> Date: Tue, 23 Jun 2015 11:59:39 +0100
> From: Pedro Caetano 
> 
> Hi,
> 
> I'm currently testing -current snapshots (tagged 5.8-beta) on an hp dl320
> gen8 and the machine panics with the following message:
> 
> panic: null acpicpu
> Stopped at   Debugger+0x9: leave
> 
> 
> If i boot with an older kernel (5.7 -current snapshot) and disable acpiprt
> (via config -ef /bsd) the system no longer panics at that stage,the
> following messages occur:
> 
> ehci_sync_hc
> ciss0: unqueued ccb 0xff0001bbbc00 ready, state=10
> 
> dmesg below is obtained running a 5.7 snapshot as i'm unable to boot system
> and get it under 5.8-beta

cpu[0-7] but only acpicpu[0-6].

We'll almost certainly need the acpidump output for your machine to
diagnose the problem.  Best to use sendbug(1) to supply that
information, as it will make sure attachments aren't stripped.

> OpenBSD 5.7-current (GENERIC.MP) #1056: Wed Jun 10 21:42:18 MDT 2015
> dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> real mem = 8537387008 (8141MB)
> avail mem = 8274767872 (7891MB)
> mpath0 at root
> scsibus0 at mpath0: 256 targets
> mainbus0 at root
> bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xb7bdb000 (85 entries)
> bios0: vendor HP version "J05" date 11/09/2013
> bios0: HP ProLiant DL320e Gen8
> acpi0 at bios0: rev 2
> acpi0: sleep states S0 S4 S5
> acpi0: tables DSDT FACP SPCR MCFG HPET  SPMI ERST APIC  BERT HEST
> DMAR  SSDT SSDT SSDT SSDT SSDT
> acpi0: wakeup devices PCI0(S4)
> acpitimer0 at acpi0: 3579545 Hz, 24 bits
> acpimcfg0 at acpi0 addr 0xb800, bus 0-63
> acpihpet0 at acpi0: 14318179 Hz
> acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
> cpu0 at mainbus0: apid 0 (boot processor)
> cpu0: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3692.13 MHz
> cpu0:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
> T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu0: 256KB 64b/line 8-way L2 cache
> cpu0: smt 0, core 0, package 0
> mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
> cpu0: apic clock running at 99MHz
> cpu0: mwait min=64, max=64, C-substates=0.2.1.1, IBE
> cpu1 at mainbus0: apid 2 (application processor)
> cpu1: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
> cpu1:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
> T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu1: 256KB 64b/line 8-way L2 cache
> cpu1: smt 0, core 1, package 0
> cpu2 at mainbus0: apid 4 (application processor)
> cpu2: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
> cpu2:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
> T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu2: 256KB 64b/line 8-way L2 cache
> cpu2: smt 0, core 2, package 0
> cpu3 at mainbus0: apid 6 (application processor)
> cpu3: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
> cpu3:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
> T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu3: 256KB 64b/line 8-way L2 cache
> cpu3: smt 0, core 3, package 0
> cpu4 at mainbus0: apid 1 (application processor)
> cpu4: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
> cpu4:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
> T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu4: 256KB 64b/line 8-way L2 cache
> cpu4: smt 1, core 0, package 0
> cpu5 at mainbus0: apid 3 (application processor)
> cpu5: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
> cpu5:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
> T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu5: 256KB 64b/line 8-way L2 cache
> cpu5: smt 1, core 1, package 0
> cpu6 at mainbus0: apid 5 (application processor)
> cpu6: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
> cpu6:
> FPU

Machine hangs on boot with snapshots 5.8-beta

2015-06-23 Thread Pedro Caetano
Hi,

I'm currently testing -current snapshots (tagged 5.8-beta) on an hp dl320
gen8 and the machine panics with the following message:

panic: null acpicpu
Stopped at   Debugger+0x9: leave


If i boot with an older kernel (5.7 -current snapshot) and disable acpiprt
(via config -ef /bsd) the system no longer panics at that stage,the
following messages occur:

ehci_sync_hc
ciss0: unqueued ccb 0xff0001bbbc00 ready, state=10

dmesg below is obtained running a 5.7 snapshot as i'm unable to boot system
and get it under 5.8-beta

OpenBSD 5.7-current (GENERIC.MP) #1056: Wed Jun 10 21:42:18 MDT 2015
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8537387008 (8141MB)
avail mem = 8274767872 (7891MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xb7bdb000 (85 entries)
bios0: vendor HP version "J05" date 11/09/2013
bios0: HP ProLiant DL320e Gen8
acpi0 at bios0: rev 2
acpi0: sleep states S0 S4 S5
acpi0: tables DSDT FACP SPCR MCFG HPET  SPMI ERST APIC  BERT HEST
DMAR  SSDT SSDT SSDT SSDT SSDT
acpi0: wakeup devices PCI0(S4)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimcfg0 at acpi0 addr 0xb800, bus 0-63
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3692.13 MHz
cpu0:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
cpu1:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 0, core 1, package 0
cpu2 at mainbus0: apid 4 (application processor)
cpu2: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
cpu2:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 2, package 0
cpu3 at mainbus0: apid 6 (application processor)
cpu3: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
cpu3:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 0, core 3, package 0
cpu4 at mainbus0: apid 1 (application processor)
cpu4: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
cpu4:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu4: 256KB 64b/line 8-way L2 cache
cpu4: smt 1, core 0, package 0
cpu5 at mainbus0: apid 3 (application processor)
cpu5: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
cpu5:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu5: 256KB 64b/line 8-way L2 cache
cpu5: smt 1, core 1, package 0
cpu6 at mainbus0: apid 5 (application processor)
cpu6: Intel(R) Xeon(R) CPU E3-1290 V2 @ 3.70GHz, 3691.62 MHz
cpu6:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,ES
T,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu6: 256KB 64b/line 8-way L2 cache
cpu6: smt 1, core 2, package 0
cpu7 at mainbus0: apid 7 (application processor)
cpu7: Intel(R) Xeon(R) CPU E3-1290 V2 @

[diff] trivia: change xorl => xorq

2015-06-23 Thread Alexey Dobriyan
Clearing 32-bit register clears whole register, save REX prefix.

Index: arch/amd64/amd64/acpi_wakecode.S
===
RCS file: /cvs/src/sys/arch/amd64/amd64/acpi_wakecode.S,v
retrieving revision 1.35
diff -u -p -u -r1.35 acpi_wakecode.S
--- arch/amd64/amd64/acpi_wakecode.S8 Dec 2014 07:12:37 -   1.35
+++ arch/amd64/amd64/acpi_wakecode.S20 Jun 2015 17:56:47 -
@@ -307,7 +307,7 @@ _C_LABEL(acpi_long_mode_resume):
lidtacpi_saved_idt
 
/* Restore the saved task register */
-   xorq%rcx, %rcx
+   xorl%ecx, %ecx
movwacpi_saved_tr, %cx
movqacpi_saved_gdt+2, %rax
andb$0xF9, 5(%rax,%rcx)
@@ -337,7 +337,7 @@ _C_LABEL(acpi_long_mode_resume):
movqacpi_saved_cr3, %rax
movq%rax, %cr3
 
-   xorq%rax, %rax  
+   xorl%eax, %eax
jmp *acpi_saved_ret
 
 #ifdef HIBERNATE
Index: arch/amd64/amd64/copy.S
===
RCS file: /cvs/src/sys/arch/amd64/amd64/copy.S,v
retrieving revision 1.6
diff -u -p -u -r1.6 copy.S
--- arch/amd64/amd64/copy.S 16 Jan 2015 10:17:51 -  1.6
+++ arch/amd64/amd64/copy.S 20 Jun 2015 17:56:47 -
@@ -93,7 +93,7 @@ ENTRY(kcopy)
 
movqCPUVAR(CURPCB),%rdx
popqPCB_ONFAULT(%rdx)
-   xorq%rax,%rax
+   xorl%eax,%eax
ret
 
 1: addq%rcx,%rdi   # copy backward
@@ -114,7 +114,7 @@ ENTRY(kcopy)
 
movqCPUVAR(CURPCB),%rdx
popqPCB_ONFAULT(%rdx)
-   xorq%rax,%rax
+   xorl%eax,%eax
ret
 
 ENTRY(copyout)
@@ -222,7 +222,7 @@ ENTRY(copyoutstr)
 
/* Success -- 0 byte reached. */
decq%rdx
-   xorq%rax,%rax
+   xorl%eax,%eax
jmp copystr_return
 
 2: /* rdx is zero -- return EFAULT or ENAMETOOLONG. */
@@ -265,7 +265,7 @@ ENTRY(copyinstr)
 
/* Success -- 0 byte reached. */
decq%rdx
-   xorq%rax,%rax
+   xorl%eax,%eax
jmp copystr_return
 
 2: /* edx is zero -- return EFAULT or ENAMETOOLONG. */
Index: arch/amd64/amd64/locore.S
===
RCS file: /cvs/src/sys/arch/amd64/amd64/locore.S,v
retrieving revision 1.62
diff -u -p -u -r1.62 locore.S
--- arch/amd64/amd64/locore.S   16 Jan 2015 10:17:51 -  1.62
+++ arch/amd64/amd64/locore.S   20 Jun 2015 17:56:47 -
@@ -732,7 +732,7 @@ longmode_hi:
movq%rax,_C_LABEL(proc0paddr)(%rip)
leaq(USPACE-FRAMESIZE)(%rax),%rsp
movq%rsi,PCB_CR3(%rax)  # pcb->pcb_cr3
-   xorq%rbp,%rbp   # mark end of frames
+   xorl%ebp,%ebp   # mark end of frames
 
xorw%ax,%ax
movw%ax,%gs
@@ -1071,7 +1071,7 @@ syscall_return:
movlTF_RDI(%rsp),%edx
movl%ebx,%ecx
movlCPUVAR(ILEVEL),%r8d
-   xorq%rax,%rax
+   xorl%eax,%eax
call_C_LABEL(printf)
 #ifdef DDB
int $3
@@ -1143,7 +1143,7 @@ _C_LABEL(doreti_iret):
 #ifdef DIAGNOSTIC
 3: sti
movabsq $4f, %rdi
-   xorq%rax,%rax
+   xorl%eax,%eax
call_C_LABEL(printf)
 #ifdef DDB
int $3
@@ -1157,7 +1157,7 @@ _C_LABEL(doreti_iret):
 ENTRY(pagezero)
movq$-PAGE_SIZE,%rdx
subq%rdx,%rdi
-   xorq%rax,%rax
+   xorl%eax,%eax
 1:
movnti  %rax,(%rdi,%rdx)
movnti  %rax,8(%rdi,%rdx)
Index: arch/amd64/amd64/mptramp.S
===
RCS file: /cvs/src/sys/arch/amd64/amd64/mptramp.S,v
retrieving revision 1.11
diff -u -p -u -r1.11 mptramp.S
--- arch/amd64/amd64/mptramp.S  8 Dec 2014 07:49:17 -   1.11
+++ arch/amd64/amd64/mptramp.S  20 Jun 2015 17:56:47 -
@@ -189,7 +189,7 @@ _TRMP_LABEL(mptramp_longmode)
 _C_LABEL(cpu_spinup_trampoline_end):   #end of code copied to MP_TRAMPOLINE
movl_C_LABEL(local_apic)+LAPIC_ID,%eax
shrl$LAPIC_ID_SHIFT,%eax
-   xorq%rcx,%rcx
+   xorl%ecx,%ecx
 1:
movq_C_LABEL(cpu_info)(,%rcx,8),%rdi
incq%rcx
Index: arch/amd64/amd64/mutex.S
===
RCS file: /cvs/src/sys/arch/amd64/amd64/mutex.S,v
retrieving revision 1.9
diff -u -p -u -r1.9 mutex.S
--- arch/amd64/amd64/mutex.S2 Jun 2013 01:55:52 -   1.9
+++ arch/amd64/amd64/mutex.S20 Jun 2015 17:56:52 -
@@ -55,7 +55,7 @@ ENTRY(mtx_enter)
 * %edx - the old ipl
 * %rcx - curcpu()
 */
-   xorq%rax, %rax
+   xorl%eax, %eax
 #ifdef MULTIPROCESSOR
lock
 #endif
@@ -99,7 +99,7 @@ ENTRY(mtx_enter_try)
 * %edx - the old ipl
 * %rcx - curcpu()
 */
-   xorq%rax, %rax
+   xorl%eax, %eax
 #ifdef MULTIPROCESSOR