Re: guess softraid as default rootdev for install/upgrade

2014-11-26 Thread Stefan Sperling
On Wed, Nov 26, 2014 at 03:05:27AM -0500, Jean-Philippe Ouellet wrote:
 Hello,
 
 Finally found some free time.
 
 What would you think of making the Which disk is the root disk?
 question default to the first softraid device you have configured,
 if any.
 
 The thinking is if you bothered to actually configure a softraid
 device, it's probably because you actually intend to use it, right?
 
 Whenever I use softraid (either for crypto, or actual raid) it's
 always held my / ever since booting from it has been supported.
 I suspect this may be the case for others as wells.

Yes, the installer doesn't support softraid automagically yet.
It does however already work well if you answer its questions correctly.
This is because the bootloaders and kernel are making softraid mostly
transparent to the installer (apart from the initial bioctl setup step).

 If you think this describes the majority of softraid users, then
 I propose the following:

Last I heard the idea was to push such logic into bioctl or a new utility
because scripting it sucks. (Perhaps jsing@ can elaborate on that?)
 
Various diffs have been suggested for RAID support in the installer,
by myself and others. So far they've been rejected because they weren't
good enough.

In your case: What if I have a RAID1 volume mounted on /storage?
I'll always get the wrong suggestion with your diff whereas it worked before.
What if I have a crypto and a RAID1 volume configured? How do you know
which one is the root disk I want to upgrade? A scripted guess is probably
just as bad as the current default.

I think this needs some support from the bootloader and kernel to work right.

 
 Index: install.sub
 ===
 RCS file: /cvs/src/distrib/miniroot/install.sub,v
 retrieving revision 1.799
 diff -u -p -r1.799 install.sub
 --- install.sub   18 Nov 2014 19:00:16 -  1.799
 +++ install.sub   25 Nov 2014 14:05:15 -
 @@ -149,15 +149,23 @@ scan_dmesg() {
  
  scan_disknames() {
   local IFS=,
 - bsort $(for _n in $(sysctl -n hw.disknames); do echo ${_n%%:*} ; done 
 | sed -n $1)
 + bsort $(for _n in $(sysctl -n hw.disknames); do echo ${_n%%:*} ; done)
  }
  
 -get_dkdevs () {
 - echo $(scan_disknames ${MDDKDEVS:-/^[sw]d[0-9][0-9]* /s/ .*//p})
 +filter_dkdevs() {
 + sed -n ${MDDKDEVS:-/^[sw]d[0-9][0-9]* /s/ .*//p}
  }
  
 -get_cddevs () {
 - echo $(scan_disknames ${MDCDDEVS:-/^cd[0-9][0-9]* /s/ .*//p})
 +filter_cddevs() {
 + sed -n ${MDCDDEVS:-/^cd[0-9][0-9]* /s/ .*//p}
 +}
 +
 +get_dkdevs() {
 + echo $(scan_disknames | filter_dkdevs)
 +}
 +
 +get_cddevs() {
 + echo $(scan_disknames | filter_cddevs)
  }
  
  get_ifdevs() {
 @@ -166,6 +174,13 @@ get_ifdevs() {
   sed -n 's/^\(.*\):.*/\1/p'
  }
  
 +guess_rootdev() {
 + local _raid _dev
 + _raid=$(bioctl -i softraid0 2/dev/null | grep ^softraid)
 + _dev=$(for _n in $_raid; do echo $_n ; done | filter_dkdevs | sed 1q)
 + [ -n $_dev ]  echo $_dev || get_dkdevs | sed 's/ .*//'
 +}
 +
  get_drive() {
   ask_which $1 contains the $MODE media $2 $3
   [[ $resp == done ]]  return 1
 @@ -2249,7 +2264,7 @@ diskinfo() {
  while :; do
   echo Available disks are: $(get_dkdevs | sed 's/^$/none/').
   _ask Which disk is the root disk? ('?' for details) \
 - $(get_dkdevs | sed 's/ .*//') || continue
 + $(guess_rootdev) || continue
   case $resp in
   ?)diskinfo $(get_dkdevs);;
   '') ;;



Re: guess softraid as default rootdev for install/upgrade

2014-11-26 Thread Stuart Henderson
On 2014/11/26 03:05, Jean-Philippe Ouellet wrote:
 
 What would you think of making the Which disk is the root disk?
 question default to the first softraid device you have configured,
 if any.

softraid isn't the only place where the guessed value is incorrect;
if the information can be made available, a better default would be the
disk you booted from.



Re: patch: properly check NULL return values

2014-11-26 Thread Tobias Stoeckmann
Hi,

turns out that there are a few more bad savestr calls even inside of pch.c.
Some of the code pathes are quite obvious that a NULL return value would
lead to a null pointer dereference, others would last longer before
dereferencing.

Carefully reviewing the savestr calls, the rule of thumb seems to be:
If savestr is used, immediately check out_of_mem, otherwise use xstrdup.

Theo pointed out that this one is very ugly (indeed):

+   if (!s)
+   s = Oops;

Yet it's current behavior of savestr.  I want to remove that in another
commit.  So for now, xstrdup behaves like savestr, calling fatal in case
of out of memory situation -- regardless of plan a or plan b.


Tobias

Index: patch.c
===
RCS file: /cvs/src/usr.bin/patch/patch.c,v
retrieving revision 1.51
diff -u -p -r1.51 patch.c
--- patch.c 26 Nov 2013 13:19:07 -  1.51
+++ patch.c 26 Nov 2014 11:46:20 -
@@ -213,7 +213,7 @@ main(int argc, char *argv[])
warn_on_invalid_line = true;
 
if (outname == NULL)
-   outname = savestr(filearg[0]);
+   outname = xstrdup(filearg[0]);
 
/* for ed script just up and do it and exit */
if (diff_type == ED_DIFF) {
@@ -491,10 +491,10 @@ get_some_switches(void)
/* FALLTHROUGH */
case 'z':
/* must directly follow 'b' case for backwards compat */
-   simple_backup_suffix = savestr(optarg);
+   simple_backup_suffix = xstrdup(optarg);
break;
case 'B':
-   origprae = savestr(optarg);
+   origprae = xstrdup(optarg);
break;
case 'c':
diff_type = CONTEXT_DIFF;
@@ -532,7 +532,7 @@ get_some_switches(void)
case 'i':
if (++filec == MAXFILEC)
fatal(too many file arguments\n);
-   filearg[filec] = savestr(optarg);
+   filearg[filec] = xstrdup(optarg);
break;
case 'l':
canonicalize = true;
@@ -544,7 +544,7 @@ get_some_switches(void)
noreverse = true;
break;
case 'o':
-   outname = savestr(optarg);
+   outname = xstrdup(optarg);
break;
case 'p':
strippath = atoi(optarg);
@@ -588,12 +588,12 @@ get_some_switches(void)
Argv += optind;
 
if (Argc  0) {
-   filearg[0] = savestr(*Argv++);
+   filearg[0] = xstrdup(*Argv++);
Argc--;
while (Argc  0) {
if (++filec == MAXFILEC)
fatal(too many file arguments\n);
-   filearg[filec] = savestr(*Argv++);
+   filearg[filec] = xstrdup(*Argv++);
Argc--;
}
}
Index: pch.c
===
RCS file: /cvs/src/usr.bin/patch/pch.c,v
retrieving revision 1.46
diff -u -p -r1.46 pch.c
--- pch.c   26 Nov 2014 10:11:21 -  1.46
+++ pch.c   26 Nov 2014 11:46:21 -
@@ -215,14 +215,14 @@ there_is_another_patch(void)
while (filearg[0] == NULL) {
if (force || batch) {
say(No file to patch.  Skipping...\n);
-   filearg[0] = savestr(bestguess);
+   filearg[0] = xstrdup(bestguess);
skip_rest_of_patch = true;
return true;
}
ask(File to patch: );
if (*buf != '\n') {
free(bestguess);
-   bestguess = savestr(buf);
+   bestguess = xstrdup(buf);
filearg[0] = fetchname(buf, exists, 0);
}
if (!exists) {
@@ -310,7 +310,7 @@ intuit_diff_type(void)
else if (strnEQ(s, Prereq:, 7)) {
for (t = s + 7; isspace((unsigned char)*t); t++)
;
-   revision = savestr(t);
+   revision = xstrdup(t);
for (t = revision;
*t  !isspace((unsigned char)*t); t++)
;
@@ -389,7 +389,7 @@ scan_exit:
free(bestguess);
bestguess = NULL;
if (filearg[0] != NULL)
-   bestguess = savestr(filearg[0]);
+   bestguess = xstrdup(filearg[0]);
else if (!ok_to_create_file) {
/*
 * We don't want to create a new file but we need a
@@ -1473,7 

Re: Behavior of changing routes on OpenBSD 5.6

2014-11-26 Thread Martin Pieuchot
Hello Florian,

On 26/11/14(Wed) 06:56, Florian Riehm wrote:
 since OpenBSD 5.6 route change messages can change the interface of a route
 (rt_ifa) even if a message doesn't seem to require it because of a changed
 gateway or stuff like that.
 I would like to ask if it's a regression or if the new behavior is intended.

Since the behavior is different and it's not documented, it is a 
regression, thanks for reporting it.  I've just committed some new
tests in order to prevent this from happening again.

 Example: (only for testing - it doesn't represent my network topology)
 ifconfig em0 inet6 fd88::1/64
 ifconfig em1 inet6 fd99::1/64
 route add -inet6 fd88::666 fd99::1
 route get fd88::666
 interface: em1 (as expected)
 route change fd88::666 -mtu 1500
 route get fd88::666
 interface: em0 (broken - trying to ping the target results in No route to
 host)
 
 In the example I can workaround the problem with adding a gateway while 
 changing
 the mtu:
 route change fd88::666 fd99::1 -mtu 1500
 
 A comment in route_output (rtsock.c) says
 /*
 * new gateway could require new ifaddr, ifp;
 * flags may also be different; ifp may be specified
 * by ll sockaddr when protocol address is ambiguous
 */
 but their is no check for a 'new gateway'.

You're right.  What's happening here is that we always call rt_geifa() in
the first place.  This is a nasty function that tries to find an ifaddr
to attach a route.  But if the gateway is not new or you didn't specify
any of the -ifp or -ifa argument we should not look for a different
ifaddr.

Here's a slightly different diff, could you tell me if it fixes the
regression in your case?

Index: net/rtsock.c
===
RCS file: /home/ncvs/src/sys/net/rtsock.c,v
retrieving revision 1.152
diff -u -p -r1.152 rtsock.c
--- net/rtsock.c12 Aug 2014 13:52:08 -  1.152
+++ net/rtsock.c26 Nov 2014 11:55:25 -
@@ -740,13 +740,6 @@ report:
break;
 
case RTM_CHANGE:
-   /*
-* new gateway could require new ifaddr, ifp;
-* flags may also be different; ifp may be specified
-* by ll sockaddr when protocol address is ambiguous
-*/
-   if ((error = rt_getifa(info, tableid)) != 0)
-   goto flush;
newgate = 0;
if (info.rti_info[RTAX_GATEWAY] != NULL)
if (rt-rt_gateway == NULL ||
@@ -761,7 +754,17 @@ report:
error = EDQUOT;
goto flush;
}
-   ifa = info.rti_ifa;
+   /*
+* new gateway could require new ifaddr, ifp;
+* flags may also be different; ifp may be specified
+* by ll sockaddr when protocol address is ambiguous
+*/
+   if (newgate || info.rti_info[RTAX_IFP] != NULL ||
+   info.rti_info[RTAX_IFA] != NULL) {
+   if ((error = rt_getifa(info, tableid)) != 0)
+   goto flush;
+   ifa = info.rti_ifa;
+   }
if (ifa) {
if (rt-rt_ifa != ifa) {
if (rt-rt_ifa-ifa_rtrequest)



Re: pf(4) and struct route

2014-11-26 Thread Martin Pieuchot
On 25/11/14(Tue) 15:16, Todd C. Miller wrote:
 On Tue, 25 Nov 2014 16:43:16 +0100, Martin Pieuchot wrote:
 
  Diff below removes the non-needed usages of struct route  friends in
  pf.c,  any comment or ok?
 
 You are missing some initializations of rt to NULL, comments inline.

Thanks for the reviews todd!  This is much appreciated now that network
hacker is a critically endangered specie :)

You'll find a corrected diff below.  Since I was asked to give more
information about this change here's the story:

We have currently two structures used to cache a route entry in order to
avoid supplementary route lookups: struct route and struct route_in6.

These structures store a pointer to a rtentry and the destination of
this route.  Yes this is duplicated information.  There are mainly two
problems with this design.  First of all the fact that we have a
structure per AF, when a rtentry is AF agnostic, which results in a lot
of #ifdefs  cast.  But the main reason to directly use a struct rtentry
instead of these structures is to strengthen  unify the code checking 
for the validity of a route.  I'd like at least to stop checking against
a cached destination, I'd like to add a check for stall ifa and I'd like
to add a check for reference counters.

So the first move is to stop using such structure when we don't want to
keep a reference on a route entry, then I'll modify the APIs keeping a
reference and finally add more checks.

Martin

Index: net/pf.c
===
RCS file: /home/ncvs/src/sys/net/pf.c,v
retrieving revision 1.896
diff -u -p -r1.896 pf.c
--- net/pf.c20 Nov 2014 13:54:24 -  1.896
+++ net/pf.c25 Nov 2014 14:58:42 -
@@ -2952,42 +2952,36 @@ pf_calc_mss(struct pf_addr *addr, sa_fam
 {
 #ifdef INET
struct sockaddr_in  *dst;
-   struct route ro;
 #endif /* INET */
 #ifdef INET6
struct sockaddr_in6 *dst6;
-   struct route_in6 ro6;
 #endif /* INET6 */
struct rtentry  *rt = NULL;
+   struct sockaddr_storage  ss;
int  hlen;
u_int16_tmss = tcp_mssdflt;
 
+   memset(ss, 0, sizeof(ss));
+
switch (af) {
 #ifdef INET
case AF_INET:
hlen = sizeof(struct ip);
-   bzero(ro, sizeof(ro));
-   dst = (struct sockaddr_in *)ro.ro_dst;
+   dst = (struct sockaddr_in *)ss;
dst-sin_family = AF_INET;
dst-sin_len = sizeof(*dst);
dst-sin_addr = addr-v4;
-   ro.ro_tableid = rtableid;
-   ro.ro_rt = rtalloc(ro.ro_dst, RT_REPORT, ro.ro_tableid);
-   rt = ro.ro_rt;
+   rt = rtalloc(sintosa(dst), RT_REPORT, rtableid);
break;
 #endif /* INET */
 #ifdef INET6
case AF_INET6:
hlen = sizeof(struct ip6_hdr);
-   bzero(ro6, sizeof(ro6));
-   dst6 = (struct sockaddr_in6 *)ro6.ro_dst;
+   dst6 = (struct sockaddr_in6 *)ss;
dst6-sin6_family = AF_INET6;
dst6-sin6_len = sizeof(*dst6);
dst6-sin6_addr = addr-v6;
-   ro6.ro_tableid = rtableid;
-   ro6.ro_rt = rtalloc(sin6tosa(ro6.ro_dst), RT_REPORT,
-   ro6.ro_tableid);
-   rt = ro6.ro_rt;
+   rt = rtalloc(sin6tosa(dst6), RT_REPORT, rtableid);
break;
 #endif /* INET6 */
}
@@ -5396,25 +5390,22 @@ int
 pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif,
 int rtableid)
 {
+   struct sockaddr_storage  ss;
struct sockaddr_in  *dst;
int  ret = 1;
int  check_mpath;
 #ifdef INET6
struct sockaddr_in6 *dst6;
-   struct route_in6 ro;
-#else
-   struct route ro;
 #endif
struct rtentry  *rt;
struct ifnet*ifp;
 
check_mpath = 0;
-   bzero(ro, sizeof(ro));
-   ro.ro_tableid = rtableid;
+   memset(ss, 0, sizeof(ss));
switch (af) {
 #ifdef INET
case AF_INET:
-   dst = (struct sockaddr_in *)ro.ro_dst;
+   dst = (struct sockaddr_in *)ss;
dst-sin_family = AF_INET;
dst-sin_len = sizeof(*dst);
dst-sin_addr = addr-v4;
@@ -5430,7 +5421,7 @@ pf_routable(struct pf_addr *addr, sa_fam
 */
if (IN6_IS_SCOPE_EMBED(addr-v6))
goto out;
-   dst6 = ro.ro_dst;
+   dst6 = (struct sockaddr_in6 *)ss;
dst6-sin6_family = AF_INET6;
dst6-sin6_len = sizeof(*dst6);
dst6-sin6_addr = addr-v6;
@@ -5444,10 +5435,8 @@ pf_routable(struct pf_addr *addr, sa_fam
if (kif != NULL  kif-pfik_ifp-if_type == IFT_ENC)
goto out;
 
-   ro.ro_rt = rtalloc((struct 

Re: guess softraid as default rootdev for install/upgrade

2014-11-26 Thread Ingo Schwarze
Hi Jean-Philippe,

Jean-Philippe Ouellet wrote on Wed, Nov 26, 2014 at 03:05:27AM -0500:

 Finally found some free time.
 
 What would you think of making the Which disk is the root disk?
 question default to the first softraid device you have configured,
 if any.

I don't like that.

 The thinking is if you bothered to actually configure a softraid
 device, it's probably because you actually intend to use it, right?

But not necessarily for the root partition.

Granted, i'm using such a setup with even root on RAID on a few
machines right now, but only because some co-admins were very
strongly in favour of it, and my own inclination to avoid it
was not *that* strong.

On machines where i make the decision alone, i still keep the
operating system (root, usr, ...) and transient data (tmp, usr/obj,
var on non-server machines, ...) off RAID and only RAID user data
(home, usr/src on dev machines, var/www on webservers, ...).

Nick has explained many times what the advantages are, and why just
RAID everything is often indicative of a false sense of security
(or reliability, depending on the scenario), so i still think root
off RAID is the recommended way unless you have special needs.
I think the installer defaults should agree with what we recommend.

Yours,
  Ingo


 Whenever I use softraid (either for crypto, or actual raid) it's
 always held my / ever since booting from it has been supported.
 I suspect this may be the case for others as wells.
 
 If you think this describes the majority of softraid users, then
 I propose the following:
 
 
 Index: install.sub
 ===
 RCS file: /cvs/src/distrib/miniroot/install.sub,v
 retrieving revision 1.799
 diff -u -p -r1.799 install.sub
 --- install.sub   18 Nov 2014 19:00:16 -  1.799
 +++ install.sub   25 Nov 2014 14:05:15 -
 @@ -149,15 +149,23 @@ scan_dmesg() {
  
  scan_disknames() {
   local IFS=,
 - bsort $(for _n in $(sysctl -n hw.disknames); do echo ${_n%%:*} ; done 
 | sed -n $1)
 + bsort $(for _n in $(sysctl -n hw.disknames); do echo ${_n%%:*} ; done)
  }
  
 -get_dkdevs () {
 - echo $(scan_disknames ${MDDKDEVS:-/^[sw]d[0-9][0-9]* /s/ .*//p})
 +filter_dkdevs() {
 + sed -n ${MDDKDEVS:-/^[sw]d[0-9][0-9]* /s/ .*//p}
  }
  
 -get_cddevs () {
 - echo $(scan_disknames ${MDCDDEVS:-/^cd[0-9][0-9]* /s/ .*//p})
 +filter_cddevs() {
 + sed -n ${MDCDDEVS:-/^cd[0-9][0-9]* /s/ .*//p}
 +}
 +
 +get_dkdevs() {
 + echo $(scan_disknames | filter_dkdevs)
 +}
 +
 +get_cddevs() {
 + echo $(scan_disknames | filter_cddevs)
  }
  
  get_ifdevs() {
 @@ -166,6 +174,13 @@ get_ifdevs() {
   sed -n 's/^\(.*\):.*/\1/p'
  }
  
 +guess_rootdev() {
 + local _raid _dev
 + _raid=$(bioctl -i softraid0 2/dev/null | grep ^softraid)
 + _dev=$(for _n in $_raid; do echo $_n ; done | filter_dkdevs | sed 1q)
 + [ -n $_dev ]  echo $_dev || get_dkdevs | sed 's/ .*//'
 +}
 +
  get_drive() {
   ask_which $1 contains the $MODE media $2 $3
   [[ $resp == done ]]  return 1
 @@ -2249,7 +2264,7 @@ diskinfo() {
  while :; do
   echo Available disks are: $(get_dkdevs | sed 's/^$/none/').
   _ask Which disk is the root disk? ('?' for details) \
 - $(get_dkdevs | sed 's/ .*//') || continue
 + $(guess_rootdev) || continue
   case $resp in
   ?)diskinfo $(get_dkdevs);;
   '') ;;
 



Re: Fix AHCI on SUNXI

2014-11-26 Thread Edwin Amsler
It’s getting stuck in a reboot loop.

Not enough time to investigate at the moment, but I’ll dig into this soon.

It may be my build environment.

On Nov 25, 2014, at 5:54 AM, Jonathan Gray j...@jsg.id.au wrote:

 On Mon, Nov 24, 2014 at 08:12:33PM -0600, Edwin Amsler wrote:
 Here are the changes needed to make SATA drives available on the Cubieboard 
 A10. It consists of a DMA workaround and fiddling with some register 
 assignments. I?ve successfully built the RAMDISK kernel via an external 
 drive using this driver patch, so it?s been through what I?m hoping is a 
 valid smoke test.
 
 This patch was based off work done by others.
 
 Let me know what needs changing.
 
 dlg would prefer this to be done with a callback rather than a flag.
 So here's an attempt to handle it that way.
 
 Doesn't seem to break anything on an amd64 machine with ahci.
 
 Index: dev/ic/ahci.c
 ===
 RCS file: /cvs/src/sys/dev/ic/ahci.c,v
 retrieving revision 1.16
 diff -u -p -r1.16 ahci.c
 --- dev/ic/ahci.c 13 Jul 2014 23:10:23 -  1.16
 +++ dev/ic/ahci.c 25 Nov 2014 10:52:15 -
 @@ -75,7 +75,7 @@ int ahci_port_alloc(struct ahci_softc 
 void  ahci_port_free(struct ahci_softc *, u_int);
 int   ahci_port_init(struct ahci_softc *, u_int);
 
 -int  ahci_port_start(struct ahci_port *, int);
 +int  ahci_default_port_start(struct ahci_port *, int);
 int   ahci_port_stop(struct ahci_port *, int);
 int   ahci_port_clo(struct ahci_port *);
 int   ahci_port_softreset(struct ahci_port *);
 @@ -175,6 +175,9 @@ ahci_attach(struct ahci_softc *sc)
   u_int32_t   pi;
   int i;
 
 + if (sc-sc_port_start == NULL)
 + sc-sc_port_start = ahci_default_port_start;
 +
   if (ahci_init(sc) != 0) {
   /* error already printed by ahci_init */
   goto unmap;
 @@ -832,7 +835,7 @@ reterr:
 }
 
 int
 -ahci_port_start(struct ahci_port *ap, int fre_only)
 +ahci_default_port_start(struct ahci_port *ap, int fre_only)
 {
   u_int32_t   r;
 
 Index: dev/ic/ahcivar.h
 ===
 RCS file: /cvs/src/sys/dev/ic/ahcivar.h,v
 retrieving revision 1.8
 diff -u -p -r1.8 ahcivar.h
 --- dev/ic/ahcivar.h  14 Apr 2014 04:42:22 -  1.8
 +++ dev/ic/ahcivar.h  25 Nov 2014 10:50:20 -
 @@ -137,9 +137,12 @@ struct ahci_softc {
   u_int32_t   sc_ccc_ports;
   u_int32_t   sc_ccc_ports_cur;
 #endif
 +
 + int (*sc_port_start)(struct ahci_port *, int);
 };
 
 #define DEVNAME(_s)   ((_s)-sc_dev.dv_xname)
 +#define ahci_port_start(_p, _f)  ((_p)-ap_sc-sc_port_start((_p), (_f)))
 
 int   ahci_attach(struct ahci_softc *);
 int   ahci_detach(struct ahci_softc *, int);
 Index: arch/armv7/sunxi/sxiahci.c
 ===
 RCS file: /cvs/src/sys/arch/armv7/sunxi/sxiahci.c,v
 retrieving revision 1.6
 diff -u -p -r1.6 sxiahci.c
 --- arch/armv7/sunxi/sxiahci.c14 Apr 2014 04:42:22 -  1.6
 +++ arch/armv7/sunxi/sxiahci.c25 Nov 2014 11:37:56 -
 @@ -1,6 +1,7 @@
 /*$OpenBSD*/
 /*
  * Copyright (c) 2013 Patrick Wildt patr...@blueri.se
 + * Copyright (c) 2013,2014 Artturi Alm
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
 @@ -44,13 +45,21 @@
 #define   SXIAHCI_TIMEOUT 0x10
 #define SXIAHCI_PWRPIN40
 
 +#define SXIAHCI_PREG_DMA 0x70
 +#define  SXIAHCI_PREG_DMA_MASK   (0xff8)
 +#define  SXIAHCI_PREG_DMA_INIT   (0x448)
 +
 void  sxiahci_attach(struct device *, struct device *, void *);
 int   sxiahci_detach(struct device *, int);
 int   sxiahci_activate(struct device *, int);
 +int  sxiahci_port_start(struct ahci_port *, int);
 
 extern int ahci_intr(void *);
 extern u_int32_t ahci_read(struct ahci_softc *, bus_size_t);
 extern void ahci_write(struct ahci_softc *, bus_size_t, u_int32_t);
 +extern u_int32_t ahci_pread(struct ahci_port *, bus_size_t);
 +extern void ahci_pwrite(struct ahci_port *, bus_size_t, u_int32_t);
 +extern int ahci_default_port_start(struct ahci_port *, int);
 
 struct sxiahci_softc {
   struct ahci_softc   sc;
 @@ -75,18 +84,15 @@ sxiahci_attach(struct device *parent, st
   struct armv7_attach_args *aa = args;
   struct sxiahci_softc *sxisc = (struct sxiahci_softc *)self;
   struct ahci_softc *sc = sxisc-sc;
 - bus_space_tag_t iot;
 - bus_space_handle_t ioh;
   uint32_t timo;
 
 - sc-sc_iot = iot = aa-aa_iot;
 + sc-sc_iot = aa-aa_iot;
   sc-sc_ios = aa-aa_dev-mem[0].size;
   sc-sc_dmat = aa-aa_dmat;
 
   if 

rdomain IPv6 local addresses

2014-11-26 Thread Martin Pieuchot
While debugging the recent route change regression I found various
bugs in the code handling IPv6 addresses.  The most ugly one, because
it leaves you with a null ifp pointer in your routing table, is fixed
by the diff below.

Basically if you try to remove an address from an interface, by deleting
it for example, in one rdomain and you have the same address in another
rdomain you wont remove the route.

You can run rttest14 and rttest16 in regress/sbin/route to see what
happens.

Ok?


Index: netinet6/in6.c
===
RCS file: /home/ncvs/src/sys/netinet6/in6.c,v
retrieving revision 1.146
diff -u -p -r1.146 in6.c
--- netinet6/in6.c  24 Nov 2014 12:43:54 -  1.146
+++ netinet6/in6.c  26 Nov 2014 14:04:54 -
@@ -1053,6 +1053,9 @@ in6_purgeaddr(struct ifaddr *ifa)
 * XXX: we should avoid such a configuration in IPv6...
 */
TAILQ_FOREACH(tmp, in6_ifaddr, ia_list) {
+   if (tmp-ia_ifp-if_rdomain != ifp-if_rdomain)
+   continue;
+
if (IN6_ARE_ADDR_EQUAL(tmp-ia_addr.sin6_addr,
ia6-ia_addr.sin6_addr)) {
ia6_count++;



Re: pf(4) and struct route

2014-11-26 Thread Martin Pieuchot
On 26/11/14(Wed) 13:32, Martin Pieuchot wrote:
 On 25/11/14(Tue) 15:16, Todd C. Miller wrote:
  On Tue, 25 Nov 2014 16:43:16 +0100, Martin Pieuchot wrote:
  
   Diff below removes the non-needed usages of struct route  friends in
   pf.c,  any comment or ok?
  
  You are missing some initializations of rt to NULL, comments inline.
 
 Thanks for the reviews todd!  This is much appreciated now that network
 hacker is a critically endangered specie :)
 
 You'll find a corrected diff below.  Since I was asked to give more
 information about this change here's the story:
 
 We have currently two structures used to cache a route entry in order to
 avoid supplementary route lookups: struct route and struct route_in6.
 
 These structures store a pointer to a rtentry and the destination of
 this route.  Yes this is duplicated information.  There are mainly two
 problems with this design.  First of all the fact that we have a
 structure per AF, when a rtentry is AF agnostic, which results in a lot
 of #ifdefs  cast.  But the main reason to directly use a struct rtentry
 instead of these structures is to strengthen  unify the code checking 
 for the validity of a route.  I'd like at least to stop checking against
 a cached destination, I'd like to add a check for stall ifa and I'd like
 to add a check for reference counters.
 
 So the first move is to stop using such structure when we don't want to
 keep a reference on a route entry, then I'll modify the APIs keeping a
 reference and finally add more checks.

And know with the correct diff...


Index: net/pf.c
===
RCS file: /home/ncvs/src/sys/net/pf.c,v
retrieving revision 1.896
diff -u -p -r1.896 pf.c
--- net/pf.c20 Nov 2014 13:54:24 -  1.896
+++ net/pf.c26 Nov 2014 12:03:13 -
@@ -2952,42 +2952,36 @@ pf_calc_mss(struct pf_addr *addr, sa_fam
 {
 #ifdef INET
struct sockaddr_in  *dst;
-   struct route ro;
 #endif /* INET */
 #ifdef INET6
struct sockaddr_in6 *dst6;
-   struct route_in6 ro6;
 #endif /* INET6 */
struct rtentry  *rt = NULL;
+   struct sockaddr_storage  ss;
int  hlen;
u_int16_tmss = tcp_mssdflt;
 
+   memset(ss, 0, sizeof(ss));
+
switch (af) {
 #ifdef INET
case AF_INET:
hlen = sizeof(struct ip);
-   bzero(ro, sizeof(ro));
-   dst = (struct sockaddr_in *)ro.ro_dst;
+   dst = (struct sockaddr_in *)ss;
dst-sin_family = AF_INET;
dst-sin_len = sizeof(*dst);
dst-sin_addr = addr-v4;
-   ro.ro_tableid = rtableid;
-   ro.ro_rt = rtalloc(ro.ro_dst, RT_REPORT, ro.ro_tableid);
-   rt = ro.ro_rt;
+   rt = rtalloc(sintosa(dst), RT_REPORT, rtableid);
break;
 #endif /* INET */
 #ifdef INET6
case AF_INET6:
hlen = sizeof(struct ip6_hdr);
-   bzero(ro6, sizeof(ro6));
-   dst6 = (struct sockaddr_in6 *)ro6.ro_dst;
+   dst6 = (struct sockaddr_in6 *)ss;
dst6-sin6_family = AF_INET6;
dst6-sin6_len = sizeof(*dst6);
dst6-sin6_addr = addr-v6;
-   ro6.ro_tableid = rtableid;
-   ro6.ro_rt = rtalloc(sin6tosa(ro6.ro_dst), RT_REPORT,
-   ro6.ro_tableid);
-   rt = ro6.ro_rt;
+   rt = rtalloc(sin6tosa(dst6), RT_REPORT, rtableid);
break;
 #endif /* INET6 */
}
@@ -5396,25 +5390,22 @@ int
 pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif,
 int rtableid)
 {
+   struct sockaddr_storage  ss;
struct sockaddr_in  *dst;
int  ret = 1;
int  check_mpath;
 #ifdef INET6
struct sockaddr_in6 *dst6;
-   struct route_in6 ro;
-#else
-   struct route ro;
 #endif
-   struct rtentry  *rt;
+   struct rtentry  *rt = NULL;
struct ifnet*ifp;
 
check_mpath = 0;
-   bzero(ro, sizeof(ro));
-   ro.ro_tableid = rtableid;
+   memset(ss, 0, sizeof(ss));
switch (af) {
 #ifdef INET
case AF_INET:
-   dst = (struct sockaddr_in *)ro.ro_dst;
+   dst = (struct sockaddr_in *)ss;
dst-sin_family = AF_INET;
dst-sin_len = sizeof(*dst);
dst-sin_addr = addr-v4;
@@ -5430,7 +5421,7 @@ pf_routable(struct pf_addr *addr, sa_fam
 */
if (IN6_IS_SCOPE_EMBED(addr-v6))
goto out;
-   dst6 = ro.ro_dst;
+   dst6 = (struct sockaddr_in6 *)ss;
dst6-sin6_family = AF_INET6;
dst6-sin6_len = sizeof(*dst6);
dst6-sin6_addr = addr-v6;
@@ -5444,10 +5435,8 @@ 

Re: 64-bit PCI bridge support: testers needed

2014-11-26 Thread sven falempin
HEllo,

So i reported a bug with a pci bridge a while ago. On an Apu with a
pci to pci bridge over pci express.
Dmesg below

I use a recent snapshot
OpenBSD 5.6-current (GENERIC.MP) #610: Tue Nov 25 06:00:07 MST 2014

and assume the commit was in

The situation improved, as i can have the card running with bsd.mp for
more than a second. But on the second boot.
During the first boot i add the vr3: restarting kernel message when
asking for a lease on vr3. At this moment my not reliable serial usb
decide to do the classic freez. This time i was not able to get access
to the machine.

I am currently sending icmp trhough rl and vr and waiting for a problem.

bug mail objet was : pci disconnection creates interfaces instabilities

dmesg:


OpenBSD 5.6-current (GENERIC.MP) #610: Tue Nov 25 06:00:07 MST 2014
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 2098520064 (2001MB)
avail mem = 2038870016 (1944MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0x7e16d820 (7 entries)
bios0: vendor coreboot version 4.0 date 09/08/2014
bios0: PC Engines APU
acpi0 at bios0: rev 0
acpi0: sleep states S0 S1 S3 S4 S5
acpi0: tables DSDT FACP SPCR HPET APIC HEST SSDT SSDT SSDT
acpi0: wakeup devices AGPB(S4) HDMI(S4) PBR4(S4) PBR5(S4) PBR6(S4)
PBR7(S4) PE20(S4) PE21(S4) PE22(S4) PE23(S4) PIBR(S4) UOH1(S3)
UOH2(S3) UOH3(S3) UOH4(S3) UOH5(S3) [...]
acpitimer0 at acpi0: 3579545 Hz, 32 bits
acpihpet0 at acpi0: 14318180 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: AMD G-T40E Processor, 1000.14 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,MWAIT,SSSE3,CX16,POPCNT,NXE,MMXX,FFXSR,PAGE1GB,LONG,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,IBS,SKINIT,ITSC
cpu0: 32KB 64b/line 2-way I-cache, 32KB 64b/line 8-way D-cache, 512KB
64b/line 16-way L2 cache
cpu0: 8 4MB entries fully associative
cpu0: DTLB 40 4KB entries fully associative, 8 4MB entries fully associative
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
cpu0: apic clock running at 200MHz
cpu1 at mainbus0: apid 1 (application processor)
cpu1: AMD G-T40E Processor, 1000.00 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,MWAIT,SSSE3,CX16,POPCNT,NXE,MMXX,FFXSR,PAGE1GB,LONG,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,IBS,SKINIT,ITSC
cpu1: 32KB 64b/line 2-way I-cache, 32KB 64b/line 8-way D-cache, 512KB
64b/line 16-way L2 cache
cpu1: 8 4MB entries fully associative
cpu1: DTLB 40 4KB entries fully associative, 8 4MB entries fully associative
cpu1: smt 0, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 21, 24 pins
acpiprt0 at acpi0: bus -1 (AGPB)
acpiprt1 at acpi0: bus -1 (HDMI)
acpiprt2 at acpi0: bus 1 (PBR4)
acpiprt3 at acpi0: bus 2 (PBR5)
acpiprt4 at acpi0: bus 3 (PBR6)
acpiprt5 at acpi0: bus -1 (PBR7)
acpiprt6 at acpi0: bus 5 (PE20)
acpiprt7 at acpi0: bus -1 (PE21)
acpiprt8 at acpi0: bus -1 (PE22)
acpiprt9 at acpi0: bus -1 (PE23)
acpiprt10 at acpi0: bus 0 (PCI0)
acpiprt11 at acpi0: bus 4 (PIBR)
acpicpu0 at acpi0: C2, PSS
acpicpu1 at acpi0: C2, PSS
acpibtn0 at acpi0: PWRB
cpu0: 1000 MHz: speeds: 1000 800 MHz
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 AMD AMD64 14h Host rev 0x00
ppb0 at pci0 dev 4 function 0 AMD AMD64 14h PCIE rev 0x00: msi
pci1 at ppb0 bus 1
re0 at pci1 dev 0 function 0 Realtek 8168 rev 0x06: RTL8168E/8111E
(0x2c00), msi, address 00:0d:b9:33:85:d8
rgephy0 at re0 phy 7: RTL8169S/8110S PHY, rev. 4
ppb1 at pci0 dev 5 function 0 AMD AMD64 14h PCIE rev 0x00: msi
pci2 at ppb1 bus 2
re1 at pci2 dev 0 function 0 Realtek 8168 rev 0x06: RTL8168E/8111E
(0x2c00), msi, address 00:0d:b9:33:85:d9
rgephy1 at re1 phy 7: RTL8169S/8110S PHY, rev. 4
ppb2 at pci0 dev 6 function 0 AMD AMD64 14h PCIE rev 0x00: msi
pci3 at ppb2 bus 3
re2 at pci3 dev 0 function 0 Realtek 8168 rev 0x06: RTL8168E/8111E
(0x2c00), msi, address 00:0d:b9:33:85:da
rgephy2 at re2 phy 7: RTL8169S/8110S PHY, rev. 4
ahci0 at pci0 dev 17 function 0 ATI SBx00 SATA rev 0x40: apic 2 int
19, AHCI 1.2
scsibus1 at ahci0: 32 targets
ohci0 at pci0 dev 18 function 0 ATI SB700 USB rev 0x00: apic 2 int
18, version 1.0, legacy support
ehci0 at pci0 dev 18 function 2 ATI SB700 USB2 rev 0x00: apic 2 int 17
usb0 at ehci0: USB revision 2.0
uhub0 at usb0 ATI EHCI root hub rev 2.00/1.00 addr 1
ohci1 at pci0 dev 19 function 0 ATI SB700 USB rev 0x00: apic 2 int
18, version 1.0, legacy support
ehci1 at pci0 dev 19 function 2 ATI SB700 USB2 rev 0x00: apic 2 int 17
usb1 at ehci1: USB revision 2.0
uhub1 at usb1 ATI EHCI root hub rev 2.00/1.00 addr 1
piixpm0 at pci0 dev 20 function 0 ATI SBx00 SMBus rev 0x42: polling
iic0 at piixpm0
pcib0 at pci0 dev 20 function 3 ATI SB700 ISA rev 0x40
ppb3 at pci0 dev 20 function 4 ATI SB600 PCI rev 0x40
pci4 at ppb3 bus 4
ohci2 at pci0 dev 20 

Re: 64-bit PCI bridge support: testers needed

2014-11-26 Thread Mark Kettenis
 From: sven falempin sven.falem...@gmail.com
 Date: Wed, 26 Nov 2014 10:10:51 -0500
 
 HEllo,
 
 So i reported a bug with a pci bridge a while ago. On an Apu with a
 pci to pci bridge over pci express.
 Dmesg below
 
 I use a recent snapshot
 OpenBSD 5.6-current (GENERIC.MP) #610: Tue Nov 25 06:00:07 MST 2014
 
 and assume the commit was in
 
 The situation improved, as i can have the card running with bsd.mp for
 more than a second. But on the second boot.
 During the first boot i add the vr3: restarting kernel message when
 asking for a lease on vr3. At this moment my not reliable serial usb
 decide to do the classic freez. This time i was not able to get access
 to the machine.

I don't expect this diff to make any difference on your machine.



Re: pf(4) and struct route

2014-11-26 Thread Todd C. Miller
On Wed, 26 Nov 2014 15:21:43 +0100, Martin Pieuchot wrote:

 And know with the correct diff...

Looks good.

 - todd



Re: tcpdump: Ethernet header is not dumped with -xX if IP header is unaligned

2014-11-26 Thread Mike Belopuhov
On Tue, Nov 25, 2014 at 18:42 +0100, Mike Belopuhov wrote:
 On Mon, Nov 24, 2014 at 19:04 +0100, Mike Belopuhov wrote:
  Hi,
  
  IP header is not always aligned since bpf copies out the mbuf
  chain into the contigous buffer provided by the userland.  I've
  seen this with large packet sizes on VLANs.  ip_print will then
  copy the packet but the Ethernet header into the internal buffer
  so that it can cast it to the IP header structure and update
  global packetp and snapend pointers hence preventing the -Xx
  dumping code from printing out the Ethernet header itself.
  
  Diff below fixes it.  OK?
  
 
 better diff.  the problem is that dissectors use packetp and
 snapend pointers themselves therefore they should be pointing
 to the newly allocated structure.  we can restore them once
 we're done with the inner content and go back to the caller
 to see if we need to hexdump the contents.
 
 i'll see if i can cook and test the ipv6 version.
 
 OK?
 

now with an ip6 version and i've made sure that this fixes
dumping unaligned ipv6 packets as well.  in the meantime
jsg@ has lured me into looking at the afl crash in the same
code and it looks like the check from ip6_print is useful
here: if we haven't got enough data for a header, don't
bother with anything else and just bail.

ok?

diff --git usr.sbin/tcpdump/print-ip.c usr.sbin/tcpdump/print-ip.c
index 3f4194c..e9d2185 100644
--- usr.sbin/tcpdump/print-ip.c
+++ usr.sbin/tcpdump/print-ip.c
@@ -351,22 +351,27 @@ in_cksum(const u_short *addr, register int len, int csum)
  * print an IP datagram.
  */
 void
 ip_print(register const u_char *bp, register u_int length)
 {
+   static u_char *abuf = NULL;
register const struct ip *ip;
register u_int hlen, len, off;
register const u_char *cp;
+   const u_char *pktp = packetp;
+   const u_char *send = snapend;
 
ip = (const struct ip *)bp;
+   if ((u_char *)(ip + 1)  snapend) {
+   printf([|ip]);
+   return;
+   }
+
/*
 * If the IP header is not aligned, copy into abuf.
-* This will never happen with BPF.  It does happen with raw packet
-* dumps from -r.
 */
if ((intptr_t)ip  (sizeof(long)-1)) {
-   static u_char *abuf = NULL;
static int didwarn = 0;
int clen = snapend - bp;
 
if (clen  snaplen)
clen = snaplen;
@@ -387,11 +392,11 @@ ip_print(register const u_char *bp, register u_int length)
}
 
TCHECK(*ip);
if (ip-ip_v != IPVERSION) {
(void)printf(bad-ip-version %u, ip-ip_v);
-   return;
+   goto out;
}
 
len = ntohs(ip-ip_len);
if (length  len) {
(void)printf(truncated-ip - %d bytes missing!,
@@ -400,11 +405,11 @@ ip_print(register const u_char *bp, register u_int length)
}
 
hlen = ip-ip_hl * 4;
if (hlen  sizeof(struct ip) || hlen  len) {
(void)printf(bad-hlen %d, hlen);
-   return;
+   goto out;
}
 
len -= hlen;
 
/*
@@ -465,11 +470,11 @@ ip_print(register const u_char *bp, register u_int length)
 ipaddr_string(ip-ip_src),
 ipaddr_string(ip-ip_dst));
ip_print(cp, len);
if (! vflag) {
printf( (encap));
-   return;
+   goto out;
}
break;
 
 #ifdef INET6
 #ifndef IPPROTO_IPV6
@@ -482,11 +487,11 @@ ip_print(register const u_char *bp, register u_int length)
 ipaddr_string(ip-ip_src),
 ipaddr_string(ip-ip_dst));
ip6_print(cp, len);
if (! vflag) {
printf( (encap));
-   return;
+   goto out;
}
break;
 #endif /*INET6*/
 
 #ifndef IPPROTO_GRE
@@ -499,11 +504,11 @@ ip_print(register const u_char *bp, register u_int length)
 ipaddr_string(ip-ip_dst));
/* do it */
gre_print(cp, len);
if (! vflag) {
printf( (gre encap));
-   return;
+   goto out;
}
break;
 
 #ifndef IPPROTO_ESP
 #define IPPROTO_ESP 50
@@ -528,11 +533,11 @@ ip_print(register const u_char *bp, register u_int length)
 ipaddr_string(ip-ip_src),
 ipaddr_string(ip-ip_dst));

operations on nd_prefix list must take rdomain into account

2014-11-26 Thread Mike Belopuhov
More rdomain checks are needed to be able to use the same subnet
in a back to back connection between IPv6 rdomains as pointed out
by mpi@.

OK?

diff --git sys/netinet6/nd6.c sys/netinet6/nd6.c
index 9616187..d704cd6 100644
--- sys/netinet6/nd6.c
+++ sys/netinet6/nd6.c
@@ -1264,10 +1264,13 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
s = splsoftnet();
/* First purge the addresses referenced by a prefix. */
LIST_FOREACH_SAFE(pr, nd_prefix, ndpr_entry, npr) {
struct in6_ifaddr *ia6, *ia6_next;
 
+   if (pr-ndpr_ifp-if_rdomain != ifp-if_rdomain)
+   continue;
+
if (IN6_IS_ADDR_LINKLOCAL(pr-ndpr_prefix.sin6_addr))
continue; /* XXX */
 
/* do we really have to remove addresses as well? */
TAILQ_FOREACH_SAFE(ia6, in6_ifaddr, ia_list, ia6_next) 
{
@@ -1282,10 +1285,13 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
 * Purging the addresses might remove the prefix as well.
 * So run the loop again to access only prefixes that have
 * not been freed already.
 */
LIST_FOREACH_SAFE(pr, nd_prefix, ndpr_entry, npr) {
+   if (pr-ndpr_ifp-if_rdomain != ifp-if_rdomain)
+   continue;
+
if (IN6_IS_ADDR_LINKLOCAL(pr-ndpr_prefix.sin6_addr))
continue; /* XXX */
 
prelist_remove(pr);
}
diff --git sys/netinet6/nd6_rtr.c sys/netinet6/nd6_rtr.c
index bfc9c9f..e46b3b4 100644
--- sys/netinet6/nd6_rtr.c
+++ sys/netinet6/nd6_rtr.c
@@ -1690,10 +1690,13 @@ nd6_prefix_onlink(struct nd_prefix *pr)
 * interface, and the prefix has already installed the interface route.
 * Although such a configuration is expected to be rare, we explicitly
 * allow it.
 */
LIST_FOREACH(opr, nd_prefix, ndpr_entry) {
+   if (opr-ndpr_ifp-if_rdomain != ifp-if_rdomain)
+   continue;
+
if (opr == pr)
continue;
 
if ((opr-ndpr_stateflags  NDPRF_ONLINK) == 0)
continue;
@@ -1826,10 +1829,13 @@ nd6_prefix_offlink(struct nd_prefix *pr)
 * the interface route (see comments in nd6_prefix_onlink).
 * If there's one, try to make the prefix on-link on the
 * interface.
 */
LIST_FOREACH(opr, nd_prefix, ndpr_entry) {
+   if (opr-ndpr_ifp-if_rdomain != ifp-if_rdomain)
+   continue;
+
if (opr == pr)
continue;
 
if ((opr-ndpr_stateflags  NDPRF_ONLINK) != 0)
continue;



libtls: Secure default cipher list and dtls support

2014-11-26 Thread Manuel Schoelling
Hi,

I hope this is the right mailing list for discussing this issue. I could
not find any information about a mailing list on libressl.org.

It currently looks like the libtls version does not set a list of secure
ciphers by default (e.g. that does not include MD5 or SHA-1).
Would it be a reasonable idea to include secure defaults in libtls?

I also noticed that libtls is currently supporting SOCK_STREAM (TLS)
connections only. Is the support of SOCK_DGRAM (DTLS) connections within
the scope of this library and would patches be accepted?


Thanks

Manuel




Re: httpd: don't send error body with HEAD method

2014-11-26 Thread Bertrand Janin
Bertrand Janin wrote :
 Philip Guenther wrote :
  On Mon, Nov 24, 2014 at 11:24 AM, Florian Obser flor...@openbsd.org wrote:
  ...
   Since we are probably not supposed to send a Content-Type header I
   think it makes sense to duplicate the httpmsg generating code in this
   case;
  
  If a GET of that resource would have a Content-Type, then the HEAD of
  it should have one.  Per RFC 2616, HEAD and GET should return the same
  header fields and only differ by HEAD leaving out the body.
 
 Here is an updated patch which fix the leak identified by Florian, ensures the
 headers are identical with HEAD and non-HEAD methods and adds Content-Length.

Replaced strlen() with the output from asprintf(), any comments?


Index: usr.sbin/httpd/server_http.c
===
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.54
diff -u -p -r1.54 server_http.c
--- usr.sbin/httpd/server_http.c25 Oct 2014 03:23:49 -  1.54
+++ usr.sbin/httpd/server_http.c26 Nov 2014 03:05:48 -
@@ -665,10 +665,11 @@ server_abort_http(struct client *clt, u_
struct server   *srv = clt-clt_srv;
struct server_config*srv_conf = srv-srv_conf;
struct bufferevent  *bev = clt-clt_bev;
-   const char  *httperr = NULL, *text = ;
-   char*httpmsg, *extraheader = NULL;
+   struct http_descriptor  *desc = clt-clt_descreq;
+   const char  *httperr = NULL, *style;
+   char*httpmsg, *body = NULL, *extraheader = NULL;
char tmbuf[32], hbuf[128];
-   const char  *style;
+   int  bodylen;
 
if ((httperr = server_httperror_byid(code)) == NULL)
httperr = Unknown Error;
@@ -710,15 +711,9 @@ server_abort_http(struct client *clt, u_
style = body { background-color: white; color: black; font-family: 
'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }\n
hr { border: 0; border-bottom: 1px dashed; }\n;
-   /* Generate simple HTTP+HTML error document */
-   if (asprintf(httpmsg,
-   HTTP/1.0 %03d %s\r\n
-   Date: %s\r\n
-   Server: %s\r\n
-   Connection: close\r\n
-   Content-Type: text/html\r\n
-   %s
-   \r\n
+
+   /* Generate simple HTML error document */
+   if ((bodylen = asprintf(body,
!DOCTYPE HTML PUBLIC 
\-//W3C//DTD HTML 4.01 Transitional//EN\\n
html\n
@@ -728,14 +723,26 @@ server_abort_http(struct client *clt, u_
/head\n
body\n
h1%03d %s/h1\n
-   div id='m'%s/div\n
hr\naddress%s/address\n
/body\n
/html\n,
-   code, httperr, tmbuf, HTTPD_SERVERNAME,
+   code, httperr, style, code, httperr, HTTPD_SERVERNAME)) == -1)
+   goto done;
+
+   /* Add basic HTTP headers */
+   if (asprintf(httpmsg,
+   HTTP/1.0 %03d %s\r\n
+   Date: %s\r\n
+   Server: %s\r\n
+   Connection: close\r\n
+   Content-Type: text/html\r\n
+   Content-Length: %d\r\n
+   %s
+   \r\n
+   %s,
+   code, httperr, tmbuf, HTTPD_SERVERNAME, bodylen,
extraheader == NULL ?  : extraheader,
-   code, httperr, style, code, httperr, text,
-   HTTPD_SERVERNAME) == -1)
+   desc-http_method == HTTP_METHOD_HEAD ?  : body) == -1)
goto done;
 
/* Dump the message without checking for success */
@@ -743,6 +750,7 @@ server_abort_http(struct client *clt, u_
free(httpmsg);
 
  done:
+   free(body);
free(extraheader);
if (asprintf(httpmsg, %s (%03d %s), msg, code, httperr) == -1) {
server_close(clt, msg);



future direction of /var/tmp

2014-11-26 Thread thevoid
On Wed, 26 Nov 2014 08:52:30 -0700 (MST) Antoine Jacoutot 
ajacou...@cvs.openbsd.org wrote:
 CVSROOT:  /cvs
 Module name:  src
 Changes by:   ajacou...@cvs.openbsd.org   2014/11/26 08:52:30
 
 Modified files:
   usr.sbin/sysmerge: sysmerge.8 sysmerge.sh 
 
 Log message:
 Drop sysmerge.log ; it used to be handy for batch mode but now the
 console output is clear and clean in that mode.
 
 Since /var/tmp is now a symlink to /tmp:
 - directly use /tmp
 - if modifications were done; at the end of the run:
 - display our backup directory (in case we want to move it to survive a 
 reboot)
 - display where and what files are still left for comparison
 
 discussed with and ok sthen@
 

what are the future plans with regards to /var/tmp? obviously it will be
around for a while, but is there a general intention to change it to /tmp
as implied above? this is timely for me, because i just thought about this
when doing ports, where PKG_TMPDIR=/var/tmp, and was about to ask: are (some)
diffs welcome for this?



Re: locate(1): ignore paths longer than MAXPATHLEN

2014-11-26 Thread Nicolas Bedos
Last update, with Tobias's help.

The following diff 
- changes MAXPATHLEN from sys/param.h to PATH_MAX from limits.h
- adds a missing prototype for sane_count
- locate.bigram and locate.code now abort when reading a pathname
  exceeding PATH_MAX bytes on stdin
  

Index: src/usr.bin/locate//bigram/locate.bigram.c
===
RCS file: /cvs/src/usr.bin/locate/bigram/locate.bigram.c,v
retrieving revision 1.12
diff -u -p -u -r1.12 locate.bigram.c
--- src/usr.bin/locate//bigram/locate.bigram.c  27 Oct 2009 23:59:39 -  
1.12
+++ src/usr.bin/locate//bigram/locate.bigram.c  26 Nov 2014 18:15:13 -
@@ -43,30 +43,41 @@
  * Use 'code' to encode a file using this output.
  */
 
+#include err.h
+#include limits.h/* for PATH_MAX */
 #include stdio.h
 #include stdlib.h
-#include sys/param.h /* for MAXPATHLEN */
+#include string.h
 #include locate.h
 
-u_char buf1[MAXPATHLEN] =  ;
-u_char buf2[MAXPATHLEN];
+u_char buf[PATH_MAX] =  ;
 u_int bigram[UCHAR_MAX + 1][UCHAR_MAX + 1];
 
 int
 main(void)
 {
u_char *cp;
-   u_char *oldpath = buf1, *path = buf2;
+   u_char *oldpath = buf, *path, *mbuf;
u_int i, j;
+   size_t len;
 
-   while (fgets(path, sizeof(buf2), stdin) != NULL) {
+   mbuf = NULL;
 
-   /*
-* We don't need remove newline character '\n'.
-* '\n' is less than ASCII_MIN and will be later
-* ignored at output.
-*/
+   while ((path=(u_char *)fgetln(stdin, len)) != NULL) {
+   if (path[len-1] == '\n')
+   path[len-1] = '\0';
+   else {
+   if ((mbuf=malloc(len+1)) == NULL)
+   err(1, malloc);
+   memcpy(mbuf, path, len);
+   mbuf[len] = '\0';
+   len++;
+   path = mbuf;
+   }
 
+   if (len  sizeof(buf))
+   errx(1, pathname exceeding %zu byte limit: %s,
+   sizeof(buf), path);
 
/* skip longest common prefix */
for (cp = path; *cp == *oldpath; cp++, oldpath++)
@@ -78,14 +89,7 @@ main(void)
cp += 2;
}
 
-   /* swap pointers */
-   if (path == buf1) {
-   path = buf2;
-   oldpath = buf1;
-   } else {
-   path = buf1;
-   oldpath = buf2;
-   }
+   memcpy(buf, path, len);
}
 
/* output, boundary check */
Index: src/usr.bin/locate//code/locate.code.c
===
RCS file: /cvs/src/usr.bin/locate/code/locate.code.c,v
retrieving revision 1.17
diff -u -p -u -r1.17 locate.code.c
--- src/usr.bin/locate//code/locate.code.c  17 Nov 2013 20:19:36 -  
1.17
+++ src/usr.bin/locate//code/locate.code.c  26 Nov 2014 18:15:13 -
@@ -78,10 +78,10 @@
  * Wolfram Schneider, Berlin September 1996
  */
 
-#include sys/param.h
 
 #include err.h
 #include errno.h
+#include limits.h
 #include stdio.h
 #include stdlib.h
 #include string.h
@@ -91,8 +91,7 @@
 
 #defineBGBUFSIZE   (NBG * 2)   /* size of bigram buffer */
 
-u_char buf1[MAXPATHLEN] =  ;
-u_char buf2[MAXPATHLEN];
+u_char buf[PATH_MAX] =  ;
 u_char bigrams[BGBUFSIZE + 1] = { 0 };
 
 #define LOOKUP 1 /* use a lookup array instead a function, 3x faster */
@@ -115,7 +114,8 @@ extern int optopt;
 int
 main(int argc, char *argv[])
 {
-   u_char *cp, *oldpath, *path;
+   u_char *cp, *oldpath, *path, *mbuf;
+   size_t len;
int ch, code, count, diffcount, oldcount;
FILE *fp;
int i, j;
@@ -156,23 +156,31 @@ main(int argc, char *argv[])
 
 #endif /* LOOKUP */
 
-   oldpath = buf1;
-   path = buf2;
+   oldpath = buf;
oldcount = 0;
+   mbuf = NULL;
 
-   while (fgets(path, sizeof(buf2), stdin) != NULL) {
-
+   while ((path=(u_char *)fgetln(stdin, len)) != NULL) {
/* skip empty lines */
if (*path == '\n')
continue;
 
-   /* remove newline */
-   for (cp = path; *cp != '\0'; cp++) {
-   /* chop newline */
-   if (*cp == '\n')
-   *cp = '\0';
+   if (path[len-1] == '\n') {
+   /* remove newline */
+   path[len-1] = '\0';
+   } else {
+   if ((mbuf = malloc(len+1)) == NULL)
+   err(1, malloc);
+   memcpy(mbuf, path, len);
+   mbuf[len] = '\0';
+   len++;
+   path = mbuf;
}
 
+   if (len  

Re: locate(1): ignore paths longer than MAXPATHLEN

2014-11-26 Thread Tobias Stoeckmann
On Wed, Nov 26, 2014 at 09:48:15PM +0100, Nicolas Bedos wrote:
 Last update, with Tobias's help.
 
 The following diff 
 - changes MAXPATHLEN from sys/param.h to PATH_MAX from limits.h
 - adds a missing prototype for sane_count
 - locate.bigram and locate.code now abort when reading a pathname
   exceeding PATH_MAX bytes on stdin

If somebody else agrees with this diff, I'll adjust the last
style-deviations and commit it.


Tobias