Iain Hibbert | 3 Sep 23:01 2015
Picon

fortification

Hello

while I was looking at the ssp/fortification code, I noticed something..
the following code example

#include <string.h>

int a, b;

void foo(void)
{
	memcpy(&a, &b, sizeof(a));
}

when preprocessed with fortification enabled

% gcc -fstack-protector -O2 -D_FORTIFY_SOURCE=2 -E -o test.i test.c

outputs basically the following code (I've added spaces and cut out the 
unrelated parts)

static __inline void * __memcpy_ichk(void * __restrict__, const void * __restrict__, size_t);

static __inline __attribute__((__always_inline__)) void * __memcpy_ichk(void * __restrict__ dst,
const void * __restrict__ src, size_t len)
{
	return __builtin___memcpy_chk(dst, src, len, __builtin_object_size(dst, 0));
}

int a, b;
(Continue reading)

Edgar Fuß | 3 Sep 12:15 2015
Picon

(b)make: selecting every other element from a list

Is there a sane way of, in a Makefile, selecting every other (i.e. either 
even or odd, I don't care) member from a list?
I'm aware of bmake's nice feature of iterating on tuples, but I need to 
select a unique subset of those list members. I.e., given
	l= foo 1 bar 2 foo 3
or
	l= 1 foo 2 bar 3 foo
if that's more convenient, I want foo bar (or bar foo), so I'd need 
something like ${l:[!odd!]:O:u}

Iain Hibbert | 2 Sep 22:31 2015
Picon

__ssp_overlap() bug?

Hi

I think the recently added __ssp_overlap() macro is incorrect, as adjacent 
areas will trigger it. example test code below shows the problem..

#include <ssp/ssp.h>
#include <stdio.h>

int a, b;

int
main(int argc, char *argv[])
{

	printf("a %p, b %p, l %zu\n", &a, &b, sizeof(a));

	if (__ssp_overlap((char *)&a, (char *)&b, sizeof(a)))
		printf("a and b overlap\n");
	else
		printf("no overlap\n");

	return 0;
}

and patch to fix.. is this ok to commit?

iain

Index: ssp.h
===================================================================
(Continue reading)

Tilman Kranz | 29 Aug 09:23 2015
Picon

Determining if a system is in shutdown

Hello,

for a patch for "nodm" (a lightweight X session manager), I try
to find out how to determine if a system is currently in shutdown.

The intention is to prevent "nodm" from restarting an X session
that caught a SIGTERM while the system is in shutdown.

I found this to work on GNU using SVr4 "utmp.h":

  #include<stdlib.h>
  #include<utmp.h>

  int in_shutdown(void) {
      struct utmp * ut;

      setutent();

      while ((ut = getutent()) != NULL)
          if (ut->ut_type == RUN_LVL)
            /* Current runlevel is pid_t modulo 256.
               Runlevel 0 means system is in shutdown. */
            return ut->ut_pid % 256 == 0;

      return -1;
  }

(This does not work with POSIX "utmpx.h", because there is
no RUN_LVL there, for obvious reasons).

(Continue reading)

Masao Uebayashi | 25 Aug 06:00 2015
Picon

Modular postinstall(8)

http://www.netbsd.org/~uebayasi/postinstall.txt

The monolithic postinstall(8) is horribly painful to maintain.  It can
be a little better by splitting the single script into per-module
(a.k.a. syspkg).  This hopefully encourages subsystem maintainers to
update their own postinstall script fragment without touching a
global, poorly maintained script.  This is much closer to how pkgsrc's
install scripts work.

Ideally these ``update'' scripts are called not only post-install but
also pre-install, pre-reboot, post-reboot, etc.  For example, if one
pre-install script detects something seriously inconsistent, it warns
administrator and cancels the update.

Well-maintained update scripts could safely migrate users to better
configurations ("This sshd configuration is outdated and not
recommended any longer").

The above patch is outdated and should be updated but you can see the
idea.  You can split files one-by-one.

I don't have time to discuss/work on this right now.

Idea basically ack'ed by lukem <at>  at EuroBSDCon 2014. :)

Christos Zoulas | 21 Aug 18:43 2015

printf and -m


Beckground:

gcc assumes that %m is a valid printf(3) format. In BSD %m is only valid
in syslog(3) like functions and means strerror(errno). GLIBC and MUSLC
implement %m also for printf(3).

Description: 

This patch does the following:

gcc:
- Introduces a format attribute called "syslog" that accepts %m.
- Makes the printf attribute not accept %m.

src:
- Introduces a __sysloglike() macro that uses the new format attribute
  if available, and fails back to the standard printf attribute.
- Changes log-like functions to use the new attribute.

We should decide what we want to do:

- Make %m work in printf() like linux does.
- Apply the following patch to prevent programs use %m in printf formats,
  keep fixing 3rd party code, and maintain the custom format attribute to
  find new offenders. It is unlikely that the gnu folks will take a patch
  that makes %m warn for printf. We could coordinate with other BSD's to
  do the same. Note that this patch can break pkgsrc code...

What do you think?
(Continue reading)

Emmanuel Dreyfus | 13 Aug 12:01 2015
X-Face
Picon

Cannot mmap character device

Hello

the mmap(2) page explicitely notes that we may map character devices.
Anyone can tell me why this fails?

# cat test.c                                                                 
#include <err.h>
#include <fcntl.h>
#include <sys/mman.h>

int
main(void)
{
        int fd;
        void *map;

        if ((fd = open("/dev/rxbd1a", O_RDONLY, 0)) == -1)
                err(1, "open /dev/rxbd1a failed");

        map = mmap(NULL, 4096, PROT_READ, MAP_FILE, fd, 8192);
        if (map == MAP_FAILED)
                err(1, "mmap /dev/rxbd1a failed");

        return 0;
}
# cc -Wall -ansi -o test test.c
# ./test
test: mmap /dev/rxbd1a failed: Invalid argument
# ls -l /dev/*xbd1a 
crw-r-----  1 root  backups        142, 8 Nov 17  2006 /dev/rxbd1a
(Continue reading)

David Young | 11 Aug 22:54 2015
Picon

Introducing ARFE

A few years ago, while I was debugging and tuning up NetBSD networking
code, I was interested in the rate of change of many statistics (netstat
-s, ifconfig -va).  I was producing lots of "before and after" stats

	ifconfig -va > before ; sleep 10 ; ifconfig -va > after

and comparing or subtracting them in my head.  A strong urge to
automate the subtraction without writing a one-off script (or scripts)
led me to write a universal statistics subtractor.  In this way,
DT---(d)ifferentiate (t)ext---was born.

DT reads two inputs and finds a longest common subsequence (LCS) of the
inputs where numbers are "wild": one number, consisting of an optional
sign followed by one or more decimal digits, can match any other.  Then
DT emits the LCS, printing the difference of all of the numbers in the
common sequence.  I will give an example.  DT input 1:

wm0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	capabilities=2bf80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Tx,UDP6CSUM_Tx>
	enabled=2bf80<TSO4,IP4CSUM_Rx,IP4CSUM_Tx,TCP4CSUM_Rx,TCP4CSUM_Tx,UDP4CSUM_Rx,UDP4CSUM_Tx,TCP6CSUM_Tx,UDP6CSUM_Tx>
	address: 00:0a:0b:cd:01:ef
	media: Ethernet autoselect (1000baseT full-duplex)
	status: active
	input: 9348780 packets, 2659054914 bytes, 2853146 multicasts
	output: 5844547 packets, 1166873148 bytes, 2667 multicasts
	inet 10.0.1.17 netmask 0xffffff00 broadcast 10.0.1.255
	inet6 fe80::20a:bff:fecd:1ef%wm0 prefixlen 64 scopeid 0x1

Input 2:

(Continue reading)

Jeff Rizzo | 30 Jul 22:40 2015
Picon

default root crontab sets HOME=/var/log

It recently came to my attention that the default root crontab sets 
HOME=/var/log, and has done since rev 1.2 in April of 1993 (!)

I discovered this because I added a backup command to my root crontab 
which didn't work, even though it had been working from the command 
line, because it could no longer find its default configuration (which 
was stored in root's home dir, by default).

1) Does anyone know why we would _want_ HOME set to /var/log?  I confess 
I never gave it any thought in over 20 years of seeing that there.

2) might we want to consider, you know, changing it?  POLA and all that...

Thoughts?

Edgar Fuß | 27 Jul 20:09 2015
Picon

rc.d/postfix:postfix_precmd()

I think the part of postfix_precmd() that tries to re-build the alias 
databases is less than helpful:

1. It doesn't deal with alias_database entries seperated by commas
2. It doesn't do variable expansion on the alias_database entries
3. It runs newaliases for every outdated or missing member instead of once.

I don't know how to properly handle (2). The only way I can think of is 
through postconf -b, but that's quite ugly.
The most common case should be a leading $config_directory

	_rebuild=false
	_configdir=$($postconf -h config_directory)
	_IFS="$IFS"; IFS=",$IFS"
	for f in $($postconf -h alias_database); do
		case $f in
			hash:*) f="${f#hash:}" ;;
			*) continue ;;
		esac
		case $f in
			\$config_directory*) f="$_configdir${f#\$config_directory}" ;;
			\${config_directory}*) f="$_configdir${f#\${config_directory\}}" ;;
			\$\(config_directory\)*) f="$_configdir${f#\$(config_directory)}" ;;
		esac
		if [ ! -e "$f.db" ]; then
			_reason="missing"
			_rebuild=true;
		elif [ "$f" -nt "$f.db" ]; then
			_reason="out of date"
			_rebuild=true;
(Continue reading)

Christof Meerwald | 25 Jul 18:23 2015

Waking up all threads waiting in kevent

Hi,

I have got multiple threads waiting on a single kqueue and want to
wake up all these threads at some point (before exiting). I believe
the way to do it is to have a dummy socket/pipe added to the kqueue
and close the other end (I have also found
http://thread.gmane.org/gmane.os.netbsd.devel.kernel/28051 which seems
to agree on that approach).

But when I am actually testing this approach, some threads don't seem
to be woken up and keep waiting in the kevent syscall. Source code for
a test case is available from
http://svn.cmeerw.net/src/nginetd/trunk/test/kqtest-wakeup.cc

I have tested on my ODROID-C1 (quad core ARMv7) with netbsd-7 (build
from a few days ago) and seen the problem occur with 3 or more
threads.

Is there a problem in my test case, is it a kernel bug or an
ODROID-C1/ARM specific issue? Any ideas?

Christof

--

-- 

http://cmeerw.org                              sip:cmeerw at cmeerw.org
mailto:cmeerw at cmeerw.org                   xmpp:cmeerw at cmeerw.org


Gmane