svn commit: r367820 - head/sys/kern

2020-11-18 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Nov 18 21:26:14 2020
New Revision: 367820
URL: https://svnweb.freebsd.org/changeset/base/367820

Log:
  Add CTLFLAG_MPSAFE to the suser_enabled sysctl.
  
  Pointed out by:   mjg

Modified:
  head/sys/kern/kern_priv.c

Modified: head/sys/kern/kern_priv.c
==
--- head/sys/kern/kern_priv.c   Wed Nov 18 21:07:08 2020(r367819)
+++ head/sys/kern/kern_priv.c   Wed Nov 18 21:26:14 2020(r367820)
@@ -107,8 +107,8 @@ sysctl_kern_suser_enabled(SYSCTL_HANDLER_ARGS)
 }
 
 SYSCTL_PROC(_security_bsd, OID_AUTO, suser_enabled, CTLTYPE_INT |
-CTLFLAG_RWTUN | CTLFLAG_PRISON, 0, 0, _kern_suser_enabled, "I",
-"Processes with uid 0 have privilege");
+CTLFLAG_RWTUN | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 0, 0,
+_kern_suser_enabled, "I", "Processes with uid 0 have privilege");
 
 static int unprivileged_mlock = 1;
 SYSCTL_INT(_security_bsd, OID_AUTO, unprivileged_mlock, CTLFLAG_RWTUN,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r367819 - in head: sys/kern sys/sys usr.sbin/jail

2020-11-18 Thread Mariusz Zaborski
Hello Mateusz,

Thank you for pointing out this. I will fix those.

Thanks,
Mariusz

On Wed, 18 Nov 2020 at 22:15, Mateusz Guzik  wrote:
>
> On 11/18/20, Mariusz Zaborski  wrote:
> > Author: oshogbo
> > Date: Wed Nov 18 21:07:08 2020
> > New Revision: 367819
> > URL: https://svnweb.freebsd.org/changeset/base/367819
> >
> > Log:
> >   jail: introduce per jail suser_enabled setting
> >
> >   The suser_enable sysctl allows to remove a privileged rights from uid 0.
> >   This change introduce per jail setting which allow to make root a
> >   normal user.
> >
> >   Reviewed by:jamie
> >   Previous version reviewed by:   kevans, emaste, markj, me_igalic.co
> >   Discussed with: pjd
> >   Differential Revision:  https://reviews.freebsd.org/D27128
> >
> > Modified:
> >   head/sys/kern/kern_jail.c
> >   head/sys/kern/kern_priv.c
> >   head/sys/sys/jail.h
> >   head/usr.sbin/jail/jail.8
> >
> > Modified: head/sys/kern/kern_jail.c
> > ==
> > --- head/sys/kern/kern_jail.c Wed Nov 18 20:59:58 2020(r367818)
> > +++ head/sys/kern/kern_jail.c Wed Nov 18 21:07:08 2020(r367819)
> > @@ -199,12 +199,14 @@ static struct bool_flags pr_flag_allow[NBBY * NBPW] =
> >
> >   {"allow.read_msgbuf", "allow.noread_msgbuf", PR_ALLOW_READ_MSGBUF},
> >   {"allow.unprivileged_proc_debug", "allow.nounprivileged_proc_debug",
> >PR_ALLOW_UNPRIV_DEBUG},
> > + {"allow.suser", "allow.nosuser", PR_ALLOW_SUSER},
> >  };
> >  const size_t pr_flag_allow_size = sizeof(pr_flag_allow);
> >
> >  #define  JAIL_DEFAULT_ALLOW  (PR_ALLOW_SET_HOSTNAME | \
> >PR_ALLOW_RESERVED_PORTS | \
> > -  PR_ALLOW_UNPRIV_DEBUG)
> > +  PR_ALLOW_UNPRIV_DEBUG | \
> > +  PR_ALLOW_SUSER)
> >  #define  JAIL_DEFAULT_ENFORCE_STATFS 2
> >  #define  JAIL_DEFAULT_DEVFS_RSNUM0
> >  static unsigned jail_default_allow = JAIL_DEFAULT_ALLOW;
> > @@ -3815,6 +3817,8 @@ SYSCTL_JAIL_PARAM(_allow, read_msgbuf, CTLTYPE_INT |
> > C
> >  "B", "Jail may read the kernel message buffer");
> >  SYSCTL_JAIL_PARAM(_allow, unprivileged_proc_debug, CTLTYPE_INT |
> > CTLFLAG_RW,
> >  "B", "Unprivileged processes may use process debugging facilities");
> > +SYSCTL_JAIL_PARAM(_allow, suser, CTLTYPE_INT | CTLFLAG_RW,
> > +"B", "Processes in jail with uid 0 have privilege");
> >
> >  SYSCTL_JAIL_PARAM_SUBNODE(allow, mount, "Jail mount/unmount permission
> > flags");
> >  SYSCTL_JAIL_PARAM(_allow_mount, , CTLTYPE_INT | CTLFLAG_RW,
> >
> > Modified: head/sys/kern/kern_priv.c
> > ==
> > --- head/sys/kern/kern_priv.c Wed Nov 18 20:59:58 2020(r367818)
> > +++ head/sys/kern/kern_priv.c Wed Nov 18 21:07:08 2020(r367819)
> > @@ -3,6 +3,7 @@
> >   *
> >   * Copyright (c) 2006 nCircle Network Security, Inc.
> >   * Copyright (c) 2009 Robert N. M. Watson
> > + * Copyright (c) 2020 Mariusz Zaborski 
> >   * All rights reserved.
> >   *
> >   * This software was developed by Robert N. M. Watson for the TrustedBSD
> > @@ -36,6 +37,9 @@ __FBSDID("$FreeBSD$");
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > +#include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -54,10 +58,58 @@ __FBSDID("$FreeBSD$");
> >   * userland programs, and should not be done without careful consideration
> > of
> >   * the consequences.
> >   */
> > -static int __read_mostly suser_enabled = 1;
> > -SYSCTL_INT(_security_bsd, OID_AUTO, suser_enabled, CTLFLAG_RWTUN,
> > -_enabled, 0, "processes with uid 0 have privilege");
> >
> > +static bool
> > +suser_enabled(struct ucred *cred)
> > +{
> > +
> > + return (prison_allow(cred, PR_ALLOW_SUSER) ? true : false);
> > +}
> > +
>
> This converts a variable read into a function call to prison_allow.
> prison_allow should be converted into an inline func and put in a
> header.
>
> Also:
> /* This is an atomic read, so no locking is necessary. */
> return (cred->cr_pr

svn commit: r367819 - in head: sys/kern sys/sys usr.sbin/jail

2020-11-18 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Nov 18 21:07:08 2020
New Revision: 367819
URL: https://svnweb.freebsd.org/changeset/base/367819

Log:
  jail: introduce per jail suser_enabled setting
  
  The suser_enable sysctl allows to remove a privileged rights from uid 0.
  This change introduce per jail setting which allow to make root a
  normal user.
  
  Reviewed by:  jamie
  Previous version reviewed by: kevans, emaste, markj, me_igalic.co
  Discussed with:   pjd
  Differential Revision:https://reviews.freebsd.org/D27128

Modified:
  head/sys/kern/kern_jail.c
  head/sys/kern/kern_priv.c
  head/sys/sys/jail.h
  head/usr.sbin/jail/jail.8

Modified: head/sys/kern/kern_jail.c
==
--- head/sys/kern/kern_jail.c   Wed Nov 18 20:59:58 2020(r367818)
+++ head/sys/kern/kern_jail.c   Wed Nov 18 21:07:08 2020(r367819)
@@ -199,12 +199,14 @@ static struct bool_flags pr_flag_allow[NBBY * NBPW] = 
{"allow.read_msgbuf", "allow.noread_msgbuf", PR_ALLOW_READ_MSGBUF},
{"allow.unprivileged_proc_debug", "allow.nounprivileged_proc_debug",
 PR_ALLOW_UNPRIV_DEBUG},
+   {"allow.suser", "allow.nosuser", PR_ALLOW_SUSER},
 };
 const size_t pr_flag_allow_size = sizeof(pr_flag_allow);
 
 #defineJAIL_DEFAULT_ALLOW  (PR_ALLOW_SET_HOSTNAME | \
 PR_ALLOW_RESERVED_PORTS | \
-PR_ALLOW_UNPRIV_DEBUG)
+PR_ALLOW_UNPRIV_DEBUG | \
+PR_ALLOW_SUSER)
 #defineJAIL_DEFAULT_ENFORCE_STATFS 2
 #defineJAIL_DEFAULT_DEVFS_RSNUM0
 static unsigned jail_default_allow = JAIL_DEFAULT_ALLOW;
@@ -3815,6 +3817,8 @@ SYSCTL_JAIL_PARAM(_allow, read_msgbuf, CTLTYPE_INT | C
 "B", "Jail may read the kernel message buffer");
 SYSCTL_JAIL_PARAM(_allow, unprivileged_proc_debug, CTLTYPE_INT | CTLFLAG_RW,
 "B", "Unprivileged processes may use process debugging facilities");
+SYSCTL_JAIL_PARAM(_allow, suser, CTLTYPE_INT | CTLFLAG_RW,
+"B", "Processes in jail with uid 0 have privilege");
 
 SYSCTL_JAIL_PARAM_SUBNODE(allow, mount, "Jail mount/unmount permission flags");
 SYSCTL_JAIL_PARAM(_allow_mount, , CTLTYPE_INT | CTLFLAG_RW,

Modified: head/sys/kern/kern_priv.c
==
--- head/sys/kern/kern_priv.c   Wed Nov 18 20:59:58 2020(r367818)
+++ head/sys/kern/kern_priv.c   Wed Nov 18 21:07:08 2020(r367819)
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2006 nCircle Network Security, Inc.
  * Copyright (c) 2009 Robert N. M. Watson
+ * Copyright (c) 2020 Mariusz Zaborski 
  * All rights reserved.
  *
  * This software was developed by Robert N. M. Watson for the TrustedBSD
@@ -36,6 +37,9 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -54,10 +58,58 @@ __FBSDID("$FreeBSD$");
  * userland programs, and should not be done without careful consideration of
  * the consequences.
  */
-static int __read_mostly   suser_enabled = 1;
-SYSCTL_INT(_security_bsd, OID_AUTO, suser_enabled, CTLFLAG_RWTUN,
-_enabled, 0, "processes with uid 0 have privilege");
 
+static bool
+suser_enabled(struct ucred *cred)
+{
+
+   return (prison_allow(cred, PR_ALLOW_SUSER) ? true : false);
+}
+
+static void inline
+prison_suser_set(struct prison *pr, int enabled)
+{
+
+   if (enabled) {
+   pr->pr_allow |= PR_ALLOW_SUSER;
+   } else {
+   pr->pr_allow &= ~PR_ALLOW_SUSER;
+   }
+}
+
+static int
+sysctl_kern_suser_enabled(SYSCTL_HANDLER_ARGS)
+{
+   struct prison *pr, *cpr;
+   struct ucred *cred;
+   int descend, error, enabled;
+
+   cred = req->td->td_ucred;
+   enabled = suser_enabled(cred);
+
+   error = sysctl_handle_int(oidp, , 0, req);
+   if (error || !req->newptr)
+   return (error);
+
+   pr = cred->cr_prison;
+   sx_slock(_lock);
+   mtx_lock(>pr_mtx);
+
+   prison_suser_set(pr, enabled);
+   if (!enabled) {
+   FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) {
+   prison_suser_set(cpr, 0);
+   }
+   }
+   mtx_unlock(>pr_mtx);
+   sx_sunlock(_lock);
+   return (0);
+}
+
+SYSCTL_PROC(_security_bsd, OID_AUTO, suser_enabled, CTLTYPE_INT |
+CTLFLAG_RWTUN | CTLFLAG_PRISON, 0, 0, _kern_suser_enabled, "I",
+"Processes with uid 0 have privilege");
+
 static int unprivileged_mlock = 1;
 SYSCTL_INT(_security_bsd, OID_AUTO, unprivileged_mlock, CTLFLAG_RWTUN,
 _mlock, 0, "Allow non-root users to call mlock(2)&quo

svn commit: r367818 - head/sys/kern

2020-11-18 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Nov 18 20:59:58 2020
New Revision: 367818
URL: https://svnweb.freebsd.org/changeset/base/367818

Log:
  Fix style nits.

Modified:
  head/sys/kern/kern_jail.c
  head/sys/kern/kern_priv.c

Modified: head/sys/kern/kern_jail.c
==
--- head/sys/kern/kern_jail.c   Wed Nov 18 20:20:03 2020(r367817)
+++ head/sys/kern/kern_jail.c   Wed Nov 18 20:59:58 2020(r367818)
@@ -3739,9 +3739,9 @@ SYSCTL_JAIL_PARAM_STRING(, name, CTLFLAG_RW, MAXHOSTNA
 SYSCTL_JAIL_PARAM_STRING(, path, CTLFLAG_RDTUN, MAXPATHLEN, "Jail root path");
 SYSCTL_JAIL_PARAM(, securelevel, CTLTYPE_INT | CTLFLAG_RW,
 "I", "Jail secure level");
-SYSCTL_JAIL_PARAM(, osreldate, CTLTYPE_INT | CTLFLAG_RDTUN, "I", 
+SYSCTL_JAIL_PARAM(, osreldate, CTLTYPE_INT | CTLFLAG_RDTUN, "I",
 "Jail value for kern.osreldate and uname -K");
-SYSCTL_JAIL_PARAM_STRING(, osrelease, CTLFLAG_RDTUN, OSRELEASELEN, 
+SYSCTL_JAIL_PARAM_STRING(, osrelease, CTLFLAG_RDTUN, OSRELEASELEN,
 "Jail value for kern.osrelease and uname -r");
 SYSCTL_JAIL_PARAM(, enforce_statfs, CTLTYPE_INT | CTLFLAG_RW,
 "I", "Jail cannot see all mounted file systems");

Modified: head/sys/kern/kern_priv.c
==
--- head/sys/kern/kern_priv.c   Wed Nov 18 20:20:03 2020(r367817)
+++ head/sys/kern/kern_priv.c   Wed Nov 18 20:59:58 2020(r367818)
@@ -54,7 +54,7 @@ __FBSDID("$FreeBSD$");
  * userland programs, and should not be done without careful consideration of
  * the consequences.
  */
-static int __read_mostly   suser_enabled = 1;
+static int __read_mostly   suser_enabled = 1;
 SYSCTL_INT(_security_bsd, OID_AUTO, suser_enabled, CTLFLAG_RWTUN,
 _enabled, 0, "processes with uid 0 have privilege");
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367487 - head/sys/contrib/openzfs/module/os/freebsd/zfs

2020-11-08 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Nov  8 14:08:00 2020
New Revision: 367487
URL: https://svnweb.freebsd.org/changeset/base/367487

Log:
  Check if the ZVOL has been written before calling zil_async_to_sync.
  The ZIL will be opened on the first write, not earlier.
  
  Reviewed-by: Ryan Moeller 
  Reviewed-by: Brian Behlendorf 
  Signed-off-by: Mariusz Zaborski 
  OpenZFS Pull Request: https://github.com/openzfs/zfs/pull/11152
  PR:   250934

Modified:
  head/sys/contrib/openzfs/module/os/freebsd/zfs/zvol_os.c

Modified: head/sys/contrib/openzfs/module/os/freebsd/zfs/zvol_os.c
==
--- head/sys/contrib/openzfs/module/os/freebsd/zfs/zvol_os.cSun Nov  8 
13:30:44 2020(r367486)
+++ head/sys/contrib/openzfs/module/os/freebsd/zfs/zvol_os.cSun Nov  8 
14:08:00 2020(r367487)
@@ -890,7 +890,8 @@ zvol_cdev_open(struct cdev *dev, int flags, int fmt, s
if (flags & (FSYNC | FDSYNC)) {
zsd = >zv_zso->zso_dev;
zsd->zsd_sync_cnt++;
-   if (zsd->zsd_sync_cnt == 1)
+   if (zsd->zsd_sync_cnt == 1 &&
+   (zv->zv_flags & ZVOL_WRITTEN_TO) != 0)
zil_async_to_sync(zv->zv_zilog, ZVOL_OBJ);
}
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r365382 - head/usr.sbin/traceroute6

2020-09-06 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Sep  6 15:44:09 2020
New Revision: 365382
URL: https://svnweb.freebsd.org/changeset/base/365382

Log:
  Remove duplicated line.
  
  Reported by:  lwhsu

Modified:
  head/usr.sbin/traceroute6/Makefile

Modified: head/usr.sbin/traceroute6/Makefile
==
--- head/usr.sbin/traceroute6/Makefile  Sun Sep  6 14:41:35 2020
(r365381)
+++ head/usr.sbin/traceroute6/Makefile  Sun Sep  6 15:44:09 2020
(r365382)
@@ -15,8 +15,6 @@
 
 .include 
 
-.include 
-
 TRACEROUTE_DISTDIR?= ${SRCTOP}/contrib/traceroute
 .PATH: ${TRACEROUTE_DISTDIR}
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r365378 - head/usr.sbin/traceroute6

2020-09-06 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Sep  6 14:04:02 2020
New Revision: 365378
URL: https://svnweb.freebsd.org/changeset/base/365378

Log:
  traceroute6: capsicumize it
  
  Submitted by: Shubh Gupta 
  Sponsored by: Google (GSOC 2020)
  Differential Revision:https://reviews.freebsd.org/D25604

Modified:
  head/usr.sbin/traceroute6/Makefile
  head/usr.sbin/traceroute6/traceroute6.c

Modified: head/usr.sbin/traceroute6/Makefile
==
--- head/usr.sbin/traceroute6/Makefile  Sun Sep  6 11:29:06 2020
(r365377)
+++ head/usr.sbin/traceroute6/Makefile  Sun Sep  6 14:04:02 2020
(r365378)
@@ -13,6 +13,10 @@
 # A PARTICULAR PURPOSE.
 # $FreeBSD$
 
+.include 
+
+.include 
+
 TRACEROUTE_DISTDIR?= ${SRCTOP}/contrib/traceroute
 .PATH: ${TRACEROUTE_DISTDIR}
 
@@ -26,7 +30,13 @@ BINMODE= 4555
 CFLAGS+= -DIPSEC -DHAVE_POLL
 CFLAGS+= -I${.CURDIR} -I${TRACEROUTE_DISTDIR} -I.
 
-LIBADD=ipsec
+.if ${MK_CASPER} != "no"
+LIBADD+=   casper
+LIBADD+=   cap_dns
+CFLAGS+=   -DWITH_CASPER
+.endif
+
+LIBADD+=   ipsec
 
 .include 
 

Modified: head/usr.sbin/traceroute6/traceroute6.c
==
--- head/usr.sbin/traceroute6/traceroute6.c Sun Sep  6 11:29:06 2020
(r365377)
+++ head/usr.sbin/traceroute6/traceroute6.c Sun Sep  6 14:04:02 2020
(r365378)
@@ -249,6 +249,7 @@ static const char rcsid[] =
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -260,6 +261,10 @@ static const char rcsid[] =
 
 #include 
 
+#include 
+#include 
+#include 
+
 #include 
 #include 
 #include 
@@ -289,11 +294,6 @@ static const char rcsid[] =
 
 #defineMAXPACKET   65535   /* max ip packet size */
 
-#ifndef HAVE_GETIPNODEBYNAME
-#define getipnodebyname(x, y, z, u)gethostbyname2((x), (y))
-#define freehostent(x)
-#endif
-
 static u_char  packet[512];/* last inbound (icmp) packet */
 static char*outpacket; /* last output packet */
 
@@ -304,6 +304,7 @@ int setpolicy(int so, char *policy);
 #endif
 void   send_probe(int, u_long);
 void   *get_uphdr(struct ip6_hdr *, u_char *);
+void   capdns_open(void);
 intget_hoplim(struct msghdr *);
 double deltaT(struct timeval *, struct timeval *);
 const char *pr_type(int);
@@ -312,6 +313,8 @@ voidprint(struct msghdr *, int);
 const char *inetname(struct sockaddr *);
 u_int32_t sctp_crc32c(void *, u_int32_t);
 u_int16_t in_cksum(u_int16_t *addr, int);
+u_int16_t udp_cksum(struct sockaddr_in6 *, struct sockaddr_in6 *,
+void *, u_int32_t);
 u_int16_t tcp_chksum(struct sockaddr_in6 *, struct sockaddr_in6 *,
 void *, u_int32_t);
 void   usage(void);
@@ -335,6 +338,8 @@ static struct cmsghdr *cmsg;
 static char *source = NULL;
 static char *hostname;
 
+static cap_channel_t *capdns;
+
 static u_long nprobes = 3;
 static u_long first_hop = 1;
 static u_long max_hops = 30;
@@ -368,7 +373,10 @@ main(int argc, char *argv[])
char ipsec_inpolicy[] = "in bypass";
char ipsec_outpolicy[] = "out bypass";
 #endif
+   cap_rights_t rights;
 
+   capdns_open();
+
/*
 * Receive ICMP
 */
@@ -429,6 +437,7 @@ main(int argc, char *argv[])
}
break;
case 'g':
+   /* XXX use after capability mode is entered */
hp = getipnodebyname(optarg, AF_INET6, 0, _errno);
if (hp == NULL) {
fprintf(stderr,
@@ -560,8 +569,8 @@ main(int argc, char *argv[])
sndsock = rcvsock;
break;
case IPPROTO_UDP:
-   if ((sndsock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-   perror("socket(SOCK_DGRAM)");
+   if ((sndsock = socket(AF_INET6, SOCK_RAW, IPPROTO_UDP)) < 0) {
+   perror("socket(SOCK_RAW)");
exit(5);
}
break;
@@ -606,7 +615,9 @@ main(int argc, char *argv[])
hints.ai_socktype = SOCK_RAW;
hints.ai_protocol = IPPROTO_ICMPV6;
hints.ai_flags = AI_CANONNAME;
-   error = getaddrinfo(*argv, NULL, , );
+
+   error = cap_getaddrinfo(capdns, *argv, NULL, , );
+
if (error) {
fprintf(stderr,
"traceroute6: %s\n", gai_strerror(error));
@@ -624,7 +635,7 @@ main(int argc, char *argv[])
exit(1);
}
if (res->ai_next) {
-   if (getnameinfo(res->ai_addr, res->ai_addrlen, hbuf,
+   if (cap_getnameinfo(capdns, res->ai_addr, res->ai_addrlen, hbuf,
sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0)
strlcpy(hbuf, "?", sizeof(hbuf));
fprintf(stderr, "traceroute6: Warning: %s has multiple "
@@ -803,7 +814,7 @@ main(int argc, char *argv[])
hints.ai_family = 

svn commit: r364355 - in head: stand/efi/loader stand/i386/loader stand/libsa/zfs stand/lua sys/cddl/boot/zfs sys/cddl/contrib/opensolaris/uts/common/fs/zfs sys/cddl/contrib/opensolaris/uts/common/...

2020-08-18 Thread Mariusz Zaborski
Author: oshogbo
Date: Tue Aug 18 19:48:04 2020
New Revision: 364355
URL: https://svnweb.freebsd.org/changeset/base/364355

Log:
  zfs: add an option to the bootloader to rewind the ZFS checkpoint
  
  The checkpoints are another way of keeping the state of ZFS.
  During the rewind, the pool has to be exported.
  This makes checkpoints unusable when using ZFS as root.
  Add the option to rewind the ZFS checkpoint at the boot time.
  If checkpoint exists, a new option for rewinding a checkpoint will appear in
  the bootloader menu.
  We fully support boot environments.
  If the rewind option is selected, the boot loader will show a list of
  boot environments that existed before the checkpoint.
  
  Reviewed by:  tsoome, allanjude, kevans (ok with high-level overview)
  Differential Revision:https://reviews.freebsd.org/D24920

Modified:
  head/stand/efi/loader/main.c
  head/stand/i386/loader/main.c
  head/stand/libsa/zfs/libzfs.h
  head/stand/libsa/zfs/zfs.c
  head/stand/libsa/zfs/zfsimpl.c
  head/stand/lua/core.lua
  head/stand/lua/menu.lua
  head/sys/cddl/boot/zfs/zfsimpl.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c

Modified: head/stand/efi/loader/main.c
==
--- head/stand/efi/loader/main.cTue Aug 18 19:34:31 2020
(r364354)
+++ head/stand/efi/loader/main.cTue Aug 18 19:48:04 2020
(r364355)
@@ -269,7 +269,7 @@ probe_zfs_currdev(uint64_t guid)
currdev.root_guid = 0;
set_currdev_devdesc((struct devdesc *));
devname = efi_fmtdev();
-   init_zfs_bootenv(devname);
+   init_zfs_boot_options(devname);
 
rv = sanity_check_currdev();
if (rv) {

Modified: head/stand/i386/loader/main.c
==
--- head/stand/i386/loader/main.c   Tue Aug 18 19:34:31 2020
(r364354)
+++ head/stand/i386/loader/main.c   Tue Aug 18 19:48:04 2020
(r364355)
@@ -363,7 +363,7 @@ extract_currdev(void)
 
 #ifdef LOADER_ZFS_SUPPORT
if (new_currdev.dd.d_dev->dv_type == DEVT_ZFS)
-   init_zfs_bootenv(zfs_fmtdev(_currdev));
+   init_zfs_boot_options(zfs_fmtdev(_currdev));
 #endif
 
env_setenv("currdev", EV_VOLATILE, i386_fmtdev(_currdev),

Modified: head/stand/libsa/zfs/libzfs.h
==
--- head/stand/libsa/zfs/libzfs.h   Tue Aug 18 19:34:31 2020
(r364354)
+++ head/stand/libsa/zfs/libzfs.h   Tue Aug 18 19:48:04 2020
(r364355)
@@ -123,7 +123,7 @@ int zfs_nextboot(void *vdev, char *buf, size_t size);
 intzfs_probe_dev(const char *devname, uint64_t *pool_guid);
 intzfs_list(const char *name);
 uint64_t ldi_get_size(void *);
-void   init_zfs_bootenv(const char *currdev);
+void   init_zfs_boot_options(const char *currdev);
 intzfs_bootenv(const char *name);
 intzfs_belist_add(const char *name, uint64_t __unused);
 intzfs_set_env(void);

Modified: head/stand/libsa/zfs/zfs.c
==
--- head/stand/libsa/zfs/zfs.c  Tue Aug 18 19:34:31 2020(r364354)
+++ head/stand/libsa/zfs/zfs.c  Tue Aug 18 19:48:04 2020(r364355)
@@ -60,7 +60,10 @@ static off_t zfs_seek(struct open_file *f, off_t offse
 static int zfs_stat(struct open_file *f, struct stat *sb);
 static int zfs_readdir(struct open_file *f, struct dirent *d);
 
-static voidzfs_bootenv_initial(const char *);
+static voidzfs_bootenv_initial(const char *envname, spa_t *spa,
+   const char *name, const char *dsname, int checkpoint);
+static voidzfs_checkpoints_initial(spa_t *spa, const char *name,
+   const char *dsname);
 
 struct devsw zfs_dev;
 
@@ -1077,16 +1080,16 @@ zfs_fmtdev(void *vdev)
return (buf);
 }
 
-int
-zfs_list(const char *name)
+static int
+split_devname(const char *name, char *poolname, size_t size,
+const char **dsnamep)
 {
-   static char poolname[ZFS_MAXNAMELEN];
-   uint64_tobjid;
-   spa_t   *spa;
-   const char  *dsname;
-   int len;
-   int rv;
+   const char *dsname;
+   size_t len;
 
+   ASSERT(name != NULL);
+   ASSERT(poolname != NULL);
+
len = strlen(name);
dsname = strchr(name, '/');
if (dsname != NULL) {
@@ -1094,9 +1097,30 @@ zfs_list(const char *name)
dsname++;
} else
dsname = "";
-   memcpy(poolname, name, len);
-   poolname[len] = '\0';
 
+   if (len + 1 > size)
+   return (EINVAL);
+
+   strlcpy(poolname, name, len + 1);
+
+   if (dsnamep != NULL)
+   *dsnamep = dsname;
+
+   

svn commit: r364276 - in head: lib/libcasper/services lib/libcasper/services/cap_dns lib/libcasper/services/cap_net lib/libcasper/services/cap_net/tests share/mk

2020-08-16 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Aug 16 18:12:21 2020
New Revision: 364276
URL: https://svnweb.freebsd.org/changeset/base/364276

Log:
  libcasper: Introduce cap_net a network service for Casper.
  
  Reviewed by:  emaste, markj (previous version), bcr (man page)
  Differential Revision:https://reviews.freebsd.org/D24688

Added:
  head/lib/libcasper/services/cap_net/
  head/lib/libcasper/services/cap_net/Makefile   (contents, props changed)
  head/lib/libcasper/services/cap_net/cap_net.3   (contents, props changed)
  head/lib/libcasper/services/cap_net/cap_net.c   (contents, props changed)
  head/lib/libcasper/services/cap_net/cap_net.h   (contents, props changed)
  head/lib/libcasper/services/cap_net/tests/
  head/lib/libcasper/services/cap_net/tests/Makefile   (contents, props changed)
  head/lib/libcasper/services/cap_net/tests/net_test.c   (contents, props 
changed)
Modified:
  head/lib/libcasper/services/Makefile
  head/lib/libcasper/services/cap_dns/Makefile
  head/lib/libcasper/services/cap_dns/cap_dns.3
  head/share/mk/src.libnames.mk

Modified: head/lib/libcasper/services/Makefile
==
--- head/lib/libcasper/services/MakefileSun Aug 16 18:10:15 2020
(r364275)
+++ head/lib/libcasper/services/MakefileSun Aug 16 18:12:21 2020
(r364276)
@@ -5,6 +5,7 @@
 SUBDIR=cap_dns
 SUBDIR+=   cap_fileargs
 SUBDIR+=   cap_grp
+SUBDIR+=   cap_net
 SUBDIR+=   cap_pwd
 SUBDIR+=   cap_sysctl
 SUBDIR+=   cap_syslog

Modified: head/lib/libcasper/services/cap_dns/Makefile
==
--- head/lib/libcasper/services/cap_dns/MakefileSun Aug 16 18:10:15 
2020(r364275)
+++ head/lib/libcasper/services/cap_dns/MakefileSun Aug 16 18:12:21 
2020(r364276)
@@ -27,11 +27,6 @@ SUBDIR.${MK_TESTS}+= tests
 MAN+=  cap_dns.3
 
 MLINKS+=cap_dns.3 libcap_dns.3
-MLINKS+=cap_dns.3 cap_gethostbyname.3
-MLINKS+=cap_dns.3 cap_gethostbyname2.3
-MLINKS+=cap_dns.3 cap_gethostbyaddr.3
-MLINKS+=cap_dns.3 cap_getaddrinfo.3
-MLINKS+=cap_dns.3 cap_getnameinfo.3
 MLINKS+=cap_dns.3 cap_dns_type_limit.3
 MLINKS+=cap_dns.3 cap_dns_family_limit.3
 

Modified: head/lib/libcasper/services/cap_dns/cap_dns.3
==
--- head/lib/libcasper/services/cap_dns/cap_dns.3   Sun Aug 16 18:10:15 
2020(r364275)
+++ head/lib/libcasper/services/cap_dns/cap_dns.3   Sun Aug 16 18:12:21 
2020(r364276)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 5, 2020
+.Dd August 15, 2020
 .Dt CAP_DNS 3
 .Os
 .Sh NAME
@@ -58,6 +58,9 @@
 .Fn cap_dns_family_limit "const cap_channel_t *chan" "const int *families" 
"size_t nfamilies"
 .Sh DESCRIPTION
 .Bf -symbolic
+This service is obsolete and
+.Xr cap_net 3
+should be used instead.
 The
 .Fn cap_getaddrinfo ,
 and

Added: head/lib/libcasper/services/cap_net/Makefile
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/libcasper/services/cap_net/MakefileSun Aug 16 18:12:21 
2020(r364276)
@@ -0,0 +1,48 @@
+# $FreeBSD$
+
+SHLIBDIR?= /lib/casper
+
+.include 
+
+PACKAGE=libcasper
+
+SHLIB_MAJOR=   1
+INCSDIR?=  ${INCLUDEDIR}/casper
+
+.if ${MK_CASPER} != "no"
+SHLIB= cap_net
+
+SRCS=  cap_net.c
+.endif
+
+INCS=  cap_net.h
+
+LIBADD=nv
+
+CFLAGS+=-I${.CURDIR}
+CFLAGS+=-DWITH_CASPER
+
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
+
+MAN+=  cap_net.3
+
+MLINKS+=cap_net.3 libcap_net.3
+MLINKS+=cap_net.3 cap_bind.3
+MLINKS+=cap_net.3 cap_connect.3
+MLINKS+=cap_net.3 cap_net_free.3
+MLINKS+=cap_net.3 cap_net_limit.3
+MLINKS+=cap_net.3 cap_net_limit_addr2name.3
+MLINKS+=cap_net.3 cap_net_limit_addr2name_family.3
+MLINKS+=cap_net.3 cap_net_limit_bind.3
+MLINKS+=cap_net.3 cap_net_limit_connect.3
+MLINKS+=cap_net.3 cap_net_limit_init.3
+MLINKS+=cap_net.3 cap_net_limit_name2addr.3
+MLINKS+=cap_net.3 cap_net_limit_name2addr_family.3
+MLINKS+=cap_net.3 cap_getaddrinfo.3
+MLINKS+=cap_net.3 cap_gethostbyaddr.3
+MLINKS+=cap_net.3 cap_gethostbyname.3
+MLINKS+=cap_net.3 cap_gethostbyname2.3
+MLINKS+=cap_net.3 cap_getnameinfo.3
+
+.include 

Added: head/lib/libcasper/services/cap_net/cap_net.3
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/libcasper/services/cap_net/cap_net.3   Sun Aug 16 18:12:21 
2020    (r364276)
@@ -0,0 +1,287 @@
+.\" Copyright (c) 2020 Mariusz Zaborski 
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the

svn commit: r359808 - in head/cddl/contrib/opensolaris: cmd/zfs lib/libzfs/common

2020-04-11 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Apr 11 17:54:35 2020
New Revision: 359808
URL: https://svnweb.freebsd.org/changeset/base/359808

Log:
  zfs: Add option for forcible unmounting dataset while receiving snapshot.
  
  Currently when the dataset is in use we can't receive snapshots.
  
  zfs send test/1@asd | zfs recv -FM test/2
  cannot unmount '/test/2': Device busy
  
  This commits add option 'M' which attempts to forcibly unmount the
  dataset.  Thanks to this we can enforce receiving snapshots in a
  single step.
  
  Note that this functionality is not supported on Linux because the
  VFS will prevent active mounted filesystems from being unmounted,
  even with the force option.  This is the intended VFS behavior.
  
  Discussed-with: Pawel Jakub Dawidek 
  Reviewed-by: Ryan Moeller 
  Reviewed-by: Brian Behlendorf 
  Reviewed-by: Allan Jude 
  Differential Revision:https://reviews.freebsd.org/D22306
  
  openzfs/zfs@a57d3d45d6efdff935421e2ef3f97e3dc089d93d

Modified:
  head/cddl/contrib/opensolaris/cmd/zfs/zfs.8
  head/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
  head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h
  head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c

Modified: head/cddl/contrib/opensolaris/cmd/zfs/zfs.8
==
--- head/cddl/contrib/opensolaris/cmd/zfs/zfs.8 Sat Apr 11 17:30:33 2020
(r359807)
+++ head/cddl/contrib/opensolaris/cmd/zfs/zfs.8 Sat Apr 11 17:54:35 2020
(r359808)
@@ -32,7 +32,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd October 16, 2019
+.Dd February 16, 2020
 .Dt ZFS 8
 .Os
 .Sh NAME
@@ -201,12 +201,12 @@
 .Fl t Ar receive_resume_token
 .Nm
 .Cm receive Ns | Ns Cm recv
-.Op Fl vnsFu
+.Op Fl vnsFMu
 .Op Fl o Sy origin Ns = Ns Ar snapshot
 .Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot
 .Nm
 .Cm receive Ns | Ns Cm recv
-.Op Fl vnsFu
+.Op Fl vnsFMu
 .Op Fl d | e
 .Op Fl o Sy origin Ns = Ns Ar snapshot
 .Ar filesystem
@@ -2909,14 +2909,14 @@ for more details.
 .It Xo
 .Nm
 .Cm receive Ns | Ns Cm recv
-.Op Fl vnsFu
+.Op Fl vnsFMu
 .Op Fl o Sy origin Ns = Ns Ar snapshot
 .Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot
 .Xc
 .It Xo
 .Nm
 .Cm receive Ns | Ns Cm recv
-.Op Fl vnsFu
+.Op Fl vnsFMu
 .Op Fl d | e
 .Op Fl o Sy origin Ns = Ns Ar snapshot
 .Ar filesystem
@@ -3016,6 +3016,9 @@ performing the receive operation. If receiving an incr
 stream (for example, one generated by
 .Qq Nm Cm send Fl R Bro Fl i | Fl I Brc ) ,
 destroy snapshots and file systems that do not exist on the sending side.
+.It Fl M
+Force an unmount of the file system while receiving a snapshot.
+This option is not supported on Linux.
 .It Fl s
 If the receive is interrupted, save the partially received state, rather
 than deleting it.  Interruption may be due to premature termination of

Modified: head/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
==
--- head/cddl/contrib/opensolaris/cmd/zfs/zfs_main.cSat Apr 11 17:30:33 
2020(r359807)
+++ head/cddl/contrib/opensolaris/cmd/zfs/zfs_main.cSat Apr 11 17:54:35 
2020(r359808)
@@ -274,9 +274,9 @@ get_usage(zfs_help_t idx)
case HELP_PROMOTE:
return (gettext("\tpromote \n"));
case HELP_RECEIVE:
-   return (gettext("\treceive|recv [-vnsFu] \n"
-   "\treceive|recv [-vnsFu] [-o origin=] [-d | -e] "
+   "\treceive|recv [-vnsFMu] [-o origin=] [-d | -e] "
"\n"
"\treceive|recv -A \n"));
case HELP_RENAME:
@@ -4078,7 +4078,7 @@ zfs_do_receive(int argc, char **argv)
nomem();
 
/* check options */
-   while ((c = getopt(argc, argv, ":o:denuvFsA")) != -1) {
+   while ((c = getopt(argc, argv, ":o:denuvMFsA")) != -1) {
switch (c) {
case 'o':
if (parseprop(props, optarg) != 0)
@@ -4105,6 +4105,9 @@ zfs_do_receive(int argc, char **argv)
break;
case 'F':
flags.force = B_TRUE;
+   break;
+   case 'M':
+   flags.forceunmount = B_TRUE;
break;
case 'A':
abort_resumable = B_TRUE;

Modified: head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h
==
--- head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.hSat Apr 11 
17:30:33 2020(r359807)
+++ head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.hSat Apr 11 
17:54:35 2020(r359808)
@@ -737,6 +737,9 @@ typedef struct recvflags {
 
/* do not mount file systems as they are extracted (private) */
boolean_t nomount;
+
+   /* force unmount while recv snapshot (private) */
+   boolean_t forceunmount;
 } recvflags_t;
 
 extern 

svn commit: r359807 - head/sbin/decryptcore

2020-04-11 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Apr 11 17:30:33 2020
New Revision: 359807
URL: https://svnweb.freebsd.org/changeset/base/359807

Log:
  decryptcore: load the nls data
  
  Load the nls data before the openssl will try to do it in the
  capability mode.
  On my machine the sa_ossl_private_decrypt is trying to do that.
  
  MFC after:2 weeks

Modified:
  head/sbin/decryptcore/decryptcore.c

Modified: head/sbin/decryptcore/decryptcore.c
==
--- head/sbin/decryptcore/decryptcore.c Sat Apr 11 15:52:07 2020
(r359806)
+++ head/sbin/decryptcore/decryptcore.c Sat Apr 11 17:30:33 2020
(r359807)
@@ -170,6 +170,7 @@ decrypt(int ofd, const char *privkeyfile, const char *
goto failed;
}
 
+   caph_cache_catpages();
if (caph_enter() < 0) {
pjdlog_errno(LOG_ERR, "Unable to enter capability mode");
goto failed;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r359730 - head/usr.bin/logger

2020-04-08 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Apr  8 18:43:00 2020
New Revision: 359730
URL: https://svnweb.freebsd.org/changeset/base/359730

Log:
  logger: temporarily disable Capsicum when a host is provided
  
  We don't have a way to send a UDP package.
  
  PR:   245314
  Reported by:  dch
  Discussed with:   emaste

Modified:
  head/usr.bin/logger/logger.c

Modified: head/usr.bin/logger/logger.c
==
--- head/usr.bin/logger/logger.cWed Apr  8 17:55:45 2020
(r359729)
+++ head/usr.bin/logger/logger.cWed Apr  8 18:43:00 2020
(r359730)
@@ -181,8 +181,10 @@ main(int argc, char *argv[])
err(1, "Unable to contact Casper");
caph_cache_catpages();
caph_cache_tzdata();
-   if (caph_enter() < 0)
-   err(1, "Unable to enter capability mode");
+   if (nsock == 0) {
+   if (caph_enter() < 0)
+   err(1, "Unable to enter capability mode");
+   }
capsyslog = cap_service_open(capcas, "system.syslog");
if (capsyslog == NULL)
err(1, "Unable to open system.syslog service");
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r358919 - head/usr.bin/logger

2020-03-12 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Mar 12 19:55:51 2020
New Revision: 358919
URL: https://svnweb.freebsd.org/changeset/base/358919

Log:
  logger: capsicumize
  
  Submitted by: Tiger Gao 
  Sponsored by: The FreeBSD Foundation
  Differential Revision:https://reviews.freebsd.org/D23744

Modified:
  head/usr.bin/logger/Makefile
  head/usr.bin/logger/logger.c

Modified: head/usr.bin/logger/Makefile
==
--- head/usr.bin/logger/MakefileThu Mar 12 19:10:53 2020
(r358918)
+++ head/usr.bin/logger/MakefileThu Mar 12 19:55:51 2020
(r358919)
@@ -9,4 +9,10 @@ PROG=  logger
 CFLAGS+= -DINET6
 .endif
 
+.if ${MK_CASPER} != "no"
+LIBADD+=casper
+LIBADD+=cap_syslog
+CFLAGS+=-DWITH_CASPER
+.endif
+
 .include 

Modified: head/usr.bin/logger/logger.c
==
--- head/usr.bin/logger/logger.cThu Mar 12 19:10:53 2020
(r358918)
+++ head/usr.bin/logger/logger.cThu Mar 12 19:55:51 2020
(r358919)
@@ -44,10 +44,12 @@ static char sccsid[] = "@(#)logger.c8.1 (Berkeley) 
6/
 #include 
 __FBSDID("$FreeBSD$");
 
+#include 
 #include 
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -57,6 +59,9 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+#include 
+#include 
+
 #defineSYSLOG_NAMES
 #include 
 
@@ -76,6 +81,7 @@ static void   logmessage(int, const char *, const char *
struct socks *, ssize_t, const char *);
 static voidusage(void);
 
+static cap_channel_t *capsyslog;
 #ifdef INET6
 static int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */
 #else
@@ -92,12 +98,13 @@ static int send_to_all = 0; /* send message to all IPv
 int
 main(int argc, char *argv[])
 {
+   cap_channel_t *capcas;
struct socks *socks;
ssize_t nsock;
time_t now;
int ch, logflags, pri;
char *tag, *host, buf[1024], *timestamp, tbuf[26],
-   *hostname, hbuf[MAXHOSTNAMELEN];
+   *hostname, hbuf[MAXHOSTNAMELEN], *pristr;
const char *svcname, *src;
 
tag = NULL;
@@ -107,6 +114,7 @@ main(int argc, char *argv[])
src = NULL;
socks = NULL;
pri = LOG_USER | LOG_NOTICE;
+   pristr = NULL;
logflags = 0;
unsetenv("TZ");
while ((ch = getopt(argc, argv, "46Af:H:h:iP:p:S:st:")) != -1)
@@ -140,7 +148,7 @@ main(int argc, char *argv[])
svcname = optarg;
break;
case 'p':   /* priority */
-   pri = pencode(optarg);
+   pristr = optarg;
break;
case 's':   /* log to standard error */
logflags |= LOG_PERROR;
@@ -168,12 +176,25 @@ main(int argc, char *argv[])
nsock = 0;
}
 
+   capcas = cap_init();
+   if (capcas == NULL)
+   err(1, "Unable to contact Casper");
+   caph_cache_catpages();
+   caph_cache_tzdata();
+   if (caph_enter() < 0)
+   err(1, "Unable to enter capability mode");
+   capsyslog = cap_service_open(capcas, "system.syslog");
+   if (capsyslog == NULL)
+   err(1, "Unable to open system.syslog service");
+   cap_close(capcas);
+
+   if (pristr != NULL)
+   pri = pencode(pristr);
if (tag == NULL)
tag = getlogin();
/* setup for logging */
if (host == NULL)
-   openlog(tag, logflags, 0);
-   (void) fclose(stdout);
+   cap_openlog(capsyslog, tag, logflags, 0);
 
(void )time();
(void )ctime_r(, tbuf);
@@ -349,7 +370,7 @@ logmessage(int pri, const char *timestamp, const char 
int len, i, lsent;
 
if (nsock == 0) {
-   syslog(pri, "%s", buf);
+   cap_syslog(capsyslog, pri, "%s", buf);
return;
}
if ((len = asprintf(, "<%d>%s %s %s: %s", pri, timestamp,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r356928 - head/tools/build/mk

2020-01-20 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Jan 20 19:56:22 2020
New Revision: 356928
URL: https://svnweb.freebsd.org/changeset/base/356928

Log:
  When MK_CASPER=no is set remove files which are not needed to run system.
  
  PR:   242971

Modified:
  head/tools/build/mk/OptionalObsoleteFiles.inc

Modified: head/tools/build/mk/OptionalObsoleteFiles.inc
==
--- head/tools/build/mk/OptionalObsoleteFiles.inc   Mon Jan 20 19:52:23 
2020(r356927)
+++ head/tools/build/mk/OptionalObsoleteFiles.inc   Mon Jan 20 19:56:22 
2020(r356928)
@@ -1141,6 +1141,15 @@ OLD_DIRS+=usr/tests/usr.bin/calendar
 .endif
 
 .if ${MK_CASPER} == no
+OLD_LIBS+=lib/libcasper.so.1
+OLD_LIBS+=lib/casper/libcap_dns.so.2
+OLD_LIBS+=lib/casper/libcap_fileargs.so.1
+OLD_LIBS+=lib/casper/libcap_grp.so.1
+OLD_LIBS+=lib/casper/libcap_net.so.1
+OLD_LIBS+=lib/casper/libcap_pwd.so.1
+OLD_LIBS+=lib/casper/libcap_sysctl.so.1
+OLD_LIBS+=lib/casper/libcap_sysctl.so.2
+OLD_LIBS+=lib/casper/libcap_syslog.so.1
 .endif
 
 .if ${MK_CCD} == no
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r356926 - head/tools/build/mk

2020-01-20 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Jan 20 19:51:53 2020
New Revision: 356926
URL: https://svnweb.freebsd.org/changeset/base/356926

Log:
  Even when the MK_CASPER is set to "no" we still want to install man pages
  and the headers. If the user decides to install the system without Casper
  support, then the Casper functions are mocked, but they still exist in
  the system.
  
  PR:   242971
  MFC after:2 weeks

Modified:
  head/tools/build/mk/OptionalObsoleteFiles.inc

Modified: head/tools/build/mk/OptionalObsoleteFiles.inc
==
--- head/tools/build/mk/OptionalObsoleteFiles.inc   Mon Jan 20 19:47:58 
2020(r356925)
+++ head/tools/build/mk/OptionalObsoleteFiles.inc   Mon Jan 20 19:51:53 
2020(r356926)
@@ -1141,19 +1141,6 @@ OLD_DIRS+=usr/tests/usr.bin/calendar
 .endif
 
 .if ${MK_CASPER} == no
-OLD_FILES+=usr/include/libcasper.h
-OLD_FILES+=usr/share/man/man3/cap_clone.3.gz
-OLD_FILES+=usr/share/man/man3/cap_close.3.gz
-OLD_FILES+=usr/share/man/man3/cap_init.3.gz
-OLD_FILES+=usr/share/man/man3/cap_limit_get.3.gz
-OLD_FILES+=usr/share/man/man3/cap_limit_set.3.gz
-OLD_FILES+=usr/share/man/man3/cap_recv_nvlist.3.gz
-OLD_FILES+=usr/share/man/man3/cap_send_nvlist.3.gz
-OLD_FILES+=usr/share/man/man3/cap_service_open.3.gz
-OLD_FILES+=usr/share/man/man3/cap_sock.3.gz
-OLD_FILES+=usr/share/man/man3/cap_unwrap.3.gz
-OLD_FILES+=usr/share/man/man3/cap_wrap.3.gz
-OLD_FILES+=usr/share/man/man3/cap_xfer_nvlist.3.gz
 .endif
 
 .if ${MK_CCD} == no
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r356925 - head/tools/build/mk

2020-01-20 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Jan 20 19:47:58 2020
New Revision: 356925
URL: https://svnweb.freebsd.org/changeset/base/356925

Log:
  Those files are already removed in ObsoleteFiles.\
  There is no need to remove them twice.
  
  PR:   242971
  MFC after:2 weeks

Modified:
  head/tools/build/mk/OptionalObsoleteFiles.inc

Modified: head/tools/build/mk/OptionalObsoleteFiles.inc
==
--- head/tools/build/mk/OptionalObsoleteFiles.inc   Mon Jan 20 19:38:29 
2020(r356924)
+++ head/tools/build/mk/OptionalObsoleteFiles.inc   Mon Jan 20 19:47:58 
2020(r356925)
@@ -1141,44 +1141,7 @@ OLD_DIRS+=usr/tests/usr.bin/calendar
 .endif
 
 .if ${MK_CASPER} == no
-OLD_FILES+=etc/casper/system.dns
-OLD_FILES+=etc/casper/system.grp
-OLD_FILES+=etc/casper/system.pwd
-OLD_FILES+=etc/casper/system.random
-OLD_FILES+=etc/casper/system.sysctl
-OLD_DIRS+=etc/casper
-OLD_FILES+=etc/rc.d/casperd
-OLD_LIBS+=lib/libcapsicum.so.0
-OLD_LIBS+=lib/libcasper.so.0
-OLD_FILES+=libexec/casper/dns
-OLD_FILES+=libexec/casper/grp
-OLD_FILES+=libexec/casper/pwd
-OLD_FILES+=libexec/casper/random
-OLD_FILES+=libexec/casper/sysctl
-OLD_FILES+=sbin/casper
-OLD_FILES+=sbin/casperd
-OLD_FILES+=usr/include/libcapsicum.h
-OLD_FILES+=usr/include/libcapsicum_dns.h
-OLD_FILES+=usr/include/libcapsicum_grp.h
-OLD_FILES+=usr/include/libcapsicum_pwd.h
-OLD_FILES+=usr/include/libcapsicum_random.h
-OLD_FILES+=usr/include/libcapsicum_service.h
-OLD_FILES+=usr/include/libcapsicum_sysctl.h
 OLD_FILES+=usr/include/libcasper.h
-OLD_FILES+=usr/lib/libcapsicum.a
-OLD_FILES+=usr/lib/libcapsicum.so
-OLD_FILES+=usr/lib/libcapsicum_p.a
-OLD_FILES+=usr/lib/libcasper.a
-OLD_FILES+=usr/lib/libcasper.so
-OLD_FILES+=usr/lib/libcasper_p.a
-OLD_FILES+=usr/lib32/libcapsicum.a
-OLD_FILES+=usr/lib32/libcapsicum.so
-OLD_LIBS+=usr/lib32/libcapsicum.so.0
-OLD_FILES+=usr/lib32/libcapsicum_p.a
-OLD_FILES+=usr/lib32/libcasper.a
-OLD_FILES+=usr/lib32/libcasper.so
-OLD_LIBS+=usr/lib32/libcasper.so.0
-OLD_FILES+=usr/lib32/libcasper_p.a
 OLD_FILES+=usr/share/man/man3/cap_clone.3.gz
 OLD_FILES+=usr/share/man/man3/cap_close.3.gz
 OLD_FILES+=usr/share/man/man3/cap_init.3.gz
@@ -1191,8 +1154,6 @@ OLD_FILES+=usr/share/man/man3/cap_sock.3.gz
 OLD_FILES+=usr/share/man/man3/cap_unwrap.3.gz
 OLD_FILES+=usr/share/man/man3/cap_wrap.3.gz
 OLD_FILES+=usr/share/man/man3/cap_xfer_nvlist.3.gz
-OLD_FILES+=usr/share/man/man3/libcapsicum.3.gz
-OLD_FILES+=usr/share/man/man8/casperd.8.gz
 .endif
 
 .if ${MK_CCD} == no
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r356176 - in head: lib/geom/nop sys/geom/nop

2019-12-29 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Dec 29 15:47:37 2019
New Revision: 356176
URL: https://svnweb.freebsd.org/changeset/base/356176

Log:
  gnop: change the "count until fail" option
  
  Change the "count_until_fail" option of gnop, now it enables the failing
  rating instead of setting them to 100%.
  
  The original patch introduced the new flag, which sets the fail/rate to 100%
  after N requests. In some cases, we don't want to have 100% of failure
  probabilities. We want to start failing at some point.
  For example, on the early stage, we may like to allow some read/writes 
requests
  before having some requests delayed - when we try to mount the partition,
  or when we are trying to import the pool.
  Another case may be to check how scrub in ZFS will behave on different stages.
  
  This allows us to cover more cases.
  The previous behavior still may be configured.
  
  Reviewed by:  kib
  Differential Revision:https://reviews.freebsd.org/D22632

Modified:
  head/lib/geom/nop/gnop.8
  head/sys/geom/nop/g_nop.c

Modified: head/lib/geom/nop/gnop.8
==
--- head/lib/geom/nop/gnop.8Sun Dec 29 15:46:59 2019(r356175)
+++ head/lib/geom/nop/gnop.8Sun Dec 29 15:47:37 2019(r356176)
@@ -123,8 +123,8 @@ See
 Additional options:
 .Bl -tag -width "-c count_until_fail"
 .It Fl c Ar count_until_fail
-Specifies the number of I/O requests to allow before setting the read and write
-failure probabilities to 100%.
+Specifies the number of I/O requests to allow before setting the read, write 
and
+delay failure probabilities.
 .It Fl d Ar delaymsec
 Specifies the delay of the requests in milliseconds.
 Note that requests will be delayed before they are sent to the backing device.

Modified: head/sys/geom/nop/g_nop.c
==
--- head/sys/geom/nop/g_nop.c   Sun Dec 29 15:46:59 2019(r356175)
+++ head/sys/geom/nop/g_nop.c   Sun Dec 29 15:47:37 2019(r356176)
@@ -204,31 +204,35 @@ g_nop_start(struct bio *bp)
struct bio *cbp;
u_int failprob, delayprob, delaytime;
 
-   failprob = delayprob = 0;
+   failprob = delayprob = delaytime = 0;
 
gp = bp->bio_to->geom;
sc = gp->softc;
 
G_NOP_LOGREQ(bp, "Request received.");
mtx_lock(>sc_lock);
-   if (sc->sc_count_until_fail != 0 && --sc->sc_count_until_fail == 0) {
-   sc->sc_rfailprob = 100;
-   sc->sc_wfailprob = 100;
-   }
switch (bp->bio_cmd) {
case BIO_READ:
sc->sc_reads++;
sc->sc_readbytes += bp->bio_length;
-   failprob = sc->sc_rfailprob;
-   delayprob = sc->sc_rdelayprob;
-   delaytime = sc->sc_delaymsec;
+   if (sc->sc_count_until_fail != 0) {
+   sc->sc_count_until_fail -= 1;
+   } else {
+   failprob = sc->sc_rfailprob;
+   delayprob = sc->sc_rdelayprob;
+   delaytime = sc->sc_delaymsec;
+   }
break;
case BIO_WRITE:
sc->sc_writes++;
sc->sc_wrotebytes += bp->bio_length;
-   failprob = sc->sc_wfailprob;
-   delayprob = sc->sc_wdelayprob;
-   delaytime = sc->sc_delaymsec;
+   if (sc->sc_count_until_fail != 0) {
+   sc->sc_count_until_fail -= 1;
+   } else {
+   failprob = sc->sc_wfailprob;
+   delayprob = sc->sc_wdelayprob;
+   delaytime = sc->sc_delaymsec;
+   }
break;
case BIO_DELETE:
sc->sc_deletes++;
@@ -262,6 +266,7 @@ g_nop_start(struct bio *bp)
break;
}
mtx_unlock(>sc_lock);
+
if (failprob > 0) {
u_int rval;
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r356174 - in head: lib/geom/nop sys/geom/nop

2019-12-29 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Dec 29 15:40:02 2019
New Revision: 356174
URL: https://svnweb.freebsd.org/changeset/base/356174

Log:
  gnop: allow to change the name of created device
  
  Thanks to this option we can create more then one gnop provider from
  single provider. This may be useful for temporary labeling some data
  on the disk.
  
  Reviewed by:  markj, allanjude, bcr
  Differential Revision:https://reviews.freebsd.org/D22304

Modified:
  head/lib/geom/nop/geom_nop.c
  head/lib/geom/nop/gnop.8
  head/sys/geom/nop/g_nop.c

Modified: head/lib/geom/nop/geom_nop.c
==
--- head/lib/geom/nop/geom_nop.cSun Dec 29 15:39:43 2019
(r356173)
+++ head/lib/geom/nop/geom_nop.cSun Dec 29 15:40:02 2019
(r356174)
@@ -56,12 +56,13 @@ struct g_command class_commands[] = {
{ 'w', "wfailprob", "-1", G_TYPE_NUMBER },
{ 'x', "wdelayprob", "-1", G_TYPE_NUMBER },
{ 'z', "physpath", G_NOP_PHYSPATH_PASSTHROUGH, G_TYPE_STRING },
+   { 'Z', "gnopname", G_VAL_OPTIONAL, G_TYPE_STRING },
G_OPT_SENTINEL
},
"[-v] [-c count_until_fail] [-d delaymsec] [-e error] [-o offset] "
"[-p stripesize] [-P stripeoffset] [-q rdelayprob] [-r rfailprob] "
"[-s size]  [-S secsize] [-w wfailprob] [-x wdelayprob] "
-   "[-z physpath] dev ..."
+   "[-z physpath] [-Z gnopname] dev ..."
},
{ "configure", G_FLAG_VERBOSE, NULL,
{

Modified: head/lib/geom/nop/gnop.8
==
--- head/lib/geom/nop/gnop.8Sun Dec 29 15:39:43 2019(r356173)
+++ head/lib/geom/nop/gnop.8Sun Dec 29 15:40:02 2019(r356174)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 13, 2019
+.Dd December 29, 2019
 .Dt GNOP 8
 .Os
 .Sh NAME
@@ -47,6 +47,7 @@
 .Op Fl w Ar wfailprob
 .Op Fl x Ar wdelayprob
 .Op Fl z Ar physpath
+.Op Fl Z Ar gnopname
 .Ar dev ...
 .Nm
 .Cm configure
@@ -153,6 +154,11 @@ Be more verbose.
 Specifies write delay probability in percent.
 .It Fl z Ar physpath
 Physical path of the transparent provider.
+.It Fl Z Ar gnopname
+The name of the new provider.
+The suffix
+.Dq .nop
+will be appended to the provider name.
 .El
 .Sh SYSCTL VARIABLES
 The following

Modified: head/sys/geom/nop/g_nop.c
==
--- head/sys/geom/nop/g_nop.c   Sun Dec 29 15:39:43 2019(r356173)
+++ head/sys/geom/nop/g_nop.c   Sun Dec 29 15:40:02 2019(r356174)
@@ -2,6 +2,7 @@
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
  * Copyright (c) 2004-2006 Pawel Jakub Dawidek 
+ * Copyright (c) 2019 Mariusz Zaborski 
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,6 +31,7 @@
 __FBSDID("$FreeBSD$");
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -81,6 +83,20 @@ struct g_nop_delay {
TAILQ_ENTRY(g_nop_delay) dl_next;
 };
 
+static bool
+g_nop_verify_nprefix(const char *name)
+{
+   int i;
+
+   for (i = 0; i < strlen(name); i++) {
+   if (isalpha(name[i]) == 0 && isdigit(name[i]) == 0) {
+   return (false);
+   }
+   }
+
+   return (true);
+}
+
 static void
 g_nop_orphan(struct g_consumer *cp)
 {
@@ -312,17 +328,17 @@ g_nop_access(struct g_provider *pp, int dr, int dw, in
 
 static int
 g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
-int ioerror, u_int count_until_fail, u_int rfailprob, u_int wfailprob,
-u_int delaymsec, u_int rdelayprob, u_int wdelayprob, off_t offset,
-off_t size, u_int secsize, off_t stripesize, off_t stripeoffset,
-const char *physpath)
+const char *gnopname, int ioerror, u_int count_until_fail,
+u_int rfailprob, u_int wfailprob, u_int delaymsec, u_int rdelayprob,
+u_int wdelayprob, off_t offset, off_t size, u_int secsize, off_t 
stripesize,
+off_t stripeoffset, const char *physpath)
 {
struct g_nop_softc *sc;
struct g_geom *gp;
struct g_provider *newpp;
struct g_consumer *cp;
char name[64];
-   int error;
+   int error, n;
off_t explicitsize;
 
g_topology_assert();
@@ -373,7 +389,22 @@ g_nop_create(struct gctl_req *req, struct g_class *mp,
gctl_error(req, "stripeoffset is too big.");
return (EINVAL);
}
-   snprintf(name, sizeof(name), "%s%s", pp->name, G_NOP_SUFFIX);
+   if (gnopname != NULL && !g_nop_verify_nprefix(gnopname)) {
+   gctl_error(req, "Name %s is invalid.", gnopnam

Re: svn commit: r355097 - in head: sys/kern tests/sys/kern

2019-12-08 Thread Mariusz Zaborski
On Mon, 2 Dec 2019 at 18:55, John Baldwin  wrote:
>
> On 11/25/19 10:33 AM, Mariusz Zaborski wrote:
> > Author: oshogbo
> > Date: Mon Nov 25 18:33:21 2019
> > New Revision: 355097
> > URL: https://svnweb.freebsd.org/changeset/base/355097
> >
> > Log:
> >   procdesc: allow to collect status through wait(1) if process is traced
> >
> >   The debugger like truss(1) depends on the wait(2) syscall. This syscall
> >   waits for ALL children. When it is waiting for ALL child's the children
> >   created by process descriptors are not returned. This behavior was
> >   introduced because we want to implement libraries which may pdfork(1).
> >
> >   The behavior of process descriptor brakes truss(1) because it will
> >   not be able to collect the status of processes with process descriptors.
> >
> >   To address this problem the status is returned to parent when the
> >   child is traced. While the process is traced the debugger is the new 
> > parent.
> >   In case the original parent and debugger are the same process it means the
> >   debugger explicitly used pdfork() to create the child. In that case the 
> > debugger
> >   should be using kqueue()/pdwait() instead of wait().
> >
> >   Add test case to verify that. The test case was implemented by markj@.
>
> Does this fix PR 201276?
>
> Also, what about PRs 220324 and 232679?
Unfortunately, only partially. I still looking at some issues.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r355097 - in head: sys/kern tests/sys/kern

2019-11-25 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Nov 25 18:33:21 2019
New Revision: 355097
URL: https://svnweb.freebsd.org/changeset/base/355097

Log:
  procdesc: allow to collect status through wait(1) if process is traced
  
  The debugger like truss(1) depends on the wait(2) syscall. This syscall
  waits for ALL children. When it is waiting for ALL child's the children
  created by process descriptors are not returned. This behavior was
  introduced because we want to implement libraries which may pdfork(1).
  
  The behavior of process descriptor brakes truss(1) because it will
  not be able to collect the status of processes with process descriptors.
  
  To address this problem the status is returned to parent when the
  child is traced. While the process is traced the debugger is the new parent.
  In case the original parent and debugger are the same process it means the
  debugger explicitly used pdfork() to create the child. In that case the 
debugger
  should be using kqueue()/pdwait() instead of wait().
  
  Add test case to verify that. The test case was implemented by markj@.
  
  Reviewed by:  kib, markj
  Discussed with:   jhb
  MFC after:1 month
  Differential Revision:https://reviews.freebsd.org/D20362

Modified:
  head/sys/kern/kern_exit.c
  head/sys/kern/sys_procdesc.c
  head/tests/sys/kern/ptrace_test.c

Modified: head/sys/kern/kern_exit.c
==
--- head/sys/kern/kern_exit.c   Mon Nov 25 18:27:02 2019(r355096)
+++ head/sys/kern/kern_exit.c   Mon Nov 25 18:33:21 2019(r355097)
@@ -993,11 +993,14 @@ proc_to_reap(struct thread *td, struct proc *p, idtype
 
switch (idtype) {
case P_ALL:
-   if (p->p_procdesc != NULL) {
-   PROC_UNLOCK(p);
-   return (0);
+   if (p->p_procdesc == NULL ||
+  (p->p_pptr == td->td_proc &&
+  (p->p_flag & P_TRACED) != 0)) {
+   break;
}
-   break;
+
+   PROC_UNLOCK(p);
+   return (0);
case P_PID:
if (p->p_pid != (pid_t)id) {
PROC_UNLOCK(p);

Modified: head/sys/kern/sys_procdesc.c
==
--- head/sys/kern/sys_procdesc.cMon Nov 25 18:27:02 2019
(r355096)
+++ head/sys/kern/sys_procdesc.cMon Nov 25 18:33:21 2019
(r355097)
@@ -60,7 +60,6 @@
  *
  * Open questions:
  *
- * - How to handle ptrace(2)?
  * - Will we want to add a pidtoprocdesc(2) system call to allow process
  *   descriptors to be created for processes without pdfork(2)?
  */

Modified: head/tests/sys/kern/ptrace_test.c
==
--- head/tests/sys/kern/ptrace_test.c   Mon Nov 25 18:27:02 2019
(r355096)
+++ head/tests/sys/kern/ptrace_test.c   Mon Nov 25 18:33:21 2019
(r355097)
@@ -4135,6 +4135,105 @@ ATF_TC_BODY(ptrace__proc_reparent, tc)
ATF_REQUIRE(errno == ECHILD);
 }
 
+/*
+ * Ensure that traced processes created with pdfork(2) are visible to
+ * waitid(P_ALL).
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__procdesc_wait_child);
+ATF_TC_BODY(ptrace__procdesc_wait_child, tc)
+{
+   pid_t child, wpid;
+   int pd, status;
+
+   child = pdfork(, 0);
+   ATF_REQUIRE(child >= 0);
+
+   if (child == 0) {
+   trace_me();
+   (void)raise(SIGSTOP);
+   exit(0);
+   }
+
+   wpid = waitpid(child, , 0);
+   ATF_REQUIRE(wpid == child);
+   ATF_REQUIRE(WIFSTOPPED(status));
+   ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+
+   ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
+
+   wpid = wait();
+   ATF_REQUIRE(wpid == child);
+   ATF_REQUIRE(WIFSTOPPED(status));
+   ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+
+   ATF_REQUIRE(ptrace(PT_CONTINUE, child, (caddr_t)1, 0) != -1);
+
+   /*
+* If process was created by pdfork, the return code have to
+* be collected through process descriptor.
+*/
+   wpid = wait();
+   ATF_REQUIRE(wpid == -1);
+   ATF_REQUIRE(errno == ECHILD);
+
+   ATF_REQUIRE(close(pd) != -1);
+}
+
+/*
+ * Ensure that traced processes created with pdfork(2) are not visible
+ * after returning to parent - waitid(P_ALL).
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__procdesc_reparent_wait_child);
+ATF_TC_BODY(ptrace__procdesc_reparent_wait_child, tc)
+{
+   pid_t traced, debuger, wpid;
+   int pd, status;
+
+   traced = pdfork(, 0);
+   ATF_REQUIRE(traced >= 0);
+   if (traced == 0) {
+   raise(SIGSTOP);
+   exit(0);
+   }
+   ATF_REQUIRE(pd >= 0);
+
+   debuger = fork();
+   ATF_REQUIRE(debuger >= 0);
+   if (debuger == 0) {
+   /* The traced process is reparented to debuger. */
+   

Re: svn commit: r352312 - in head: lib/geom/nop sys/geom/nop

2019-11-09 Thread Mariusz Zaborski
Hello Chuck :)

I wonder if we shouldn't change this option a bit.
Shouldn't we have an option which says more like:

```
Specifies the number of I/O requests to allow before
setting the read and write failure rate.
```

In some cases, I don't want to have 100% of failure probabilities,
but on the early stage, I would like to allow some read/writes requests.
If the options would only specify the amount of the requests not
the failure probabilities could be used in other cases?

Those that make sens?
Mariusz

On Thu, 3 Oct 2019 at 00:08, Chuck Silvers  wrote:
>
> On Wed, Oct 02, 2019 at 08:11:57AM -0600, Alan Somers wrote:
> > On Fri, Sep 13, 2019 at 5:04 PM Chuck Silvers  wrote:
> >
> > > Author: chs
> > > Date: Fri Sep 13 23:03:56 2019
> > > New Revision: 352312
> > > URL: https://svnweb.freebsd.org/changeset/base/352312
> > >
> > > Log:
> > >   Add a "count_until_fail" option to gnop, which says to start failing
> > >   I/O requests after the given number have been allowed though.
> > >
> > >   Approved by:imp (mentor)
> > >   Reviewed by:rpokala kib 0mp mckusick
> > >   Sponsored by:   Netflix
> > >   Differential Revision:  https://reviews.freebsd.org/D21593
> > >
> > > Modified:
> > >   head/lib/geom/nop/geom_nop.c
> > >   head/lib/geom/nop/gnop.8
> > >   head/sys/geom/nop/g_nop.c
> > >   head/sys/geom/nop/g_nop.h
> > >
> >
> > This patch introduces a backwards-compatibility bug.  On a system with a
> > post-352312 kernel but a pre-352312 userland, the gnop command will always
> > fail with the error "gnop: Missing count_until_fail argument".
> > -Alan
>
> Thanks for pointing this out, I'll see about fixing it right away.
>
> -Chuck
> ___
> svn-src-head@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/svn-src-head
> To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r353107 - head/sys/cddl/dev/dtrace/amd64

2019-10-04 Thread Mariusz Zaborski
Author: oshogbo
Date: Fri Oct  4 16:17:00 2019
New Revision: 353107
URL: https://svnweb.freebsd.org/changeset/base/353107

Log:
  dtrace: 64-bits registers support
  
  The registers in ilumos and FreeBSD have a different number.
  In the illumos, last 32-bits register defined is SS an in FreeBSD is GS.
  While translating register we should comper it to the highest one.
  
  PR: 240358
  Reported by:lwhsu@
  MFC after:  2 weeks

Modified:
  head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c

Modified: head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c
==
--- head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c Fri Oct  4 15:27:10 2019
(r353106)
+++ head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c Fri Oct  4 16:17:00 2019
(r353107)
@@ -505,7 +505,11 @@ dtrace_getreg(struct trapframe *rp, uint_t reg)
REG_SS  /* 18 SS */
};
 
+#ifdef illumos
if (reg <= SS) {
+#else  /* !illumos */
+   if (reg <= GS) {
+#endif
if (reg >= sizeof (regmap) / sizeof (int)) {
DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
return (0);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r352186 - head/lib/geom/nop

2019-09-10 Thread Mariusz Zaborski
Author: oshogbo
Date: Tue Sep 10 20:27:44 2019
New Revision: 352186
URL: https://svnweb.freebsd.org/changeset/base/352186

Log:
  gnop: Fix initial value for the wdelayprob
  
  Reported by:  Chuck Silvers 

Modified:
  head/lib/geom/nop/geom_nop.c

Modified: head/lib/geom/nop/geom_nop.c
==
--- head/lib/geom/nop/geom_nop.cTue Sep 10 20:21:47 2019
(r352185)
+++ head/lib/geom/nop/geom_nop.cTue Sep 10 20:27:44 2019
(r352186)
@@ -53,7 +53,7 @@ struct g_command class_commands[] = {
{ 's', "size", "0", G_TYPE_NUMBER },
{ 'S', "secsize", "0", G_TYPE_NUMBER },
{ 'w', "wfailprob", "-1", G_TYPE_NUMBER },
-   { 'x', "wdelayprob", "1", G_TYPE_NUMBER },
+   { 'x', "wdelayprob", "-1", G_TYPE_NUMBER },
{ 'z', "physpath", G_NOP_PHYSPATH_PASSTHROUGH, G_TYPE_STRING },
G_OPT_SENTINEL
},
@@ -68,7 +68,7 @@ struct g_command class_commands[] = {
{ 'q', "rdelayprob", "-1", G_TYPE_NUMBER },
{ 'r', "rfailprob", "-1", G_TYPE_NUMBER },
{ 'w', "wfailprob", "-1", G_TYPE_NUMBER },
-   { 'x', "wdelayprob", "1", G_TYPE_NUMBER },
+   { 'x', "wdelayprob", "-1", G_TYPE_NUMBER },
G_OPT_SENTINEL
},
"[-v] [-d delaymsec] [-e error] [-q rdelayprob] [-r rfailprob] "
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r346322 - head/lib/libcasper/services/cap_fileargs

2019-09-03 Thread Mariusz Zaborski
On Wed, Apr 17, 2019 at 04:58:38PM +, Adrian Chadd wrote:
> Author: adrian
> Date: Wed Apr 17 16:58:38 2019
> New Revision: 346322
> URL: https://svnweb.freebsd.org/changeset/base/346322
> 
> Log:
>   [casper] fix compilation when casper is disabled.
>   
>   This triggers an error in gcc-mips 6.4.0 complaining about unused arguments.
>   
>   Tested:
>   
>   * compiled/run on mips32; nothing complained.
> 
> Modified:
>   head/lib/libcasper/services/cap_fileargs/cap_fileargs.h
> 
> Modified: head/lib/libcasper/services/cap_fileargs/cap_fileargs.h
> ==
> --- head/lib/libcasper/services/cap_fileargs/cap_fileargs.h   Wed Apr 17 
> 16:45:42 2019(r346321)
> +++ head/lib/libcasper/services/cap_fileargs/cap_fileargs.h   Wed Apr 17 
> 16:58:38 2019(r346322)
> @@ -108,8 +108,12 @@ fileargs_cinitnv(cap_channel_t *cas __unused, nvlist_t
>   lstat(name, sb)
>  #define  fileargs_open(fa, name) 
> \
>   open(name, fa->fa_flags, fa->fa_mode)
> -#define  fileargs_fopen(fa, name, mode)  
> \
> - fopen(name, mode)
> +static inline
> +FILE *fileargs_fopen(fileargs_t *fa, const char *name, const char *mode)
> +{
> + (void) fa;
__unused is not good enough?
> + return (fopen(name, mode));
> +}
>  #define  fileargs_free(fa)   (free(fa))
>  #endif
>  
> 

-- 
Mariusz Zaborski
oshogbo//vx | http://oshogbo.vexillium.org
FreeBSD committer   | https://freebsd.org
Software developer  | http://wheelsystems.com
If it's not broken, let's fix it till it is!!1


signature.asc
Description: PGP signature


svn commit: r346263 - head/contrib/tcpdump

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Tue Apr 16 04:12:41 2019
New Revision: 346263
URL: https://svnweb.freebsd.org/changeset/base/346263

Log:
  tcpdump: disable Capsicum if -E option is provided.
  
  The -E is used to provide a secret for decrypting IPsec.
  The secret may be provided through command line or as the file.
  The problem is that tcpdump doesn't support yet opening files in capability 
mode
  and the file may contain a list of the files to open.
  
  As a workaround, for now, let's just disable capsicum if the -E
  the option is provided.
  
  PR:   236819
  MFC after:2 weeks

Modified:
  head/contrib/tcpdump/tcpdump.c

Modified: head/contrib/tcpdump/tcpdump.c
==
--- head/contrib/tcpdump/tcpdump.c  Tue Apr 16 02:48:04 2019
(r346262)
+++ head/contrib/tcpdump/tcpdump.c  Tue Apr 16 04:12:41 2019
(r346263)
@@ -2063,7 +2063,8 @@ main(int argc, char **argv)
}
 
 #ifdef HAVE_CAPSICUM
-   cansandbox = (VFileName == NULL && zflag == NULL);
+   cansandbox = (VFileName == NULL && zflag == NULL &&
+   ndo->ndo_espsecret == NULL);
 #ifdef HAVE_CASPER
cansandbox = (cansandbox && (ndo->ndo_nflag || capdns != NULL));
 #else


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


Re: svn commit: r345875 - in head: contrib/elftoolchain/strings usr.bin/strings

2019-09-03 Thread Mariusz Zaborski
On Sun, Apr 14, 2019 at 08:19:22AM -0700, Adrian Chadd wrote:
> This exposed a fun bug - gcc mips 6.4.0 complains about an unused arg (fa)
> in fileargs_fopen() in the strings change when you compile without casper
> support. I do that on mips.
> 
> I have a local change that converts the #define to an inline function so
> the unused arg can be (void)'ed away. Mind if I commit it?
Sounds good to me.
Although you don't have an issue with others services?

-- 
Mariusz Zaborski
oshogbo//vx | http://oshogbo.vexillium.org
FreeBSD committer   | https://freebsd.org
Software developer  | http://wheelsystems.com
If it's not broken, let's fix it till it is!!1

> 
> On Thu, 4 Apr 2019 at 09:32, Mariusz Zaborski  wrote:
> 
> > Author: oshogbo
> > Date: Thu Apr  4 16:32:27 2019
> > New Revision: 345875
> > URL: https://svnweb.freebsd.org/changeset/base/345875
> >
> > Log:
> >   strings: capsicumize it
> >
> >   Reviewed by:  cem
> >   Discussed with: emaste
> >   Differential Revision:https://reviews.freebsd.org/D18038
> >
> > Modified:
> >   head/contrib/elftoolchain/strings/strings.c
> >   head/usr.bin/strings/Makefile
> >
> > Modified: head/contrib/elftoolchain/strings/strings.c
> >
> > ==
> > --- head/contrib/elftoolchain/strings/strings.c Thu Apr  4 12:02:48 2019
> >   (r345874)
> > +++ head/contrib/elftoolchain/strings/strings.c Thu Apr  4 16:32:27 2019
> >   (r345875)
> > @@ -25,8 +25,10 @@
> >   */
> >
> >  #include 
> > +#include 
> >  #include 
> >
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -44,6 +46,9 @@
> >  #include 
> >  #include 
> >
> > +#include 
> > +#include 
> > +
> >  #include "_elftc.h"
> >
> >  ELFTC_VCSID("$Id: strings.c 3648 2018-11-22 23:26:43Z emaste $");
> > @@ -85,7 +90,7 @@ static struct option strings_longopts[] = {
> >  };
> >
> >  intgetcharacter(FILE *, long *);
> > -inthandle_file(const char *);
> > +inthandle_file(fileargs_t *fa, const char *);
> >  inthandle_elf(const char *, FILE *);
> >  inthandle_binary(const char *, FILE *, size_t);
> >  intfind_strings(const char *, FILE *, off_t, off_t);
> > @@ -99,6 +104,8 @@ void usage(void);
> >  int
> >  main(int argc, char **argv)
> >  {
> > +   fileargs_t *fa;
> > +   cap_rights_t rights;
> > int ch, rc;
> >
> > rc = 0;
> > @@ -187,27 +194,41 @@ main(int argc, char **argv)
> > argc -= optind;
> > argv += optind;
> >
> > +   cap_rights_init(, CAP_READ, CAP_SEEK, CAP_FSTAT, CAP_FCNTL);
> > +   fa = fileargs_init(argc, argv, O_RDONLY, 0, );
> > +   if (fa == NULL)
> > +   err(1, "Unable to initialize casper fileargs");
> > +
> > +   caph_cache_catpages();
> > +   if (caph_limit_stdio() < 0 && caph_enter_casper() < 0) {
> > +   fileargs_free(fa);
> > +   err(1, "Unable to enter capability mode");
> > +   }
> > +
> > if (min_len == 0)
> > min_len = 4;
> > if (*argv == NULL)
> > rc = find_strings("{standard input}", stdin, 0, 0);
> > else while (*argv != NULL) {
> > -   if (handle_file(*argv) != 0)
> > +   if (handle_file(fa, *argv) != 0)
> > rc = 1;
> > argv++;
> > }
> > +
> > +   fileargs_free(fa);
> > +
> > return (rc);
> >  }
> >
> >  int
> > -handle_file(const char *name)
> > +handle_file(fileargs_t *fa, const char *name)
> >  {
> > FILE *pfile;
> > int rt;
> >
> > if (name == NULL)
> > return (1);
> > -   pfile = fopen(name, "rb");
> > +   pfile = fileargs_fopen(fa, name, "rb");
> > if (pfile == NULL) {
> > warnx("'%s': %s", name, strerror(errno));
> > return (1);
> >
> > Modified: head/usr.bin/strings/Makefile
> >
> > ==
> > --- head/usr.bin/strings/Makefile   Thu Apr  4 12:02:48 2019
> > (r345874)
> > +++ head/usr.bin/strings/Makefile   Thu Apr  4 16:32:27 2019
> > (r345875)
> > @@ -10,6 +10,12 @@ PROG=strings
> >
> >  LIBADD=elftc elf
> >
> > +.if ${MK_CASPER} != "no" && !defined(BOOTSTRAPPING)
> > +LIBADD+=   casper
> > +LIBADD+=   cap_fileargs
> > +CFLAGS+=   -DWITH_CASPER
> > +.endif
> > +
> >  CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
> >
> >  .include 
> >
> >


signature.asc
Description: PGP signature


svn commit: r346219 - head/lib/libnv/tests

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Apr 15 03:32:01 2019
New Revision: 346219
URL: https://svnweb.freebsd.org/changeset/base/346219

Log:
  libnv: extend the tests
  
  Add cases for sending file descriptors.
  
  Submitted by: Mindaugas Rasiukevicius 
  MFC after:2 weeks

Modified:
  head/lib/libnv/tests/nvlist_send_recv_test.c

Modified: head/lib/libnv/tests/nvlist_send_recv_test.c
==
--- head/lib/libnv/tests/nvlist_send_recv_test.cMon Apr 15 03:31:02 
2019(r346218)
+++ head/lib/libnv/tests/nvlist_send_recv_test.cMon Apr 15 03:32:01 
2019(r346219)
@@ -34,6 +34,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -58,6 +59,7 @@ child(int sock)
 {
nvlist_t *nvl;
nvlist_t *empty;
+   int pfd[2];
 
nvl = nvlist_create(0);
empty = nvlist_create(0);
@@ -73,7 +75,16 @@ child(int sock)
nvlist_add_string(nvl, "nvlist/string/", "");
nvlist_add_string(nvl, "nvlist/string/x", "x");
nvlist_add_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz", 
"abcdefghijklmnopqrstuvwxyz");
+
nvlist_add_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", 
STDERR_FILENO);
+   if (pipe(pfd) == -1)
+   err(EXIT_FAILURE, "pipe");
+   if (write(pfd[1], "test", 4) != 4)
+   err(EXIT_FAILURE, "write");
+   close(pfd[1]);
+   nvlist_add_descriptor(nvl, "nvlist/descriptor/pipe_rd", pfd[0]);
+   close(pfd[0]);
+
nvlist_add_binary(nvl, "nvlist/binary/x", "x", 1);
nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", 
"abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz"));
nvlist_move_nvlist(nvl, "nvlist/nvlist/empty", empty);
@@ -91,8 +102,9 @@ parent(int sock)
const nvlist_t *cnvl, *empty;
const char *name, *cname;
void *cookie, *ccookie;
-   int type, ctype;
+   int type, ctype, fd;
size_t size;
+   char buf[4];
 
nvl = nvlist_recv(sock, 0);
CHECK(nvlist_error(nvl) == 0);
@@ -175,6 +187,15 @@ parent(int sock)
 
name = nvlist_next(nvl, , );
CHECK(name != NULL);
+   CHECK(type == NV_TYPE_DESCRIPTOR);
+   CHECK(strcmp(name, "nvlist/descriptor/pipe_rd") == 0);
+   fd = nvlist_get_descriptor(nvl, name);
+   CHECK(fd_is_valid(fd));
+   CHECK(read(fd, buf, sizeof(buf)) == 4);
+   CHECK(strncmp(buf, "test", sizeof(buf)) == 0);
+
+   name = nvlist_next(nvl, , );
+   CHECK(name != NULL);
CHECK(type == NV_TYPE_BINARY);
CHECK(strcmp(name, "nvlist/binary/x") == 0);
CHECK(memcmp(nvlist_get_binary(nvl, name, NULL), "x", 1) == 0);
@@ -278,6 +299,12 @@ parent(int sock)
 
cname = nvlist_next(cnvl, , );
CHECK(cname != NULL);
+   CHECK(ctype == NV_TYPE_DESCRIPTOR);
+   CHECK(strcmp(cname, "nvlist/descriptor/pipe_rd") == 0);
+   CHECK(fd_is_valid(nvlist_get_descriptor(cnvl, cname)));
+
+   cname = nvlist_next(cnvl, , );
+   CHECK(cname != NULL);
CHECK(ctype == NV_TYPE_BINARY);
CHECK(strcmp(cname, "nvlist/binary/x") == 0);
CHECK(memcmp(nvlist_get_binary(cnvl, cname, NULL), "x", 1) == 0);
@@ -359,7 +386,7 @@ int
 main(void)
 {
 
-   printf("1..136\n");
+   printf("1..146\n");
fflush(stdout);
 
send_nvlist();


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


svn commit: r346218 - head/lib/libnv

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Apr 15 03:31:02 2019
New Revision: 346218
URL: https://svnweb.freebsd.org/changeset/base/346218

Log:
  libnv: add support for nvlist_send()/nvlist_recv() on Linux
  
  This may be useful for cross build in the feature.
  
  Submitted by: Mindaugas Rasiukevicius 
  MFC after:2 weeks

Modified:
  head/lib/libnv/msgio.c

Modified: head/lib/libnv/msgio.c
==
--- head/lib/libnv/msgio.c  Mon Apr 15 01:27:15 2019(r346217)
+++ head/lib/libnv/msgio.c  Mon Apr 15 03:31:02 2019(r346218)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -58,7 +59,12 @@ __FBSDID("$FreeBSD$");
 #definePJDLOG_ABORT(...)   abort()
 #endif
 
+#ifdef __linux__
+/* Linux: arbitrary size, but must be lower than SCM_MAX_FD. */
+#definePKG_MAX_SIZE((64U - 1) * CMSG_SPACE(sizeof(int)))
+#else
 #definePKG_MAX_SIZE(MCLBYTES / CMSG_SPACE(sizeof(int)) - 1)
+#endif
 
 static int
 msghdr_add_fd(struct cmsghdr *cmsg, int fd)
@@ -74,31 +80,6 @@ msghdr_add_fd(struct cmsghdr *cmsg, int fd)
return (0);
 }
 
-static int
-msghdr_get_fd(struct cmsghdr *cmsg)
-{
-   int fd;
-
-   if (cmsg == NULL || cmsg->cmsg_level != SOL_SOCKET ||
-   cmsg->cmsg_type != SCM_RIGHTS ||
-   cmsg->cmsg_len != CMSG_LEN(sizeof(fd))) {
-   errno = EINVAL;
-   return (-1);
-   }
-
-   bcopy(CMSG_DATA(cmsg), , sizeof(fd));
-#ifndef MSG_CMSG_CLOEXEC
-   /*
-* If the MSG_CMSG_CLOEXEC flag is not available we cannot set the
-* close-on-exec flag atomically, but we still want to set it for
-* consistency.
-*/
-   (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
-#endif
-
-   return (fd);
-}
-
 static void
 fd_wait(int fd, bool doread)
 {
@@ -157,14 +138,7 @@ msg_send(int sock, const struct msghdr *msg)
return (0);
 }
 
-/*
- * MacOS/Linux do not define struct cmsgcred but we need to bootstrap libnv
- * when building on non-FreeBSD systems. Since they are not used during
- * bootstrap we can just omit these two functions there.
- */
-#ifndef __FreeBSD__
-#warning "cred_send() not supported on non-FreeBSD systems"
-#else
+#ifdef __FreeBSD__
 int
 cred_send(int sock)
 {
@@ -326,29 +300,53 @@ fd_package_recv(int sock, int *fds, size_t nfds)
if (msg_recv(sock, ) == -1)
goto end;
 
-   for (i = 0, cmsg = CMSG_FIRSTHDR(); i < nfds && cmsg != NULL;
-   i++, cmsg = CMSG_NXTHDR(, cmsg)) {
-   fds[i] = msghdr_get_fd(cmsg);
-   if (fds[i] < 0)
+   i = 0;
+   cmsg = CMSG_FIRSTHDR();
+   while (cmsg && i < nfds) {
+   unsigned int n;
+
+   if (cmsg->cmsg_level != SOL_SOCKET ||
+   cmsg->cmsg_type != SCM_RIGHTS) {
+   errno = EINVAL;
break;
+   }
+   n = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
+   if (i + n > nfds) {
+   errno = EINVAL;
+   break;
+   }
+   bcopy(CMSG_DATA(cmsg), fds + i, sizeof(int) * n);
+   cmsg = CMSG_NXTHDR(, cmsg);
+   i += n;
}
 
if (cmsg != NULL || i < nfds) {
-   int fd;
+   unsigned int last;
 
/*
 * We need to close all received descriptors, even if we have
 * different control message (eg. SCM_CREDS) in between.
 */
-   for (cmsg = CMSG_FIRSTHDR(); cmsg != NULL;
-   cmsg = CMSG_NXTHDR(, cmsg)) {
-   fd = msghdr_get_fd(cmsg);
-   if (fd >= 0)
-   close(fd);
+   last = i;
+   for (i = 0; i < last; i++) {
+   if (fds[i] >= 0) {
+   close(fds[i]);
+   }
}
errno = EINVAL;
goto end;
}
+
+#ifndef MSG_CMSG_CLOEXEC
+   /*
+* If the MSG_CMSG_CLOEXEC flag is not available we cannot set the
+* close-on-exec flag atomically, but we still want to set it for
+* consistency.
+*/
+   for (i = 0; i < nfds; i++) {
+   (void) fcntl(fds[i], F_SETFD, FD_CLOEXEC);
+   }
+#endif
 
ret = 0;
 end:


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


svn commit: r346115 - head/sys/contrib/libnv

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr 11 04:24:41 2019
New Revision: 346115
URL: https://svnweb.freebsd.org/changeset/base/346115

Log:
  The nvlist_report_missing is also used by the cnvlist.
  It can't be a static one.
  
  Reported by:  jenkins
  MFC after:2 weeks

Modified:
  head/sys/contrib/libnv/nvlist.c

Modified: head/sys/contrib/libnv/nvlist.c
==
--- head/sys/contrib/libnv/nvlist.c Thu Apr 11 04:22:06 2019
(r346114)
+++ head/sys/contrib/libnv/nvlist.c Thu Apr 11 04:24:41 2019
(r346115)
@@ -324,7 +324,7 @@ nvlist_set_flags(nvlist_t *nvl, int flags)
nvl->nvl_flags = flags;
 }
 
-static void
+void
 nvlist_report_missing(int type, const char *name)
 {
 


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


svn commit: r346112 - head/sys/contrib/libnv

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr 11 03:47:53 2019
New Revision: 346112
URL: https://svnweb.freebsd.org/changeset/base/346112

Log:
  libnv: fix compilation warnings
  
  When building libnv without a debug those arguments are no longer used
  because assertions will be changed to NOP.
  
  Submitted by: Mindaugas Rasiukevicius 
  MFC after:2 weeks

Modified:
  head/sys/contrib/libnv/nvlist.c

Modified: head/sys/contrib/libnv/nvlist.c
==
--- head/sys/contrib/libnv/nvlist.c Thu Apr 11 00:41:07 2019
(r346111)
+++ head/sys/contrib/libnv/nvlist.c Thu Apr 11 03:47:53 2019
(r346112)
@@ -324,7 +324,7 @@ nvlist_set_flags(nvlist_t *nvl, int flags)
nvl->nvl_flags = flags;
 }
 
-void
+static void
 nvlist_report_missing(int type, const char *name)
 {
 
@@ -1374,7 +1374,7 @@ nvlist_first_nvpair(const nvlist_t *nvl)
 }
 
 nvpair_t *
-nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
+nvlist_next_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
 {
nvpair_t *retnvp;
 
@@ -1390,7 +1390,7 @@ nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t
 }
 
 nvpair_t *
-nvlist_prev_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
+nvlist_prev_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
 {
nvpair_t *retnvp;
 


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


svn commit: r346113 - head/sys/contrib/libnv

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr 11 04:21:58 2019
New Revision: 346113
URL: https://svnweb.freebsd.org/changeset/base/346113

Log:
  libnv: fix compilation warnings
  
  When building libnv without a debug those arguments are no longer used
  because assertions will be changed to NOP.
  
  Submitted by: Mindaugas Rasiukevicius 
  MFC after:2 weeks

Modified:
  head/sys/contrib/libnv/nvpair.c

Modified: head/sys/contrib/libnv/nvpair.c
==
--- head/sys/contrib/libnv/nvpair.c Thu Apr 11 03:47:53 2019
(r346112)
+++ head/sys/contrib/libnv/nvpair.c Thu Apr 11 04:21:58 2019
(r346113)
@@ -108,7 +108,7 @@ struct nvpair_header {
 
 
 void
-nvpair_assert(const nvpair_t *nvp)
+nvpair_assert(const nvpair_t *nvp __unused)
 {
 
NVPAIR_ASSERT(nvp);
@@ -235,7 +235,8 @@ nvpair_remove_nvlist_array(nvpair_t *nvp)
 }
 
 void
-nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl)
+nvpair_remove(struct nvl_head *head, nvpair_t *nvp,
+const nvlist_t *nvl __unused)
 {
 
NVPAIR_ASSERT(nvp);
@@ -359,7 +360,7 @@ nvpair_pack_header(const nvpair_t *nvp, unsigned char 
 }
 
 unsigned char *
-nvpair_pack_null(const nvpair_t *nvp, unsigned char *ptr,
+nvpair_pack_null(const nvpair_t *nvp __unused, unsigned char *ptr,
 size_t *leftp __unused)
 {
 


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


svn commit: r346023 - head/usr.bin/strings

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Apr  8 03:35:47 2019
New Revision: 346023
URL: https://svnweb.freebsd.org/changeset/base/346023

Log:
  strings: disable Casper support while building native-xtools
  
  Reported by:  Charlie Li
  Tested by:Charlie Li

Modified:
  head/usr.bin/strings/Makefile

Modified: head/usr.bin/strings/Makefile
==
--- head/usr.bin/strings/Makefile   Sun Apr  7 21:01:02 2019
(r346022)
+++ head/usr.bin/strings/Makefile   Mon Apr  8 03:35:47 2019
(r346023)
@@ -10,7 +10,7 @@ PROG= strings
 
 LIBADD=elftc elf
 
-.if ${MK_CASPER} != "no" && !defined(BOOTSTRAPPING)
+.if ${MK_CASPER} != "no" && !defined(BOOTSTRAPPING) && !defined(NXB_TARGET)
 LIBADD+=   casper
 LIBADD+=   cap_fileargs
 CFLAGS+=   -DWITH_CASPER


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


svn commit: r346029 - head/sys/kern

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Apr  8 14:23:52 2019
New Revision: 346029
URL: https://svnweb.freebsd.org/changeset/base/346029

Log:
  In the unlinkat syscall, the operation is performed on the directory
  descriptor, not the file descriptor. The file descriptor is used only for
  verification so do not expect any additional capabilities on it.
  
  Reported by:  antoine
  Tested by:antoine
  Discussed with:   kib, emaste, bapt
  Sponsored by: Fudo Security

Modified:
  head/sys/kern/vfs_syscalls.c

Modified: head/sys/kern/vfs_syscalls.c
==
--- head/sys/kern/vfs_syscalls.cMon Apr  8 13:40:46 2019
(r346028)
+++ head/sys/kern/vfs_syscalls.cMon Apr  8 14:23:52 2019
(r346029)
@@ -1809,13 +1809,11 @@ kern_funlinkat(struct thread *td, int dfd, const char 
struct vnode *vp;
struct nameidata nd;
struct stat sb;
-   cap_rights_t rights;
int error;
 
fp = NULL;
if (fd != FD_NONE) {
-   error = getvnode(td, fd, cap_rights_init(, CAP_LOOKUP),
-   );
+   error = getvnode(td, fd, _no_rights, );
if (error != 0)
return (error);
}


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


Re: svn commit: r345982 - in head: include lib/libc/sys sys/cddl/compat/opensolaris/sys sys/compat/cloudabi sys/compat/freebsd32 sys/compat/linux sys/kern sys/sys sys/ufs/ffs

2019-09-03 Thread Mariusz Zaborski
In the https://wiki.freebsd.org/AddingSyscalls we mentions that we need to bump
__FreeBSD_version. I confirmed that with Warner. So this was my mistake.

Thanks Shawn.
-- 
Mariusz Zaborski
oshogbo//vx | http://oshogbo.vexillium.org
FreeBSD committer   | https://freebsd.org
Software developer  | http://wheelsystems.com
If it's not broken, let's fix it till it is!!1

On Sun, Apr 07, 2019 at 08:35:07AM -0700, Cy Schubert wrote:
> In message <201904071510.x37fa7tm050...@gndrsh.dnsmgr.net>, "Rodney W. 
> Grimes"
> writes:
> > > On April 7, 2019 7:11:52 AM PDT, Shawn Webb  
> > > wr
> > ote:
> > > >On Sat, Apr 06, 2019 at 09:34:26AM +, Mariusz Zaborski wrote:
> > > >> Author: oshogbo
> > > >> Date: Sat Apr  6 09:34:26 2019
> > > >> New Revision: 345982
> > > >> URL: https://svnweb.freebsd.org/changeset/base/345982
> > > >> 
> > > >> Log:
> > > >>   Introduce funlinkat syscall that always us to check if we are
> > > >removing
> > > >>   the file associated with the given file descriptor.
> > > >>   
> > > >>   Reviewed by: kib, asomers
> > > >>   Reviewed by: cem, jilles, brooks (they reviewed previous version)
> > > >>   Discussed with:  pjd, and many others
> > > >>   Differential Revision:   https://reviews.freebsd.org/D14567
> > > >
> > > >Hey Mariusz,
> > > >
> > > >Is __FreeBSD_version supposed to be bumped after adding new syscalls?
> > > >I can't remember off-hand.
> > > >
> > > >Thanks,
> > > 
> > > I don't think so. Why force the rebuild of all ports through poudriere 
> > > over
> >  something that would never affect any of them?
> >
> > So that you can if version >= foo to know it is safe to use the new syscal?
> > Or if version  < foo you must use the old way.
> 
> Granted. However we do need something to avoid gratuitous rebuilds of 
> ports.
> 
> Personally, my poudriere script adjusts the pkg version 
> ($JAILPATH/data/packages/${JAIL}-${PORTS}/.building/.jailversion) with 
> that of the jail version (reported by poudriere jail -i -j $JAIL), 
> rebuilding all ports when I (the human) determines when the machine 
> should rebuild all ports with -c.
> 
> In that regard FreeBSD version bumps occasionally seem a little 
> gratuitous. Using the same indicator to tell whether software should be 
> able to use a new feature and when ports build infrastructure should 
> summarily delete all packages forcing a rebuild of absolutely 
> everything is probably not the best.
> 
> Just throwing out an idea, what if poudriere considers the first N 
> bytes of __FreeBSD_version significant? Having said that, looking at 
> __FreeBSD_version, I don't think we have enough digits to do what I was 
> planning on suggesting. But, you get the idea of what I'm driving at. 
> Maybe a new macro such as __FreeBSD_ports that is incremented every 
> time a change that affects ports?
> 
> Anyhow, I'm not too terribly concerned as what I have (selfishly 
> speaking) works. But we may as a group might want to consider this at 
> some point to build some efficiency into the ports part of the equation.
> 
> 
> -- 
> Cheers,
> Cy Schubert 
> FreeBSD UNIX: Web:  http://www.FreeBSD.org
> 
>   The need of the many outweighs the greed of the few.
>  
> 


signature.asc
Description: PGP signature


svn commit: r346012 - head/sys/sys

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Apr  7 16:07:41 2019
New Revision: 346012
URL: https://svnweb.freebsd.org/changeset/base/346012

Log:
  Bump FreeBSD version after r345982.
  
  Reported by:  Shawn Webb 
  Discussed with: imp, cy, rgrimes

Modified:
  head/sys/sys/param.h

Modified: head/sys/sys/param.h
==
--- head/sys/sys/param.hSun Apr  7 14:30:17 2019(r346011)
+++ head/sys/sys/param.hSun Apr  7 16:07:41 2019(r346012)
@@ -60,7 +60,7 @@
  * in the range 5 to 9.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1300017  /* Master, propagated to newvers */
+#define __FreeBSD_version 1300018  /* Master, propagated to newvers */
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,


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


svn commit: r345983 - in head/sys: compat/freebsd32 kern sys

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Apr  6 09:37:10 2019
New Revision: 345983
URL: https://svnweb.freebsd.org/changeset/base/345983

Log:
  Regen after r345982.

Modified:
  head/sys/compat/freebsd32/freebsd32_syscall.h
  head/sys/compat/freebsd32/freebsd32_syscalls.c
  head/sys/compat/freebsd32/freebsd32_sysent.c
  head/sys/compat/freebsd32/freebsd32_systrace_args.c
  head/sys/kern/init_sysent.c
  head/sys/kern/syscalls.c
  head/sys/kern/systrace_args.c
  head/sys/sys/syscall.h
  head/sys/sys/syscall.mk
  head/sys/sys/sysproto.h

Modified: head/sys/compat/freebsd32/freebsd32_syscall.h
==
--- head/sys/compat/freebsd32/freebsd32_syscall.h   Sat Apr  6 09:34:26 
2019(r345982)
+++ head/sys/compat/freebsd32/freebsd32_syscall.h   Sat Apr  6 09:37:10 
2019(r345983)
@@ -494,4 +494,5 @@
 #defineFREEBSD32_SYS_fhlink565
 #defineFREEBSD32_SYS_fhlinkat  566
 #defineFREEBSD32_SYS_fhreadlink567
-#defineFREEBSD32_SYS_MAXSYSCALL568
+#defineFREEBSD32_SYS_funlinkat 568
+#defineFREEBSD32_SYS_MAXSYSCALL569

Modified: head/sys/compat/freebsd32/freebsd32_syscalls.c
==
--- head/sys/compat/freebsd32/freebsd32_syscalls.c  Sat Apr  6 09:34:26 
2019(r345982)
+++ head/sys/compat/freebsd32/freebsd32_syscalls.c  Sat Apr  6 09:37:10 
2019(r345983)
@@ -604,4 +604,5 @@ const char *freebsd32_syscallnames[] = {
"fhlink",   /* 565 = fhlink */
"fhlinkat", /* 566 = fhlinkat */
"fhreadlink",   /* 567 = fhreadlink */
+   "funlinkat",/* 568 = funlinkat */
 };

Modified: head/sys/compat/freebsd32/freebsd32_sysent.c
==
--- head/sys/compat/freebsd32/freebsd32_sysent.cSat Apr  6 09:34:26 
2019(r345982)
+++ head/sys/compat/freebsd32/freebsd32_sysent.cSat Apr  6 09:37:10 
2019(r345983)
@@ -651,4 +651,5 @@ struct sysent freebsd32_sysent[] = {
{ AS(fhlink_args), (sy_call_t *)sys_fhlink, AUE_NULL, NULL, 0, 0, 0, 
SY_THR_STATIC },   /* 565 = fhlink */
{ AS(fhlinkat_args), (sy_call_t *)sys_fhlinkat, AUE_NULL, NULL, 0, 0, 
0, SY_THR_STATIC },   /* 566 = fhlinkat */
{ AS(fhreadlink_args), (sy_call_t *)sys_fhreadlink, AUE_NULL, NULL, 0, 
0, 0, SY_THR_STATIC },   /* 567 = fhreadlink */
+   { AS(funlinkat_args), (sy_call_t *)sys_funlinkat, AUE_UNLINKAT, NULL, 
0, 0, SYF_CAPENABLED, SY_THR_STATIC },/* 568 = funlinkat */
 };

Modified: head/sys/compat/freebsd32/freebsd32_systrace_args.c
==
--- head/sys/compat/freebsd32/freebsd32_systrace_args.c Sat Apr  6 09:34:26 
2019(r345982)
+++ head/sys/compat/freebsd32/freebsd32_systrace_args.c Sat Apr  6 09:37:10 
2019(r345983)
@@ -3310,6 +3310,16 @@ systrace_args(int sysnum, void *params, uint64_t *uarg
*n_args = 3;
break;
}
+   /* funlinkat */
+   case 568: {
+   struct funlinkat_args *p = params;
+   iarg[0] = p->dfd; /* int */
+   uarg[1] = (intptr_t) p->path; /* const char * */
+   iarg[2] = p->fd; /* int */
+   iarg[3] = p->flag; /* int */
+   *n_args = 4;
+   break;
+   }
default:
*n_args = 0;
break;
@@ -8905,6 +8915,25 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *d
break;
};
break;
+   /* funlinkat */
+   case 568:
+   switch(ndx) {
+   case 0:
+   p = "int";
+   break;
+   case 1:
+   p = "userland const char *";
+   break;
+   case 2:
+   p = "int";
+   break;
+   case 3:
+   p = "int";
+   break;
+   default:
+   break;
+   };
+   break;
default:
break;
};
@@ -10771,6 +10800,11 @@ systrace_return_setargdesc(int sysnum, int ndx, char *
break;
/* fhreadlink */
case 567:
+   if (ndx == 0 || ndx == 1)
+   p = "int";
+   break;
+   /* funlinkat */
+   case 568:
if (ndx == 0 || ndx == 1)
p = "int";
break;

Modified: head/sys/kern/init_sysent.c
==
--- head/sys/kern/init_sysent.c Sat Apr  6 09:34:26 2019(r345982)
+++ head/sys/kern/init_sysent.c Sat Apr  6 

svn commit: r345984 - head/lib/libutil

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Apr  6 11:24:43 2019
New Revision: 345984
URL: https://svnweb.freebsd.org/changeset/base/345984

Log:
  Use funlinkat in pidfile to ensure we are removing the right file.

Modified:
  head/lib/libutil/pidfile.c

Modified: head/lib/libutil/pidfile.c
==
--- head/lib/libutil/pidfile.c  Sat Apr  6 09:37:10 2019(r345983)
+++ head/lib/libutil/pidfile.c  Sat Apr  6 11:24:43 2019(r345984)
@@ -293,8 +293,11 @@ _pidfile_remove(struct pidfh *pfh, int freeit)
return (-1);
}
 
-   if (unlinkat(pfh->pf_dirfd, pfh->pf_filename, 0) == -1)
+   if (funlinkat(pfh->pf_dirfd, pfh->pf_filename, pfh->pf_fd, 0) == -1) {
+   if (errno == EDEADLK)
+   return (-1);
error = errno;
+   }
if (close(pfh->pf_fd) == -1 && error == 0)
error = errno;
if (close(pfh->pf_dirfd) == -1 && error == 0)


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


svn commit: r345982 - in head: include lib/libc/sys sys/cddl/compat/opensolaris/sys sys/compat/cloudabi sys/compat/freebsd32 sys/compat/linux sys/kern sys/sys sys/ufs/ffs

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Apr  6 09:34:26 2019
New Revision: 345982
URL: https://svnweb.freebsd.org/changeset/base/345982

Log:
  Introduce funlinkat syscall that always us to check if we are removing
  the file associated with the given file descriptor.
  
  Reviewed by:  kib, asomers
  Reviewed by:  cem, jilles, brooks (they reviewed previous version)
  Discussed with:   pjd, and many others
  Differential Revision:https://reviews.freebsd.org/D14567

Modified:
  head/include/unistd.h
  head/lib/libc/sys/Makefile.inc
  head/lib/libc/sys/Symbol.map
  head/lib/libc/sys/unlink.2
  head/sys/cddl/compat/opensolaris/sys/vnode.h
  head/sys/compat/cloudabi/cloudabi_file.c
  head/sys/compat/freebsd32/syscalls.master
  head/sys/compat/linux/linux_file.c
  head/sys/kern/capabilities.conf
  head/sys/kern/syscalls.master
  head/sys/kern/vfs_mountroot.c
  head/sys/kern/vfs_syscalls.c
  head/sys/sys/fcntl.h
  head/sys/sys/syscallsubr.h
  head/sys/ufs/ffs/ffs_alloc.c

Modified: head/include/unistd.h
==
--- head/include/unistd.h   Sat Apr  6 09:00:06 2019(r345981)
+++ head/include/unistd.h   Sat Apr  6 09:34:26 2019(r345982)
@@ -585,6 +585,7 @@ off_t__syscall(quad_t, ...);
 int undelete(const char *);
 int unwhiteout(const char *);
 void   *valloc(size_t);/* obsoleted by malloc() */
+int funlinkat(int, const char *, int, int);
 
 #ifndef _OPTRESET_DECLARED
 #define_OPTRESET_DECLARED

Modified: head/lib/libc/sys/Makefile.inc
==
--- head/lib/libc/sys/Makefile.inc  Sat Apr  6 09:00:06 2019
(r345981)
+++ head/lib/libc/sys/Makefile.inc  Sat Apr  6 09:34:26 2019
(r345982)
@@ -485,6 +485,7 @@ MLINKS+=timer_settime.2 timer_getoverrun.2 \
 MLINKS+=thr_kill.2 thr_kill2.2
 MLINKS+=truncate.2 ftruncate.2
 MLINKS+=unlink.2 unlinkat.2
+MLINKS+=unlink.2 funlinkat.2
 MLINKS+=utimensat.2 futimens.2
 MLINKS+=utimes.2 futimes.2 \
utimes.2 futimesat.2 \

Modified: head/lib/libc/sys/Symbol.map
==
--- head/lib/libc/sys/Symbol.mapSat Apr  6 09:00:06 2019
(r345981)
+++ head/lib/libc/sys/Symbol.mapSat Apr  6 09:34:26 2019
(r345982)
@@ -406,6 +406,7 @@ FBSD_1.6 {
fhlinkat;
fhreadlink;
getfhat;
+   funlinkat;
 };
 
 FBSDprivate_1.0 {

Modified: head/lib/libc/sys/unlink.2
==
--- head/lib/libc/sys/unlink.2  Sat Apr  6 09:00:06 2019(r345981)
+++ head/lib/libc/sys/unlink.2  Sat Apr  6 09:34:26 2019(r345982)
@@ -28,7 +28,7 @@
 .\" @(#)unlink.2   8.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd November 11, 2018
+.Dd April 6, 2019
 .Dt UNLINK 2
 .Os
 .Sh NAME
@@ -42,7 +42,9 @@
 .Ft int
 .Fn unlink "const char *path"
 .Ft int
-.Fn unlinkat "int fd" "const char *path" "int flag"
+.Fn unlinkat "int dfd" "const char *path" "int flag"
+.Ft int
+.Fn funlinkat "int dfd" "const char *path" "int fd" "int flag"
 .Sh DESCRIPTION
 The
 .Fn unlink
@@ -74,7 +76,7 @@ except in the case where
 specifies a relative path.
 In this case the directory entry to be removed is determined
 relative to the directory associated with the file descriptor
-.Fa fd
+.Fa dfd
 instead of the current working directory.
 .Pp
 The values for
@@ -113,6 +115,26 @@ or
 respectively, depending on whether or not the
 .Dv AT_REMOVEDIR
 bit is set in flag.
+.Pp
+The
+.Fn funlinkat
+system call can be used to unlink an already-opened file, unless that
+file has been replaced since it was opened.
+It is equivalent to
+.Fn unlinkat
+in the case where
+.Fa path
+is already open as the file descriptor
+.Fa fd .
+Otherwise, the path will not be removed and an error will be returned.
+The
+.Fa fd
+can be set the
+.Dv FD_NONE .
+In that case
+.Fn funlinkat
+behaves exactly like
+.Fn unlinkat .
 .Sh RETURN VALUES
 .Rv -std unlink
 .Sh ERRORS
@@ -227,6 +249,15 @@ or the relative
 .Fa path
 escapes it.
 .El
+.Pp
+In addition to the errors returned by
+.Fn unlinkat ,
+.Fn funlinkat
+may fail if:
+.Bl -tag -width Er
+.It Bq Er EDEADLK
+The file descriptor is not associated with the path.
+.El
 .Sh SEE ALSO
 .Xr chflags 2 ,
 .Xr close 2 ,
@@ -246,6 +277,10 @@ The
 .Fn unlinkat
 system call appeared in
 .Fx 8.0 .
+The
+.Fn funlinkat
+system call appeared in
+.Fx 13.0 .
 .Pp
 The
 .Fn unlink

Modified: head/sys/cddl/compat/opensolaris/sys/vnode.h
==
--- head/sys/cddl/compat/opensolaris/sys/vnode.hSat Apr  6 09:00:06 
2019(r345981)
+++ head/sys/cddl/compat/opensolaris/sys/vnode.hSat Apr  6 09:34:26 
2019(r345982)
@@ -278,7 +278,8 @@ vn_remove(char *fnamep, enum uio_seg seg, enum rm dirf
ASSERT(seg == 

svn commit: r345875 - in head: contrib/elftoolchain/strings usr.bin/strings

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr  4 16:32:27 2019
New Revision: 345875
URL: https://svnweb.freebsd.org/changeset/base/345875

Log:
  strings: capsicumize it
  
  Reviewed by:  cem
  Discussed with: emaste
  Differential Revision:https://reviews.freebsd.org/D18038

Modified:
  head/contrib/elftoolchain/strings/strings.c
  head/usr.bin/strings/Makefile

Modified: head/contrib/elftoolchain/strings/strings.c
==
--- head/contrib/elftoolchain/strings/strings.c Thu Apr  4 12:02:48 2019
(r345874)
+++ head/contrib/elftoolchain/strings/strings.c Thu Apr  4 16:32:27 2019
(r345875)
@@ -25,8 +25,10 @@
  */
 
 #include 
+#include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -44,6 +46,9 @@
 #include 
 #include 
 
+#include 
+#include 
+
 #include "_elftc.h"
 
 ELFTC_VCSID("$Id: strings.c 3648 2018-11-22 23:26:43Z emaste $");
@@ -85,7 +90,7 @@ static struct option strings_longopts[] = {
 };
 
 intgetcharacter(FILE *, long *);
-inthandle_file(const char *);
+inthandle_file(fileargs_t *fa, const char *);
 inthandle_elf(const char *, FILE *);
 inthandle_binary(const char *, FILE *, size_t);
 intfind_strings(const char *, FILE *, off_t, off_t);
@@ -99,6 +104,8 @@ void usage(void);
 int
 main(int argc, char **argv)
 {
+   fileargs_t *fa;
+   cap_rights_t rights;
int ch, rc;
 
rc = 0;
@@ -187,27 +194,41 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
 
+   cap_rights_init(, CAP_READ, CAP_SEEK, CAP_FSTAT, CAP_FCNTL);
+   fa = fileargs_init(argc, argv, O_RDONLY, 0, );
+   if (fa == NULL)
+   err(1, "Unable to initialize casper fileargs");
+
+   caph_cache_catpages();
+   if (caph_limit_stdio() < 0 && caph_enter_casper() < 0) {
+   fileargs_free(fa);
+   err(1, "Unable to enter capability mode");
+   }
+
if (min_len == 0)
min_len = 4;
if (*argv == NULL)
rc = find_strings("{standard input}", stdin, 0, 0);
else while (*argv != NULL) {
-   if (handle_file(*argv) != 0)
+   if (handle_file(fa, *argv) != 0)
rc = 1;
argv++;
}
+
+   fileargs_free(fa);
+
return (rc);
 }
 
 int
-handle_file(const char *name)
+handle_file(fileargs_t *fa, const char *name)
 {
FILE *pfile;
int rt;
 
if (name == NULL)
return (1);
-   pfile = fopen(name, "rb");
+   pfile = fileargs_fopen(fa, name, "rb");
if (pfile == NULL) {
warnx("'%s': %s", name, strerror(errno));
return (1);

Modified: head/usr.bin/strings/Makefile
==
--- head/usr.bin/strings/Makefile   Thu Apr  4 12:02:48 2019
(r345874)
+++ head/usr.bin/strings/Makefile   Thu Apr  4 16:32:27 2019
(r345875)
@@ -10,6 +10,12 @@ PROG=strings
 
 LIBADD=elftc elf
 
+.if ${MK_CASPER} != "no" && !defined(BOOTSTRAPPING)
+LIBADD+=   casper
+LIBADD+=   cap_fileargs
+CFLAGS+=   -DWITH_CASPER
+.endif
+
 CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
 
 .include 


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


svn commit: r345870 - head/tools/build

2019-09-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr  4 04:14:20 2019
New Revision: 345870
URL: https://svnweb.freebsd.org/changeset/base/345870

Log:
  Add cap_fileargs.h to -legacy if needed.
  
  Reviewed by:  arichardson
  Differential Revision:https://reviews.freebsd.org/D19685

Modified:
  head/tools/build/Makefile

Modified: head/tools/build/Makefile
==
--- head/tools/build/Makefile   Thu Apr  4 02:08:36 2019(r345869)
+++ head/tools/build/Makefile   Thu Apr  4 04:14:20 2019(r345870)
@@ -4,10 +4,11 @@
 
 LIB=   egacy
 SRC=
-INCSGROUPS=INCS SYSINCS
+INCSGROUPS=INCS SYSINCS CASPERINC
 INCS=
 
 SYSINCSDIR=${INCLUDEDIR}/sys
+CASPERINCDIR=  ${INCLUDEDIR}/casper
 
 BOOTSTRAPPING?=0
 
@@ -58,6 +59,10 @@ INCS+=   capsicum_helpers.h
 INCS+= libcasper.h
 .endif
 
+.if !exists(/usr/include/casper/cap_fileargs.h)
+CASPERINC+=${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h
+.endif
+
 .if empty(SRCS)
 SRCS=  dummy.c
 .endif
@@ -116,7 +121,7 @@ host-symlinks:
 # and cross-tools stages. We do this here using mkdir since mtree may not exist
 # yet (this happens if we are crossbuilding from Linux/Mac).
 installdirs:
-.for _dir in bin usr/lib usr/include lib/geom lib/casper
+.for _dir in bin usr/lib usr/include usr/include/casper lib/geom lib/casper
mkdir -p "${DESTDIR}/${_dir}"
 .endfor
 # Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a


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


svn commit: r350695 - head/lib/libcasper/services/cap_fileargs

2019-08-07 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Aug  7 19:30:33 2019
New Revision: 350695
URL: https://svnweb.freebsd.org/changeset/base/350695

Log:
  cap_filergs: limit size of the file name
  
  The limit of the name in fileargs is twice the size of the MAXPATH.
  The nvlist will not add an element with the longer name.
  We can detect at this point that the path is too big, and simple return
  the same error as open(2) would.
  
  PR:   239700
  Reported by:  markj
  Tested by:markj
  MFC after:2 weeks

Modified:
  head/lib/libcasper/services/cap_fileargs/cap_fileargs.c

Modified: head/lib/libcasper/services/cap_fileargs/cap_fileargs.c
==
--- head/lib/libcasper/services/cap_fileargs/cap_fileargs.c Wed Aug  7 
19:28:35 2019(r350694)
+++ head/lib/libcasper/services/cap_fileargs/cap_fileargs.c Wed Aug  7 
19:30:33 2019(r350695)
@@ -185,6 +185,11 @@ fileargs_create_limit(int argc, const char * const *ar
nvlist_add_number(limits, "mode", (uint64_t)mode);
 
for (i = 0; i < argc; i++) {
+   if (strlen(argv[i]) >= MAXPATHLEN) {
+   nvlist_destroy(limits);
+   errno = ENAMETOOLONG;
+   return (NULL);
+   }
nvlist_add_null(limits, argv[i]);
}
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350617 - head/sys/kern

2019-08-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Aug  5 20:31:17 2019
New Revision: 350617
URL: https://svnweb.freebsd.org/changeset/base/350617

Log:
  procdesc: fix the function name
  
  I changed name of the function r350429 and forgot to update
  the r350612 patch.
  
  Reported by:  jenkins
  MFC after:1 month

Modified:
  head/sys/kern/sys_procdesc.c

Modified: head/sys/kern/sys_procdesc.c
==
--- head/sys/kern/sys_procdesc.cMon Aug  5 20:26:01 2019
(r350616)
+++ head/sys/kern/sys_procdesc.cMon Aug  5 20:31:17 2019
(r350617)
@@ -419,7 +419,7 @@ procdesc_close(struct file *fp, struct thread *td)
if ((p->p_flag & P_TRACED) == 0) {
proc_reparent(p, p->p_reaper, true);
} else {
-   clear_orphan(p);
+   proc_clear_orphan(p);
p->p_oppid = p->p_reaper->p_pid;
proc_add_orphan(p, p->p_reaper);
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350616 - head/sys/kern

2019-08-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Aug  5 20:26:01 2019
New Revision: 350616
URL: https://svnweb.freebsd.org/changeset/base/350616

Log:
  process: style
  
  We don't need to check if the parent is already set.
  This is done already in the proc_reparent.
  
  No functional behaviour changes intended.
  
  MFC after:1 month

Modified:
  head/sys/kern/sys_process.c

Modified: head/sys/kern/sys_process.c
==
--- head/sys/kern/sys_process.c Mon Aug  5 20:21:35 2019(r350615)
+++ head/sys/kern/sys_process.c Mon Aug  5 20:26:01 2019(r350616)
@@ -958,9 +958,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, voi
 * on a "detach".
 */
proc_set_traced(p, true);
-   if (p->p_pptr != td->td_proc) {
-   proc_reparent(p, td->td_proc, false);
-   }
+   proc_reparent(p, td->td_proc, false);
CTR2(KTR_PTRACE, "PT_ATTACH: pid %d, oppid %d", p->p_pid,
p->p_oppid);
 
@@ -1109,7 +1107,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, voi
p->p_pid, psr->sr_error, psr->sr_retval[0],
psr->sr_retval[1]);
break;
-   
+
case PT_STEP:
case PT_CONTINUE:
case PT_TO_SCE:
@@ -1219,8 +1217,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, voi
 
sendsig:
MPASS(proctree_locked == 0);
-   
-   /* 
+
+   /*
 * Clear the pending event for the thread that just
 * reported its event (p_xthread).  This may not be
 * the thread passed to PT_CONTINUE, PT_STEP, etc. if
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350614 - head/sys/kern

2019-08-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Aug  5 20:20:14 2019
New Revision: 350614
URL: https://svnweb.freebsd.org/changeset/base/350614

Log:
  exit1: fix style nits
  
  MFC after:1 month

Modified:
  head/sys/kern/kern_exit.c

Modified: head/sys/kern/kern_exit.c
==
--- head/sys/kern/kern_exit.c   Mon Aug  5 20:19:38 2019(r350613)
+++ head/sys/kern/kern_exit.c   Mon Aug  5 20:20:14 2019(r350614)
@@ -475,7 +475,7 @@ exit1(struct thread *td, int rval, int signo)
PROC_LOCK(q);
q->p_sigparent = SIGCHLD;
 
-   if (!(q->p_flag & P_TRACED)) {
+   if ((q->p_flag & P_TRACED) == 0) {
proc_reparent(q, q->p_reaper, true);
if (q->p_state == PRS_ZOMBIE) {
/*
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350612 - in head: sys/kern tests/sys/kern

2019-08-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Aug  5 20:15:46 2019
New Revision: 350612
URL: https://svnweb.freebsd.org/changeset/base/350612

Log:
  procdesc: fix reparenting when the debugger is attached
  
  The process is reparented to the debugger while it is attached.
B  B
   /   >   |
  A  A D
  
  Every time when the process is reparented, it is added to the orphan list
  of the previous parent:
  
  A->orphan = B
  D->orphan = NULL
  
  When the A process will close the process descriptor to the B process,
  the B process will be reparented to the init process.
BB - init
|   >
  A D  A   D
  
  A->orphan = B
  D->orphan = B
  
  In this scenario, the B process is in the orphan list of A and D.
  
  When the last process descriptor is closed instead of reparenting
  it to the reaper let it stay with the debugger process and set
  our previews parent to the reaper.
  
  Add test case for this situation.
  Notice that without this patch the kernel will crash with this test case:
  panic: orphan 0xf8000e990530 of 0xf8000e99 has unexpected oppid 1
  
  Reviewed by:  markj, kib
  MFC after:1 month
  Differential Revision:https://reviews.freebsd.org/D20361

Modified:
  head/sys/kern/sys_procdesc.c
  head/tests/sys/kern/ptrace_test.c

Modified: head/sys/kern/sys_procdesc.c
==
--- head/sys/kern/sys_procdesc.cMon Aug  5 20:11:57 2019
(r350611)
+++ head/sys/kern/sys_procdesc.cMon Aug  5 20:15:46 2019
(r350612)
@@ -416,7 +416,13 @@ procdesc_close(struct file *fp, struct thread *td)
 * terminate with prejudice.
 */
p->p_sigparent = SIGCHLD;
-   proc_reparent(p, p->p_reaper, true);
+   if ((p->p_flag & P_TRACED) == 0) {
+   proc_reparent(p, p->p_reaper, true);
+   } else {
+   clear_orphan(p);
+   p->p_oppid = p->p_reaper->p_pid;
+   proc_add_orphan(p, p->p_reaper);
+   }
if ((pd->pd_flags & PDF_DAEMON) == 0)
kern_psignal(p, SIGKILL);
PROC_UNLOCK(p);

Modified: head/tests/sys/kern/ptrace_test.c
==
--- head/tests/sys/kern/ptrace_test.c   Mon Aug  5 20:11:57 2019
(r350611)
+++ head/tests/sys/kern/ptrace_test.c   Mon Aug  5 20:15:46 2019
(r350612)
@@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -4075,6 +4076,60 @@ ATF_TC_BODY(ptrace__syscall_args, tc)
ATF_REQUIRE(errno == ECHILD);
 }
 
+/*
+ * Verify that when the process is traced that it isn't reparent
+ * to the init process when we close all process descriptors.
+ */
+ATF_TC(ptrace__proc_reparent);
+ATF_TC_HEAD(ptrace__proc_reparent, tc)
+{
+
+   atf_tc_set_md_var(tc, "timeout", "2");
+}
+ATF_TC_BODY(ptrace__proc_reparent, tc)
+{
+   pid_t traced, debuger, wpid;
+   int pd, status;
+
+   traced = pdfork(, 0);
+   ATF_REQUIRE(traced >= 0);
+   if (traced == 0) {
+   raise(SIGSTOP);
+   exit(0);
+   }
+   ATF_REQUIRE(pd >= 0);
+
+   debuger = fork();
+   ATF_REQUIRE(debuger >= 0);
+   if (debuger == 0) {
+   /* The traced process is reparented to debuger. */
+   ATF_REQUIRE(ptrace(PT_ATTACH, traced, 0, 0) == 0);
+   wpid = waitpid(traced, , 0);
+   ATF_REQUIRE(wpid == traced);
+   ATF_REQUIRE(WIFSTOPPED(status));
+   ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+   ATF_REQUIRE(close(pd) == 0);
+   ATF_REQUIRE(ptrace(PT_DETACH, traced, (caddr_t)1, 0) == 0);
+
+   /* We closed pd so we should not have any child. */
+   wpid = wait();
+   ATF_REQUIRE(wpid == -1);
+   ATF_REQUIRE(errno == ECHILD);
+
+   exit(0);
+   }
+
+   ATF_REQUIRE(close(pd) == 0);
+   wpid = waitpid(debuger, , 0);
+   ATF_REQUIRE(wpid == debuger);
+   ATF_REQUIRE(WEXITSTATUS(status) == 0);
+
+   /* Check if we still have any child. */
+   wpid = wait();
+   ATF_REQUIRE(wpid == -1);
+   ATF_REQUIRE(errno == ECHILD);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -4137,6 +4192,7 @@ ATF_TP_ADD_TCS(tp)
 #endif
ATF_TP_ADD_TC(tp, ptrace__PT_LWPINFO_stale_siginfo);
ATF_TP_ADD_TC(tp, ptrace__syscall_args);
+   ATF_TP_ADD_TC(tp, ptrace__proc_reparent);
 
return (atf_no_error());
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to 

svn commit: r350611 - in head/sys: kern sys

2019-08-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Aug  5 20:11:57 2019
New Revision: 350611
URL: https://svnweb.freebsd.org/changeset/base/350611

Log:
  proc: introduce the proc_add_orphan function
  
  This API allows adding the process to its parent orphan list.
  
  Reviewed by:  kib, markj
  MFC after:1 month

Modified:
  head/sys/kern/kern_exit.c
  head/sys/sys/proc.h

Modified: head/sys/kern/kern_exit.c
==
--- head/sys/kern/kern_exit.c   Mon Aug  5 19:59:23 2019(r350610)
+++ head/sys/kern/kern_exit.c   Mon Aug  5 20:11:57 2019(r350611)
@@ -1355,6 +1355,24 @@ loop_locked:
goto loop;
 }
 
+void
+proc_add_orphan(struct proc *child, struct proc *parent)
+{
+
+   sx_assert(_lock, SX_XLOCKED);
+   KASSERT((child->p_flag & P_TRACED) != 0,
+   ("proc_add_orphan: not traced"));
+
+   if (LIST_EMPTY(>p_orphans)) {
+   child->p_treeflag |= P_TREE_FIRST_ORPHAN;
+   LIST_INSERT_HEAD(>p_orphans, child, p_orphan);
+   } else {
+   LIST_INSERT_AFTER(LIST_FIRST(>p_orphans),
+   child, p_orphan);
+   }
+   child->p_treeflag |= P_TREE_ORPHANED;
+}
+
 /*
  * Make process 'parent' the new parent of process 'child'.
  * Must be called with an exclusive hold of proctree lock.
@@ -1375,16 +1393,8 @@ proc_reparent(struct proc *child, struct proc *parent,
LIST_INSERT_HEAD(>p_children, child, p_sibling);
 
proc_clear_orphan(child);
-   if (child->p_flag & P_TRACED) {
-   if (LIST_EMPTY(>p_pptr->p_orphans)) {
-   child->p_treeflag |= P_TREE_FIRST_ORPHAN;
-   LIST_INSERT_HEAD(>p_pptr->p_orphans, child,
-   p_orphan);
-   } else {
-   LIST_INSERT_AFTER(LIST_FIRST(>p_pptr->p_orphans),
-   child, p_orphan);
-   }
-   child->p_treeflag |= P_TREE_ORPHANED;
+   if ((child->p_flag & P_TRACED) != 0) {
+   proc_add_orphan(child, child->p_pptr);
}
 
child->p_pptr = parent;

Modified: head/sys/sys/proc.h
==
--- head/sys/sys/proc.h Mon Aug  5 19:59:23 2019(r350610)
+++ head/sys/sys/proc.h Mon Aug  5 20:11:57 2019(r350611)
@@ -1069,6 +1069,7 @@ void  proc_linkup(struct proc *p, struct thread *td);
 struct proc *proc_realparent(struct proc *child);
 void   proc_reap(struct thread *td, struct proc *p, int *status, int options);
 void   proc_reparent(struct proc *child, struct proc *newparent, bool 
set_oppid);
+void   proc_add_orphan(struct proc *child, struct proc *parent);
 void   proc_set_traced(struct proc *p, bool stop);
 void   proc_wkilled(struct proc *p);
 struct pstats *pstats_alloc(void);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350610 - head/sys/kern

2019-08-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Aug  5 19:59:23 2019
New Revision: 350610
URL: https://svnweb.freebsd.org/changeset/base/350610

Log:
  exit1: postpone clearing P_TRACED flag until the proctree lock is acquired
  
  In case of the process being debugged. The P_TRACED is cleared very early,
  which would make procdesc_close() not calling proc_clear_orphan().
  That would result in the debugged process can not be able to collect
  status of the process with process descriptor.
  
  Reviewed by:  markj, kib
  Tested by:pho
  MFC after:1 month

Modified:
  head/sys/kern/kern_exit.c

Modified: head/sys/kern/kern_exit.c
==
--- head/sys/kern/kern_exit.c   Mon Aug  5 19:30:28 2019(r350609)
+++ head/sys/kern/kern_exit.c   Mon Aug  5 19:59:23 2019(r350610)
@@ -355,7 +355,6 @@ exit1(struct thread *td, int rval, int signo)
 */
PROC_LOCK(p);
stopprofclock(p);
-   p->p_flag &= ~(P_TRACED | P_PPWAIT | P_PPTRACE);
p->p_ptevents = 0;
 
/*
@@ -458,6 +457,9 @@ exit1(struct thread *td, int rval, int signo)
sx_xunlock(_lock);
 
sx_xlock(_lock);
+   PROC_LOCK(p);
+   p->p_flag &= ~(P_TRACED | P_PPWAIT | P_PPTRACE);
+   PROC_UNLOCK(p);
 
/*
 * Reparent all children processes:
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350482 - head

2019-07-31 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jul 31 19:32:39 2019
New Revision: 350482
URL: https://svnweb.freebsd.org/changeset/base/350482

Log:
  gnop: add note to the RELNOTES
  
  Submitted by: markj

Modified:
  head/RELNOTES

Modified: head/RELNOTES
==
--- head/RELNOTES   Wed Jul 31 19:27:20 2019(r350481)
+++ head/RELNOTES   Wed Jul 31 19:32:39 2019(r350482)
@@ -10,6 +10,10 @@ newline.  Entries should be separated by a newline.
 
 Changes to this file should not be MFCed.
 
+r350471:
+   gnop(8) can now configure a delay to be applied to read and write
+   request delays.  See the -d, -q and -x parameters.
+
 r350307:
libcap_random(3) has been removed.  Applications can use native
APIs to get random data in capability mode.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350472 - head/sys/geom/nop

2019-07-31 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jul 31 17:51:06 2019
New Revision: 350472
URL: https://svnweb.freebsd.org/changeset/base/350472

Log:
  gnop: style nits

Modified:
  head/sys/geom/nop/g_nop.c

Modified: head/sys/geom/nop/g_nop.c
==
--- head/sys/geom/nop/g_nop.c   Wed Jul 31 17:47:12 2019(r350471)
+++ head/sys/geom/nop/g_nop.c   Wed Jul 31 17:51:06 2019(r350472)
@@ -116,6 +116,7 @@ static int
 g_nop_dumper(void *priv, void *virtual, vm_offset_t physical, off_t offset,
 size_t length)
 {
+
return (0);
 }
 
@@ -213,7 +214,7 @@ g_nop_start(struct bio *bp)
break;
case BIO_GETATTR:
sc->sc_getattrs++;
-   if (sc->sc_physpath && 
+   if (sc->sc_physpath &&
g_handleattr_str(bp, "GEOM::physpath", sc->sc_physpath))
;
else if (strcmp(bp->bio_attribute, "GEOM::kerneldump") == 0)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350471 - in head: lib/geom/nop sys/geom/nop

2019-07-31 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jul 31 17:47:12 2019
New Revision: 350471
URL: https://svnweb.freebsd.org/changeset/base/350471

Log:
  gnop: Introduce requests delay.
  
  This allows to simulated disk that is responding slowly to the IO requests.
  
  Reviewed by:  markj, bcr, pjd (previous version)
  Differential Revision:https://reviews.freebsd.org/D21052

Modified:
  head/lib/geom/nop/geom_nop.c
  head/lib/geom/nop/gnop.8
  head/sys/geom/nop/g_nop.c
  head/sys/geom/nop/g_nop.h

Modified: head/lib/geom/nop/geom_nop.c
==
--- head/lib/geom/nop/geom_nop.cWed Jul 31 17:29:14 2019
(r350470)
+++ head/lib/geom/nop/geom_nop.cWed Jul 31 17:47:12 2019
(r350471)
@@ -43,29 +43,36 @@ uint32_t version = G_NOP_VERSION;
 struct g_command class_commands[] = {
{ "create", G_FLAG_VERBOSE | G_FLAG_LOADKLD, NULL,
{
+   { 'd', "delaymsec", "-1", G_TYPE_NUMBER },
{ 'e', "error", "-1", G_TYPE_NUMBER },
{ 'o', "offset", "0", G_TYPE_NUMBER },
{ 'p', "stripesize", "0", G_TYPE_NUMBER },
{ 'P', "stripeoffset", "0", G_TYPE_NUMBER },
+   { 'q', "rdelayprob", "-1", G_TYPE_NUMBER },
{ 'r', "rfailprob", "-1", G_TYPE_NUMBER },
{ 's', "size", "0", G_TYPE_NUMBER },
{ 'S', "secsize", "0", G_TYPE_NUMBER },
{ 'w', "wfailprob", "-1", G_TYPE_NUMBER },
+   { 'x', "wdelayprob", "1", G_TYPE_NUMBER },
{ 'z', "physpath", G_NOP_PHYSPATH_PASSTHROUGH, G_TYPE_STRING },
G_OPT_SENTINEL
},
-   "[-v] [-e error] [-o offset] [-p stripesize] [-P stripeoffset] "
-   "[-r rfailprob] [-s size] [-S secsize] [-w wfailprob] "
-   "[-z physpath] dev ..."
+   "[-v] [-d delaymsec] [-e error] [-o offset] [-p stripesize] "
+   "[-P stripeoffset] [-q rdelayprob] [-r rfailprob] [-s size] "
+   "[-S secsize] [-w wfailprob] [-x wdelayprob] [-z physpath] dev ..."
},
{ "configure", G_FLAG_VERBOSE, NULL,
{
+   { 'd', "delaymsec", "-1", G_TYPE_NUMBER },
{ 'e', "error", "-1", G_TYPE_NUMBER },
+   { 'q', "rdelayprob", "-1", G_TYPE_NUMBER },
{ 'r', "rfailprob", "-1", G_TYPE_NUMBER },
{ 'w', "wfailprob", "-1", G_TYPE_NUMBER },
+   { 'x', "wdelayprob", "1", G_TYPE_NUMBER },
G_OPT_SENTINEL
},
-   "[-v] [-e error] [-r rfailprob] [-w wfailprob] prov ..."
+   "[-v] [-d delaymsec] [-e error] [-q rdelayprob] [-r rfailprob] "
+   "[-w wfailprob] [-x wdelayprob] prov ..."
},
{ "destroy", G_FLAG_VERBOSE, NULL,
{

Modified: head/lib/geom/nop/gnop.8
==
--- head/lib/geom/nop/gnop.8Wed Jul 31 17:29:14 2019(r350470)
+++ head/lib/geom/nop/gnop.8Wed Jul 31 17:47:12 2019(r350471)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd January 17, 2018
+.Dd July 31, 2019
 .Dt GNOP 8
 .Os
 .Sh NAME
@@ -34,22 +34,28 @@
 .Nm
 .Cm create
 .Op Fl v
+.Op Fl d Ar delaymsec
 .Op Fl e Ar error
 .Op Fl o Ar offset
 .Op Fl p Ar stripesize
 .Op Fl P Ar stripeoffset
+.Op Fl q Ar rdelayprob
 .Op Fl r Ar rfailprob
 .Op Fl s Ar size
 .Op Fl S Ar secsize
 .Op Fl w Ar wfailprob
+.Op Fl x Ar wdelayprob
 .Op Fl z Ar physpath
 .Ar dev ...
 .Nm
 .Cm configure
 .Op Fl v
+.Op Fl d Ar delaymsec
 .Op Fl e Ar error
+.Op Fl q Ar rdelayprob
 .Op Fl r Ar rfailprob
 .Op Fl w Ar wfailprob
+.Op Fl x Ar wdelayprob
 .Ar prov ...
 .Nm
 .Cm destroy
@@ -113,6 +119,9 @@ See
 .Pp
 Additional options:
 .Bl -tag -width ".Fl r Ar rfailprob"
+.It Fl d Ar delaymsec
+Specifies the delay of the requests in milliseconds.
+Note that requests will be delayed before they are sent to the backing device.
 .It Fl e Ar error
 Specifies the error number to return on failure.
 .It Fl f
@@ -123,6 +132,8 @@ Where to begin on the original provider.
 Value of the stripesize property of the transparent provider.
 .It Fl P Ar stripeoffset
 Value of the stripeoffset property of the transparent provider.
+.It Fl q Ar rdelayprob
+Specifies read delay probability in percent.
 .It Fl r Ar rfailprob
 Specifies read failure probability in percent.
 .It Fl s Ar size
@@ -133,6 +144,8 @@ Sector size of the transparent provider.
 Specifies write failure probability in percent.
 .It Fl v
 Be more verbose.
+.It Fl x Ar wdelayprob
+Specifies write delay probability in percent.
 .It Fl z Ar physpath
 Physical path of the transparent provider.
 .El

Modified: head/sys/geom/nop/g_nop.c
==
--- head/sys/geom/nop/g_nop.c   Wed Jul 31 17:29:14 2019(r350470)
+++ head/sys/geom/nop/g_nop.c   Wed Jul 31 17:47:12 2019(r350471)
@@ -74,6 

svn commit: r350438 - head/lib/libcasper/services/cap_fileargs

2019-07-30 Thread Mariusz Zaborski
Author: oshogbo
Date: Tue Jul 30 08:53:03 2019
New Revision: 350438
URL: https://svnweb.freebsd.org/changeset/base/350438

Log:
  fileargs: fix formating in EXAMPLES
  
  PR:   239523
  Submitted by: mikael.uran...@gmail.com

Modified:
  head/lib/libcasper/services/cap_fileargs/cap_fileargs.3

Modified: head/lib/libcasper/services/cap_fileargs/cap_fileargs.3
==
--- head/lib/libcasper/services/cap_fileargs/cap_fileargs.3 Tue Jul 30 
05:14:28 2019(r350437)
+++ head/lib/libcasper/services/cap_fileargs/cap_fileargs.3 Tue Jul 30 
08:53:03 2019(r350438)
@@ -247,7 +247,7 @@ for (i = 0; i < argc; i++) {
fd = fileargs_open(fa, argv[i]);
if (fd < 0)
err(1, "unable to open file %s", argv[i]);
-   printf("File %s opened in capability mode\n", argv[i]);
+   printf("File %s opened in capability mode\en", argv[i]);
close(fd);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350430 - in head: share/man/man9 sys/sys

2019-07-29 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Jul 29 21:53:02 2019
New Revision: 350430
URL: https://svnweb.freebsd.org/changeset/base/350430

Log:
  seqc: add man page
  
  Reviewed by:  markj
  Earlier version reviewed by:  emaste, mjg, bcr, 0mp
  Differential Revision:https://reviews.freebsd.org/D16744

Added:
  head/share/man/man9/seqc.9   (contents, props changed)
Modified:
  head/share/man/man9/Makefile
  head/sys/sys/seqc.h

Modified: head/share/man/man9/Makefile
==
--- head/share/man/man9/MakefileMon Jul 29 21:42:57 2019
(r350429)
+++ head/share/man/man9/MakefileMon Jul 29 21:53:02 2019
(r350430)
@@ -289,6 +289,7 @@ MAN=accept_filter.9 \
securelevel_gt.9 \
selrecord.9 \
sema.9 \
+   seqc.9 \
sf_buf.9 \
sglist.9 \
shm_map.9 \
@@ -1825,6 +1826,10 @@ MLINKS+=sema.9 sema_destroy.9 \
sema.9 sema_trywait.9 \
sema.9 sema_value.9 \
sema.9 sema_wait.9
+MLINKS+=seqc.9 seqc_consistent.9 \
+   seqc.9 seqc_read.9 \
+   seqc.9 seqc_write_begin.9 \
+   seqc.9 seqc_write_end.9
 MLINKS+=sf_buf.9 sf_buf_alloc.9 \
sf_buf.9 sf_buf_free.9 \
sf_buf.9 sf_buf_kva.9 \

Added: head/share/man/man9/seqc.9
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/share/man/man9/seqc.9  Mon Jul 29 21:53:02 2019(r350430)
@@ -0,0 +1,138 @@
+.\"
+.\" Copyright (C) 2019 Mariusz Zaborski 
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice(s), this list of conditions and the following disclaimer as
+.\"the first lines of this file unmodified other than the possible
+.\"addition of one or more copyright notices.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice(s), this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
+.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+.\" DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd July 29, 2019
+.Dt SEQC 9
+.Os
+.Sh NAME
+.Nm seqc_consistent ,
+.Nm seqc_read ,
+.Nm seqc_write_begin ,
+.Nm seqc_write_end
+.Nd "lockless read algorithm"
+.Sh SYNOPSIS
+.In sys/seqc.h
+.Ft void
+.Fn seqc_write_begin "seqc_t *seqcp"
+.Ft void
+.Fn seqc_write_end "seqc_t *seqcp"
+.Ft seqc_t
+.Fn seqc_read "seqc_t *seqcp"
+.Ft seqc_t
+.Fn seqc_consistent "const seqc_t *seqcp" "seqc_t oldseqc"
+.Sh DESCRIPTION
+The
+.Nm seqc
+allows zero or more readers and zero or one writer to concurrently access
+an object, providing a consistent snapshot of the object for readers.
+No mutual exclusion between readers and writers is required,
+but readers may be starved indefinitely by writers.
+.Pp
+The functions
+.Fn seqc_write_begin
+and
+.Fn seqc_write_end
+are used to create a transaction for writer, and notify the readers that the
+object will be modified.
+.Pp
+The
+.Fn seqc_read
+function returns the current sequence number.
+If a writer has started a transaction, this function will spin until the
+transaction has ended.
+.Pp
+The
+.Fn seqc_consistent
+function compares the sequence number with a previously fetched value.
+The
+.Fa oldseqc
+variable should contain a sequence number from the beginning of read
+transaction.
+.Pp
+The reader at the end of a transaction checks if the sequence number has
+changed.
+If the sequence number didn't change the object wasn't modified, and fetched
+variables are valid.
+If the sequence number changed the object was modified and the fetch should be
+repeated.
+In case when sequence number is odd the object change is in progress and the
+reader will wait until the write will the sequence number will become even.
+.Sh EXAMPLES
+The following example for a w

svn commit: r350429 - in head/sys: kern sys

2019-07-29 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Jul 29 21:42:57 2019
New Revision: 350429
URL: https://svnweb.freebsd.org/changeset/base/350429

Log:
  proc: make clear_orphan an public API
  
  This will be useful for other patches with process descriptors.
  Change its name as well.
  
  Reviewed by:  markj, kib

Modified:
  head/sys/kern/kern_exit.c
  head/sys/sys/proc.h

Modified: head/sys/kern/kern_exit.c
==
--- head/sys/kern/kern_exit.c   Mon Jul 29 21:26:26 2019(r350428)
+++ head/sys/kern/kern_exit.c   Mon Jul 29 21:42:57 2019(r350429)
@@ -167,8 +167,8 @@ reaper_clear(struct proc *p)
proc_id_clear(PROC_ID_REAP, p->p_reapsubtree);
 }
 
-static void
-clear_orphan(struct proc *p)
+void
+proc_clear_orphan(struct proc *p)
 {
struct proc *p1;
 
@@ -522,7 +522,7 @@ exit1(struct thread *td, int rval, int signo)
 * list due to present P_TRACED flag. Clear
 * orphan link for q now while q is locked.
 */
-   clear_orphan(q);
+   proc_clear_orphan(q);
q->p_flag &= ~(P_TRACED | P_STOPPED_TRACE);
q->p_flag2 &= ~P2_PTRACE_FSTP;
q->p_ptevents = 0;
@@ -556,7 +556,7 @@ exit1(struct thread *td, int rval, int signo)
kern_psignal(q, q->p_pdeathsig);
CTR2(KTR_PTRACE, "exit: pid %d, clearing orphan %d", p->p_pid,
q->p_pid);
-   clear_orphan(q);
+   proc_clear_orphan(q);
PROC_UNLOCK(q);
}
 
@@ -912,7 +912,7 @@ proc_reap(struct thread *td, struct proc *p, int *stat
reaper_clear(p);
proc_id_clear(PROC_ID_PID, p->p_pid);
PROC_LOCK(p);
-   clear_orphan(p);
+   proc_clear_orphan(p);
PROC_UNLOCK(p);
leavepgrp(p);
if (p->p_procdesc != NULL)
@@ -1372,7 +1372,7 @@ proc_reparent(struct proc *child, struct proc *parent,
LIST_REMOVE(child, p_sibling);
LIST_INSERT_HEAD(>p_children, child, p_sibling);
 
-   clear_orphan(child);
+   proc_clear_orphan(child);
if (child->p_flag & P_TRACED) {
if (LIST_EMPTY(>p_pptr->p_orphans)) {
child->p_treeflag |= P_TREE_FIRST_ORPHAN;

Modified: head/sys/sys/proc.h
==
--- head/sys/sys/proc.h Mon Jul 29 21:26:26 2019(r350428)
+++ head/sys/sys/proc.h Mon Jul 29 21:42:57 2019(r350429)
@@ -1074,6 +1074,7 @@ void  proc_wkilled(struct proc *p);
 struct pstats *pstats_alloc(void);
 void   pstats_fork(struct pstats *src, struct pstats *dst);
 void   pstats_free(struct pstats *ps);
+void   proc_clear_orphan(struct proc *p);
 void   reaper_abandon_children(struct proc *p, bool exiting);
 intsecurelevel_ge(struct ucred *cr, int level);
 intsecurelevel_gt(struct ucred *cr, int level);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350428 - head/lib/libcasper/libcasper

2019-07-29 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Jul 29 21:26:26 2019
New Revision: 350428
URL: https://svnweb.freebsd.org/changeset/base/350428

Log:
  libcasper: remove reference to deprecated system.random

Modified:
  head/lib/libcasper/libcasper/libcasper.3

Modified: head/lib/libcasper/libcasper/libcasper.3
==
--- head/lib/libcasper/libcasper/libcasper.3Mon Jul 29 21:21:53 2019
(r350427)
+++ head/lib/libcasper/libcasper/libcasper.3Mon Jul 29 21:26:26 2019
(r350428)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd November 5, 2018
+.Dd July 29, 2019
 .Dt LIBCASPER 3
 .Os
 .Sh NAME
@@ -212,9 +212,6 @@ compatible API
 provides
 .Xr getpwent 3
 compatible API
-.It system.random
-allows to obtain entropy from
-.Pa /dev/random
 .It system.sysctl
 provides
 .Xr sysctlbyname 3
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350024 - head/contrib/elftoolchain/strings

2019-07-15 Thread Mariusz Zaborski
Author: oshogbo
Date: Tue Jul 16 04:17:25 2019
New Revision: 350024
URL: https://svnweb.freebsd.org/changeset/base/350024

Log:
  strings: extends rights
  
  The libelf is using mmap if it can, if not it was fall backing to read.
  
  Reported by:  markj

Modified:
  head/contrib/elftoolchain/strings/strings.c

Modified: head/contrib/elftoolchain/strings/strings.c
==
--- head/contrib/elftoolchain/strings/strings.c Tue Jul 16 03:55:27 2019
(r350023)
+++ head/contrib/elftoolchain/strings/strings.c Tue Jul 16 04:17:25 2019
(r350024)
@@ -194,7 +194,7 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
 
-   cap_rights_init(, CAP_READ, CAP_SEEK, CAP_FSTAT, CAP_FCNTL);
+   cap_rights_init(, CAP_READ, CAP_SEEK, CAP_FSTAT, CAP_FCNTL, 
CAP_MMAP_R);
fa = fileargs_init(argc, argv, O_RDONLY, 0, , FA_OPEN);
if (fa == NULL)
err(1, "Unable to initialize casper fileargs");
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r350022 - head/contrib/elftoolchain/strings

2019-07-15 Thread Mariusz Zaborski
Author: oshogbo
Date: Tue Jul 16 03:32:21 2019
New Revision: 350022
URL: https://svnweb.freebsd.org/changeset/base/350022

Log:
  strings: fix entering to the capability mode
  
  Reported by:  markj

Modified:
  head/contrib/elftoolchain/strings/strings.c

Modified: head/contrib/elftoolchain/strings/strings.c
==
--- head/contrib/elftoolchain/strings/strings.c Tue Jul 16 03:09:03 2019
(r350021)
+++ head/contrib/elftoolchain/strings/strings.c Tue Jul 16 03:32:21 2019
(r350022)
@@ -200,7 +200,7 @@ main(int argc, char **argv)
err(1, "Unable to initialize casper fileargs");
 
caph_cache_catpages();
-   if (caph_limit_stdio() < 0 && caph_enter_casper() < 0) {
+   if (caph_limit_stdio() < 0 || caph_enter_casper() < 0) {
fileargs_free(fa);
err(1, "Unable to enter capability mode");
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r349002 - head/lib/libcasper/services/cap_fileargs

2019-06-12 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun 12 19:31:26 2019
New Revision: 349002
URL: https://svnweb.freebsd.org/changeset/base/349002

Log:
  fileargs: add wrapping/unwrapping functions
  
  Those function may be useful to pass fileargs connections around.

Modified:
  head/lib/libcasper/services/cap_fileargs/cap_fileargs.c
  head/lib/libcasper/services/cap_fileargs/cap_fileargs.h

Modified: head/lib/libcasper/services/cap_fileargs/cap_fileargs.c
==
--- head/lib/libcasper/services/cap_fileargs/cap_fileargs.c Wed Jun 12 
19:29:48 2019(r349001)
+++ head/lib/libcasper/services/cap_fileargs/cap_fileargs.c Wed Jun 12 
19:31:26 2019(r349002)
@@ -424,6 +424,39 @@ fileargs_free(fileargs_t *fa)
free(fa);
 }
 
+cap_channel_t *
+fileargs_unwrap(fileargs_t *fa, int *flags)
+{
+   cap_channel_t *chan;
+
+   if (fa == NULL)
+   return (NULL);
+
+   assert(fa->fa_magic == FILEARGS_MAGIC);
+
+   chan = fa->fa_chann;
+   if (flags != NULL) {
+   *flags = fa->fa_fdflags;
+   }
+
+   nvlist_destroy(fa->fa_cache);
+   explicit_bzero(>fa_magic, sizeof(fa->fa_magic));
+   free(fa);
+
+   return (chan);
+}
+
+fileargs_t *
+fileargs_wrap(cap_channel_t *chan, int fdflags)
+{
+
+   if (chan == NULL) {
+   return (NULL);
+   }
+
+   return (fileargs_create(chan, fdflags));
+}
+
 /*
  * Service functions.
  */

Modified: head/lib/libcasper/services/cap_fileargs/cap_fileargs.h
==
--- head/lib/libcasper/services/cap_fileargs/cap_fileargs.h Wed Jun 12 
19:29:48 2019(r349001)
+++ head/lib/libcasper/services/cap_fileargs/cap_fileargs.h Wed Jun 12 
19:31:26 2019(r349002)
@@ -54,6 +54,9 @@ int fileargs_lstat(fileargs_t *fa, const char *name, s
 int fileargs_open(fileargs_t *fa, const char *name);
 void fileargs_free(fileargs_t *fa);
 FILE *fileargs_fopen(fileargs_t *fa, const char *name, const char *mode);
+
+fileargs_t *fileargs_wrap(cap_channel_t *chan, int fdflags);
+cap_channel_t *fileargs_unwrap(fileargs_t *fa, int *fdflags);
 #else
 typedef struct fileargs {
int fa_flags;
@@ -114,7 +117,27 @@ FILE *fileargs_fopen(fileargs_t *fa, const char *name,
(void) fa;
return (fopen(name, mode));
 }
-#definefileargs_free(fa)   (free(fa))
+#definefileargs_free(fa)   (free(fa))
+
+static inline fileargs_t *
+fileargs_wrap(cap_channel_t *chan, int fdflags)
+{
+
+   cap_close(chan);
+   return (fileargs_init(0, NULL, fdflags, 0, NULL, 0));
+}
+
+static inline cap_channel_t *
+fileargs_unwrap(fileargs_t *fa, int *fdflags)
+{
+
+   if (fdflags != NULL) {
+   *fdflags = fa->fa_flags;
+   }
+   fileargs_free(fa);
+   return (cap_init());
+}
+
 #endif
 
 #endif /* !_FILEARGS_H_ */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r349000 - head/sys/geom/eli

2019-06-12 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun 12 19:29:12 2019
New Revision: 349000
URL: https://svnweb.freebsd.org/changeset/base/349000

Log:
  geli: partially revert r348709
  
  Let's change the unsigned arguments to the signed one, but let's don't
  change pointers to the array notation.
  
  Requested by: pjd

Modified:
  head/sys/geom/eli/g_eli.h
  head/sys/geom/eli/g_eli_hmac.c
  head/sys/geom/eli/pkcs5v2.c
  head/sys/geom/eli/pkcs5v2.h

Modified: head/sys/geom/eli/g_eli.h
==
--- head/sys/geom/eli/g_eli.h   Wed Jun 12 18:07:04 2019(r348999)
+++ head/sys/geom/eli/g_eli.h   Wed Jun 12 19:29:12 2019(r349000)
@@ -721,12 +721,12 @@ struct hmac_ctx {
SHA512_CTX  outerctx;
 };
 
-void g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const char hkey[],
+void g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const char *hkey,
 size_t hkeylen);
 void g_eli_crypto_hmac_update(struct hmac_ctx *ctx, const uint8_t *data,
 size_t datasize);
 void g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize);
-void g_eli_crypto_hmac(const char hkey[], size_t hkeysize,
+void g_eli_crypto_hmac(const char *hkey, size_t hkeysize,
 const uint8_t *data, size_t datasize, uint8_t *md, size_t mdsize);
 
 void g_eli_key_fill(struct g_eli_softc *sc, struct g_eli_key *key,

Modified: head/sys/geom/eli/g_eli_hmac.c
==
--- head/sys/geom/eli/g_eli_hmac.c  Wed Jun 12 18:07:04 2019
(r348999)
+++ head/sys/geom/eli/g_eli_hmac.c  Wed Jun 12 19:29:12 2019
(r349000)
@@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$");
 #include 
 
 void
-g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const char hkey[],
+g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const char *hkey,
 size_t hkeylen)
 {
u_char k_ipad[128], k_opad[128], key[128];
@@ -110,7 +110,7 @@ g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t 
 }
 
 void
-g_eli_crypto_hmac(const char hkey[], size_t hkeysize, const uint8_t *data,
+g_eli_crypto_hmac(const char *hkey, size_t hkeysize, const uint8_t *data,
 size_t datasize, uint8_t *md, size_t mdsize)
 {
struct hmac_ctx ctx;

Modified: head/sys/geom/eli/pkcs5v2.c
==
--- head/sys/geom/eli/pkcs5v2.c Wed Jun 12 18:07:04 2019(r348999)
+++ head/sys/geom/eli/pkcs5v2.c Wed Jun 12 19:29:12 2019(r349000)
@@ -52,7 +52,7 @@ xor(uint8_t *dst, const uint8_t *src, size_t size)
 
 void
 pkcs5v2_genkey(uint8_t *key, unsigned keylen, const uint8_t *salt,
-size_t saltsize, const char passphrase[], u_int iterations)
+size_t saltsize, const char *passphrase, u_int iterations)
 {
uint8_t md[SHA512_MDLEN], saltcount[saltsize + sizeof(uint32_t)];
uint8_t *counter, *keyp;

Modified: head/sys/geom/eli/pkcs5v2.h
==
--- head/sys/geom/eli/pkcs5v2.h Wed Jun 12 18:07:04 2019(r348999)
+++ head/sys/geom/eli/pkcs5v2.h Wed Jun 12 19:29:12 2019(r349000)
@@ -31,7 +31,7 @@
 #ifndef _PKCS5V2_H_
 #define_PKCS5V2_H_
 void pkcs5v2_genkey(uint8_t *key, unsigned keylen, const uint8_t *salt,
-size_t saltsize, const char passphrase[], u_int iterations);
+size_t saltsize, const char *passphrase, u_int iterations);
 #ifndef _KERNEL
 int pkcs5v2_calculate(int usecs);
 #endif
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r349001 - head/sys/geom/eli

2019-06-12 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun 12 19:29:48 2019
New Revision: 349001
URL: https://svnweb.freebsd.org/changeset/base/349001

Log:
  geli: style nits

Modified:
  head/sys/geom/eli/g_eli_hmac.c

Modified: head/sys/geom/eli/g_eli_hmac.c
==
--- head/sys/geom/eli/g_eli_hmac.c  Wed Jun 12 19:29:12 2019
(r349000)
+++ head/sys/geom/eli/g_eli_hmac.c  Wed Jun 12 19:29:48 2019
(r349001)
@@ -96,11 +96,11 @@ g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t 
 
/* Complete inner hash */
SHA512_Final(digest, >innerctx);
-   
+
/* Complete outer hash */
SHA512_Update(>outerctx, digest, sizeof(digest));
SHA512_Final(digest, >outerctx);
-   
+
explicit_bzero(ctx, sizeof(*ctx));
/* mdsize == 0 means "Give me the whole hash!" */
if (mdsize == 0)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r348842 - head/usr.bin/tail

2019-06-09 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Jun  9 22:55:21 2019
New Revision: 348842
URL: https://svnweb.freebsd.org/changeset/base/348842

Log:
  tail: fix the checks if the file was rotated
  
  The freopen(3) was replaced with fileargs_open(3) and fclose(3).
  In the following function, we skip if the stream is standard in, so it is
  safe to do so.
  This also requires us to change the logic first to open the file and then
  check its status. The stat(2) is disallowed in capability mode.
  
  This commit unbrakes the -F option.
  The bug was introduced in the r348708.
  
  Reported by:  pho
  Tested by:pho

Modified:
  head/usr.bin/tail/extern.h
  head/usr.bin/tail/forward.c
  head/usr.bin/tail/misc.c
  head/usr.bin/tail/read.c
  head/usr.bin/tail/reverse.c
  head/usr.bin/tail/tail.c

Modified: head/usr.bin/tail/extern.h
==
--- head/usr.bin/tail/extern.h  Sun Jun  9 22:45:07 2019(r348841)
+++ head/usr.bin/tail/extern.h  Sun Jun  9 22:55:21 2019(r348842)
@@ -78,3 +78,4 @@ int maparound(struct mapinfo *, off_t);
 void printfn(const char *, int);
 
 extern int Fflag, fflag, qflag, rflag, rval, no_files;
+extern fileargs_t *fa;

Modified: head/usr.bin/tail/forward.c
==
--- head/usr.bin/tail/forward.c Sun Jun  9 22:45:07 2019(r348841)
+++ head/usr.bin/tail/forward.c Sun Jun  9 22:55:21 2019(r348842)
@@ -57,6 +57,9 @@ static const char sccsid[] = "@(#)forward.c   8.1 (Berke
 #include 
 #include 
 
+#include 
+#include 
+
 #include "extern.h"
 
 static void rlines(FILE *, const char *fn, off_t, struct stat *);
@@ -310,6 +313,7 @@ follow(file_info_t *files, enum STYLE style, off_t off
int active, ev_change, i, n = -1;
struct stat sb2;
file_info_t *file;
+   FILE *ftmp;
struct timespec ts;
 
/* Position each of the files */
@@ -346,7 +350,9 @@ follow(file_info_t *files, enum STYLE style, off_t off
if (Fflag) {
for (i = 0, file = files; i < no_files; i++, file++) {
if (!file->fp) {
-   file->fp = fopen(file->file_name, "r");
+   file->fp =
+   fileargs_fopen(fa, file->file_name,
+   "r");
if (file->fp != NULL &&
fstat(fileno(file->fp), >st)
== -1) {
@@ -359,7 +365,9 @@ follow(file_info_t *files, enum STYLE style, off_t off
}
if (fileno(file->fp) == STDIN_FILENO)
continue;
-   if (stat(file->file_name, ) == -1) {
+   ftmp = fileargs_fopen(fa, file->file_name, "r");
+   if (ftmp == NULL ||
+   fstat(fileno(file->fp), ) == -1) {
if (errno != ENOENT)
ierr(file->file_name);
show(file);
@@ -367,6 +375,9 @@ follow(file_info_t *files, enum STYLE style, off_t off
fclose(file->fp);
file->fp = NULL;
}
+   if (ftmp != NULL) {
+   fclose(ftmp);
+   }
ev_change++;
continue;
}
@@ -375,14 +386,13 @@ follow(file_info_t *files, enum STYLE style, off_t off
sb2.st_dev != file->st.st_dev ||
sb2.st_nlink == 0) {
show(file);
-   file->fp = freopen(file->file_name, "r",
-   file->fp);
-   if (file->fp != NULL)
-   memcpy(>st, ,
-   sizeof(struct stat));
-   else if (errno != ENOENT)
-   ierr(file->file_name);
+   fclose(file->fp);
+   file->fp = ftmp;
+   memcpy(>st, ,
+   sizeof(struct stat));
ev_change++;
+   } else {
+   fclose(ftmp);

svn commit: r348841 - head/cddl/usr.sbin/dtrace/tests/amd64

2019-06-09 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Jun  9 22:45:07 2019
New Revision: 348841
URL: https://svnweb.freebsd.org/changeset/base/348841

Log:
  DTrace: add a top level makefile to the new test suit
  
  Pointed out by:   markj

Added:
  head/cddl/usr.sbin/dtrace/tests/amd64/Makefile   (contents, props changed)

Added: head/cddl/usr.sbin/dtrace/tests/amd64/Makefile
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/cddl/usr.sbin/dtrace/tests/amd64/Makefile  Sun Jun  9 22:45:07 
2019(r348841)
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+TESTSDIR=  ${TESTSBASE}/cddl/usr.sbin/dtrace/amd64
+TESTS_SUBDIRS+= arrays
+
+.PATH: ${.CURDIR:H:H:H:H:H}/tests
+KYUAFILE=  YES
+
+.include 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r348833 - head/usr.bin/tail

2019-06-09 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Jun  9 11:21:29 2019
New Revision: 348833
URL: https://svnweb.freebsd.org/changeset/base/348833

Log:
  tail: style nits

Modified:
  head/usr.bin/tail/tail.c

Modified: head/usr.bin/tail/tail.c
==
--- head/usr.bin/tail/tail.cSun Jun  9 08:22:38 2019(r348832)
+++ head/usr.bin/tail/tail.cSun Jun  9 11:21:29 2019(r348833)
@@ -212,7 +212,8 @@ main(int argc, char *argv[])
file->file_name = strdup(fn);
if (! file->file_name)
errx(1, "Couldn't malloc space for file name.");
-   if ((file->fp = fileargs_fopen(fa, file->file_name, 
"r")) == NULL ||
+   file->fp = fileargs_fopen(fa, file->file_name, "r");
+   if (file->fp == NULL ||
fstat(fileno(file->fp), >st)) {
if (file->fp != NULL) {
fclose(file->fp);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r348711 - head/usr.bin/tail

2019-06-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun  5 22:55:00 2019
New Revision: 348711
URL: https://svnweb.freebsd.org/changeset/base/348711

Log:
  tail: disable capsicum in rescue mode
  
  All rescue application are not capsicumized.
  
  Reported by:  jenkins

Modified:
  head/usr.bin/tail/Makefile

Modified: head/usr.bin/tail/Makefile
==
--- head/usr.bin/tail/Makefile  Wed Jun  5 22:47:37 2019(r348710)
+++ head/usr.bin/tail/Makefile  Wed Jun  5 22:55:00 2019(r348711)
@@ -6,7 +6,7 @@
 PROG=  tail
 SRCS=  forward.c misc.c read.c reverse.c tail.c
 
-.if ${MK_CASPER} != "no"
+.if ${MK_CASPER} != "no" && !defined(RESCUE)
 LIBADD+= casper
 LIBADD+= cap_fileargs
 CFLAGS+= -DWITH_CASPER
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r348710 - head/usr.bin/tail

2019-06-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun  5 22:47:37 2019
New Revision: 348710
URL: https://svnweb.freebsd.org/changeset/base/348710

Log:
  tail: fix style nit introduced in the r348708

Modified:
  head/usr.bin/tail/tail.c

Modified: head/usr.bin/tail/tail.c
==
--- head/usr.bin/tail/tail.cWed Jun  5 22:46:18 2019(r348709)
+++ head/usr.bin/tail/tail.cWed Jun  5 22:47:37 2019(r348710)
@@ -175,7 +175,6 @@ main(int argc, char *argv[])
if (caph_enter_casper() < 0)
err(1, "unable to enter capability mode");
 
-   
/*
 * If displaying in reverse, don't permit follow option, and convert
 * style values.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r348709 - head/sys/geom/eli

2019-06-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun  5 22:46:18 2019
New Revision: 348709
URL: https://svnweb.freebsd.org/changeset/base/348709

Log:
  geli: build warning fixes
  
  Submitted by: Aaron Prieger 
  Reviewed by:  sbruno
  Differential Revision:https://reviews.freebsd.org/D11068

Modified:
  head/sys/geom/eli/g_eli.h
  head/sys/geom/eli/g_eli_hmac.c
  head/sys/geom/eli/pkcs5v2.c
  head/sys/geom/eli/pkcs5v2.h

Modified: head/sys/geom/eli/g_eli.h
==
--- head/sys/geom/eli/g_eli.h   Wed Jun  5 22:40:49 2019(r348708)
+++ head/sys/geom/eli/g_eli.h   Wed Jun  5 22:46:18 2019(r348709)
@@ -721,12 +721,12 @@ struct hmac_ctx {
SHA512_CTX  outerctx;
 };
 
-void g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey,
+void g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const char hkey[],
 size_t hkeylen);
 void g_eli_crypto_hmac_update(struct hmac_ctx *ctx, const uint8_t *data,
 size_t datasize);
 void g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize);
-void g_eli_crypto_hmac(const uint8_t *hkey, size_t hkeysize,
+void g_eli_crypto_hmac(const char hkey[], size_t hkeysize,
 const uint8_t *data, size_t datasize, uint8_t *md, size_t mdsize);
 
 void g_eli_key_fill(struct g_eli_softc *sc, struct g_eli_key *key,

Modified: head/sys/geom/eli/g_eli_hmac.c
==
--- head/sys/geom/eli/g_eli_hmac.c  Wed Jun  5 22:40:49 2019
(r348708)
+++ head/sys/geom/eli/g_eli_hmac.c  Wed Jun  5 22:46:18 2019
(r348709)
@@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$");
 #include 
 
 void
-g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey,
+g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const char hkey[],
 size_t hkeylen)
 {
u_char k_ipad[128], k_opad[128], key[128];
@@ -110,7 +110,7 @@ g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t 
 }
 
 void
-g_eli_crypto_hmac(const uint8_t *hkey, size_t hkeysize, const uint8_t *data,
+g_eli_crypto_hmac(const char hkey[], size_t hkeysize, const uint8_t *data,
 size_t datasize, uint8_t *md, size_t mdsize)
 {
struct hmac_ctx ctx;

Modified: head/sys/geom/eli/pkcs5v2.c
==
--- head/sys/geom/eli/pkcs5v2.c Wed Jun  5 22:40:49 2019(r348708)
+++ head/sys/geom/eli/pkcs5v2.c Wed Jun  5 22:46:18 2019(r348709)
@@ -52,7 +52,7 @@ xor(uint8_t *dst, const uint8_t *src, size_t size)
 
 void
 pkcs5v2_genkey(uint8_t *key, unsigned keylen, const uint8_t *salt,
-size_t saltsize, const char *passphrase, u_int iterations)
+size_t saltsize, const char passphrase[], u_int iterations)
 {
uint8_t md[SHA512_MDLEN], saltcount[saltsize + sizeof(uint32_t)];
uint8_t *counter, *keyp;
@@ -97,7 +97,7 @@ static int
 pkcs5v2_probe(int iterations)
 {
uint8_t key[G_ELI_USERKEYLEN], salt[G_ELI_SALTLEN];
-   uint8_t passphrase[] = "passphrase";
+   const char passphrase[] = "passphrase";
struct rusage start, end;
int usecs;
 

Modified: head/sys/geom/eli/pkcs5v2.h
==
--- head/sys/geom/eli/pkcs5v2.h Wed Jun  5 22:40:49 2019(r348708)
+++ head/sys/geom/eli/pkcs5v2.h Wed Jun  5 22:46:18 2019(r348709)
@@ -31,7 +31,7 @@
 #ifndef _PKCS5V2_H_
 #define_PKCS5V2_H_
 void pkcs5v2_genkey(uint8_t *key, unsigned keylen, const uint8_t *salt,
-size_t saltsize, const char *passphrase, u_int iterations);
+size_t saltsize, const char passphrase[], u_int iterations);
 #ifndef _KERNEL
 int pkcs5v2_calculate(int usecs);
 #endif
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r348708 - head/usr.bin/tail

2019-06-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun  5 22:40:49 2019
New Revision: 348708
URL: https://svnweb.freebsd.org/changeset/base/348708

Log:
  tail: capsicumize
  
  Submitted by: Nik Sultana 
  Differential Revision:https://reviews.freebsd.org/D20393

Modified:
  head/usr.bin/tail/Makefile
  head/usr.bin/tail/tail.c

Modified: head/usr.bin/tail/Makefile
==
--- head/usr.bin/tail/Makefile  Wed Jun  5 22:36:19 2019(r348707)
+++ head/usr.bin/tail/Makefile  Wed Jun  5 22:40:49 2019(r348708)
@@ -6,6 +6,12 @@
 PROG=  tail
 SRCS=  forward.c misc.c read.c reverse.c tail.c
 
+.if ${MK_CASPER} != "no"
+LIBADD+= casper
+LIBADD+= cap_fileargs
+CFLAGS+= -DWITH_CASPER
+.endif
+
 HAS_TESTS=
 SUBDIR.${MK_TESTS}+= tests
 

Modified: head/usr.bin/tail/tail.c
==
--- head/usr.bin/tail/tail.cWed Jun  5 22:36:19 2019(r348707)
+++ head/usr.bin/tail/tail.cWed Jun  5 22:40:49 2019(r348708)
@@ -46,9 +46,11 @@ static const char copyright[] =
 static const char sccsid[] = "@(#)tail.c   8.1 (Berkeley) 6/6/93";
 #endif
 
+#include 
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -57,6 +59,9 @@ static const char sccsid[] = "@(#)tail.c  8.1 (Berkeley
 #include 
 #include 
 
+#include 
+#include 
+
 #include "extern.h"
 
 int Fflag, fflag, qflag, rflag, rval, no_files;
@@ -85,7 +90,14 @@ main(int argc, char *argv[])
int i, ch, first;
file_info_t *file;
char *p;
+   fileargs_t *fa;
+   cap_rights_t rights;
 
+   cap_rights_init(, CAP_FSTAT, CAP_FCNTL, CAP_MMAP_RW);
+   if (caph_rights_limit(STDIN_FILENO, ) < 0 ||
+   caph_limit_stderr() < 0 || caph_limit_stdout() < 0)
+   err(1, "can't limit stdio rights");
+
/*
 * Tail's options are weird.  First, -n10 is the same as -n-10, not
 * -n+10.  Second, the number options are 1 based and not offsets,
@@ -155,6 +167,15 @@ main(int argc, char *argv[])
 
no_files = argc ? argc : 1;
 
+   fa = fileargs_init(argc, argv, O_RDONLY, 0, , FA_OPEN);
+   if (fa == NULL)
+   errx(1, "unable to init casper");
+
+   caph_cache_catpages();
+   if (caph_enter_casper() < 0)
+   err(1, "unable to enter capability mode");
+
+   
/*
 * If displaying in reverse, don't permit follow option, and convert
 * style values.
@@ -192,7 +213,7 @@ main(int argc, char *argv[])
file->file_name = strdup(fn);
if (! file->file_name)
errx(1, "Couldn't malloc space for file name.");
-   if ((file->fp = fopen(file->file_name, "r")) == NULL ||
+   if ((file->fp = fileargs_fopen(fa, file->file_name, 
"r")) == NULL ||
fstat(fileno(file->fp), >st)) {
if (file->fp != NULL) {
fclose(file->fp);
@@ -209,7 +230,7 @@ main(int argc, char *argv[])
free(files);
} else if (*argv) {
for (first = 1; (fn = *argv++);) {
-   if ((fp = fopen(fn, "r")) == NULL ||
+   if ((fp = fileargs_fopen(fa, fn, "r")) == NULL ||
fstat(fileno(fp), )) {
ierr(fn);
continue;
@@ -247,6 +268,7 @@ main(int argc, char *argv[])
else
forward(stdin, fn, style, off, );
}
+   fileargs_free(fa);
exit(rval);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r348707 - head/lib/libc/sys

2019-06-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun  5 22:36:19 2019
New Revision: 348707
URL: https://svnweb.freebsd.org/changeset/base/348707

Log:
  unlink: add missing function to unlink.2 man page

Modified:
  head/lib/libc/sys/unlink.2

Modified: head/lib/libc/sys/unlink.2
==
--- head/lib/libc/sys/unlink.2  Wed Jun  5 22:32:26 2019(r348706)
+++ head/lib/libc/sys/unlink.2  Wed Jun  5 22:36:19 2019(r348707)
@@ -28,12 +28,13 @@
 .\" @(#)unlink.2   8.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd April 6, 2019
+.Dd June 6, 2019
 .Dt UNLINK 2
 .Os
 .Sh NAME
 .Nm unlink ,
-.Nm unlinkat
+.Nm unlinkat ,
+.Nm funlinkat
 .Nd remove directory entry
 .Sh LIBRARY
 .Lb libc
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r348706 - in head: cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64 cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays cddl/usr.sbin/dtrace/tests cddl/usr.sbin/dtrace/tests/amd...

2019-06-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun  5 22:32:26 2019
New Revision: 348706
URL: https://svnweb.freebsd.org/changeset/base/348706

Log:
  DTrace: create an amd64 test suit
  
  Create two tests checking if we can read urgs registers and if the
  rax register returns a correct number.
  
  Reviewed by:  markj
  Discussed with:   lwhsu
  MFC after:2 weeks
  Differential Revision:https://reviews.freebsd.org/D20364

Added:
  head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/
  head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/
  head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/tst.rax.c   
(contents, props changed)
  head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/tst.rax.d   
(contents, props changed)
  
head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/tst.uregsarray.d 
  (contents, props changed)
  head/cddl/usr.sbin/dtrace/tests/amd64/
  head/cddl/usr.sbin/dtrace/tests/amd64/arrays/
  head/cddl/usr.sbin/dtrace/tests/amd64/arrays/Makefile   (contents, props 
changed)
Modified:
  head/cddl/usr.sbin/dtrace/tests/Makefile
  head/cddl/usr.sbin/dtrace/tests/tools/genmakefiles.sh
  head/etc/mtree/BSD.tests.dist

Added: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/tst.rax.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/tst.rax.c
Wed Jun  5 22:32:26 2019(r348706)
@@ -0,0 +1,43 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright (c) 2019 Mariusz Zaborski 
+ * Use is subject to license terms.
+ */
+
+__attribute__((optnone)) void
+frax(void)
+{
+   asm volatile("mov $0x41414141, %%rax"
+   : : : "rax"
+   );
+}
+
+int
+main(void)
+{
+
+   while (1) {
+   frax();
+   }
+   return (0);
+}

Added: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/tst.rax.d
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/tst.rax.d
Wed Jun  5 22:32:26 2019(r348706)
@@ -0,0 +1,36 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright (c) 2019 Mariusz Zaborski 
+ * Use is subject to license terms.
+ */
+
+#pragma D option quiet
+
+pid$1::frax:return / uregs[R_RAX] == 0x41414141 / {
+   exit(0);
+}
+
+pid$1::frax:return / uregs[R_RAX] != 0x41414141 / {
+   printf("wrong rax value: %d\n", uregs[R_RAX]);
+   exit(1);
+}

Added: 
head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/tst.uregsarray.d
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ 
head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/amd64/arrays/tst.uregsarray.d 
Wed Jun  5 22:32:26 2019(r348706)
@@ -0,0 +1,82 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr

svn commit: r348705 - head/sys/cddl/dev/dtrace/amd64

2019-06-05 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Jun  5 22:29:05 2019
New Revision: 348705
URL: https://svnweb.freebsd.org/changeset/base/348705

Log:
  dtrace: 64-bits registers support
  
  The registers in ilumos and FreeBSD have a different number.
  In the illumos, last 32-bits register defined is SS an in FreeBSD is GS.
  This off-by-one caused the uregs array to returns the wrong 64-bits register
  on amd64.
  
  Reviewed by:  markj
  MFC after:2 weeks
  Differential Revision:https://reviews.freebsd.org/D20363

Modified:
  head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c

Modified: head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c
==
--- head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c Wed Jun  5 21:46:56 2019
(r348704)
+++ head/sys/cddl/dev/dtrace/amd64/dtrace_isa.c Wed Jun  5 22:29:05 2019
(r348705)
@@ -514,7 +514,11 @@ dtrace_getreg(struct trapframe *rp, uint_t reg)
reg = regmap[reg];
} else {
/* This is dependent on reg.d. */
+#ifdef illumos
reg -= SS + 1;
+#else  /* !illumos */
+   reg -= GS + 1;
+#endif
}
 
switch (reg) {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r346322 - head/lib/libcasper/services/cap_fileargs

2019-04-19 Thread Mariusz Zaborski
On Wed, Apr 17, 2019 at 04:58:38PM +, Adrian Chadd wrote:
> Author: adrian
> Date: Wed Apr 17 16:58:38 2019
> New Revision: 346322
> URL: https://svnweb.freebsd.org/changeset/base/346322
> 
> Log:
>   [casper] fix compilation when casper is disabled.
>   
>   This triggers an error in gcc-mips 6.4.0 complaining about unused arguments.
>   
>   Tested:
>   
>   * compiled/run on mips32; nothing complained.
> 
> Modified:
>   head/lib/libcasper/services/cap_fileargs/cap_fileargs.h
> 
> Modified: head/lib/libcasper/services/cap_fileargs/cap_fileargs.h
> ==
> --- head/lib/libcasper/services/cap_fileargs/cap_fileargs.h   Wed Apr 17 
> 16:45:42 2019(r346321)
> +++ head/lib/libcasper/services/cap_fileargs/cap_fileargs.h   Wed Apr 17 
> 16:58:38 2019(r346322)
> @@ -108,8 +108,12 @@ fileargs_cinitnv(cap_channel_t *cas __unused, nvlist_t
>   lstat(name, sb)
>  #define  fileargs_open(fa, name) 
> \
>   open(name, fa->fa_flags, fa->fa_mode)
> -#define  fileargs_fopen(fa, name, mode)  
> \
> - fopen(name, mode)
> +static inline
> +FILE *fileargs_fopen(fileargs_t *fa, const char *name, const char *mode)
> +{
> + (void) fa;
__unused is not good enough?
> + return (fopen(name, mode));
> +}
>  #define  fileargs_free(fa)   (free(fa))
>  #endif
>  
> 

-- 
Mariusz Zaborski
oshogbo//vx | http://oshogbo.vexillium.org
FreeBSD committer   | https://freebsd.org
Software developer  | http://wheelsystems.com
If it's not broken, let's fix it till it is!!1


signature.asc
Description: PGP signature


svn commit: r346263 - head/contrib/tcpdump

2019-04-15 Thread Mariusz Zaborski
Author: oshogbo
Date: Tue Apr 16 04:12:41 2019
New Revision: 346263
URL: https://svnweb.freebsd.org/changeset/base/346263

Log:
  tcpdump: disable Capsicum if -E option is provided.
  
  The -E is used to provide a secret for decrypting IPsec.
  The secret may be provided through command line or as the file.
  The problem is that tcpdump doesn't support yet opening files in capability 
mode
  and the file may contain a list of the files to open.
  
  As a workaround, for now, let's just disable capsicum if the -E
  the option is provided.
  
  PR:   236819
  MFC after:2 weeks

Modified:
  head/contrib/tcpdump/tcpdump.c

Modified: head/contrib/tcpdump/tcpdump.c
==
--- head/contrib/tcpdump/tcpdump.c  Tue Apr 16 02:48:04 2019
(r346262)
+++ head/contrib/tcpdump/tcpdump.c  Tue Apr 16 04:12:41 2019
(r346263)
@@ -2063,7 +2063,8 @@ main(int argc, char **argv)
}
 
 #ifdef HAVE_CAPSICUM
-   cansandbox = (VFileName == NULL && zflag == NULL);
+   cansandbox = (VFileName == NULL && zflag == NULL &&
+   ndo->ndo_espsecret == NULL);
 #ifdef HAVE_CASPER
cansandbox = (cansandbox && (ndo->ndo_nflag || capdns != NULL));
 #else
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346219 - head/lib/libnv/tests

2019-04-14 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Apr 15 03:32:01 2019
New Revision: 346219
URL: https://svnweb.freebsd.org/changeset/base/346219

Log:
  libnv: extend the tests
  
  Add cases for sending file descriptors.
  
  Submitted by: Mindaugas Rasiukevicius 
  MFC after:2 weeks

Modified:
  head/lib/libnv/tests/nvlist_send_recv_test.c

Modified: head/lib/libnv/tests/nvlist_send_recv_test.c
==
--- head/lib/libnv/tests/nvlist_send_recv_test.cMon Apr 15 03:31:02 
2019(r346218)
+++ head/lib/libnv/tests/nvlist_send_recv_test.cMon Apr 15 03:32:01 
2019(r346219)
@@ -34,6 +34,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -58,6 +59,7 @@ child(int sock)
 {
nvlist_t *nvl;
nvlist_t *empty;
+   int pfd[2];
 
nvl = nvlist_create(0);
empty = nvlist_create(0);
@@ -73,7 +75,16 @@ child(int sock)
nvlist_add_string(nvl, "nvlist/string/", "");
nvlist_add_string(nvl, "nvlist/string/x", "x");
nvlist_add_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz", 
"abcdefghijklmnopqrstuvwxyz");
+
nvlist_add_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", 
STDERR_FILENO);
+   if (pipe(pfd) == -1)
+   err(EXIT_FAILURE, "pipe");
+   if (write(pfd[1], "test", 4) != 4)
+   err(EXIT_FAILURE, "write");
+   close(pfd[1]);
+   nvlist_add_descriptor(nvl, "nvlist/descriptor/pipe_rd", pfd[0]);
+   close(pfd[0]);
+
nvlist_add_binary(nvl, "nvlist/binary/x", "x", 1);
nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", 
"abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz"));
nvlist_move_nvlist(nvl, "nvlist/nvlist/empty", empty);
@@ -91,8 +102,9 @@ parent(int sock)
const nvlist_t *cnvl, *empty;
const char *name, *cname;
void *cookie, *ccookie;
-   int type, ctype;
+   int type, ctype, fd;
size_t size;
+   char buf[4];
 
nvl = nvlist_recv(sock, 0);
CHECK(nvlist_error(nvl) == 0);
@@ -175,6 +187,15 @@ parent(int sock)
 
name = nvlist_next(nvl, , );
CHECK(name != NULL);
+   CHECK(type == NV_TYPE_DESCRIPTOR);
+   CHECK(strcmp(name, "nvlist/descriptor/pipe_rd") == 0);
+   fd = nvlist_get_descriptor(nvl, name);
+   CHECK(fd_is_valid(fd));
+   CHECK(read(fd, buf, sizeof(buf)) == 4);
+   CHECK(strncmp(buf, "test", sizeof(buf)) == 0);
+
+   name = nvlist_next(nvl, , );
+   CHECK(name != NULL);
CHECK(type == NV_TYPE_BINARY);
CHECK(strcmp(name, "nvlist/binary/x") == 0);
CHECK(memcmp(nvlist_get_binary(nvl, name, NULL), "x", 1) == 0);
@@ -278,6 +299,12 @@ parent(int sock)
 
cname = nvlist_next(cnvl, , );
CHECK(cname != NULL);
+   CHECK(ctype == NV_TYPE_DESCRIPTOR);
+   CHECK(strcmp(cname, "nvlist/descriptor/pipe_rd") == 0);
+   CHECK(fd_is_valid(nvlist_get_descriptor(cnvl, cname)));
+
+   cname = nvlist_next(cnvl, , );
+   CHECK(cname != NULL);
CHECK(ctype == NV_TYPE_BINARY);
CHECK(strcmp(cname, "nvlist/binary/x") == 0);
CHECK(memcmp(nvlist_get_binary(cnvl, cname, NULL), "x", 1) == 0);
@@ -359,7 +386,7 @@ int
 main(void)
 {
 
-   printf("1..136\n");
+   printf("1..146\n");
fflush(stdout);
 
send_nvlist();
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346218 - head/lib/libnv

2019-04-14 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Apr 15 03:31:02 2019
New Revision: 346218
URL: https://svnweb.freebsd.org/changeset/base/346218

Log:
  libnv: add support for nvlist_send()/nvlist_recv() on Linux
  
  This may be useful for cross build in the feature.
  
  Submitted by: Mindaugas Rasiukevicius 
  MFC after:2 weeks

Modified:
  head/lib/libnv/msgio.c

Modified: head/lib/libnv/msgio.c
==
--- head/lib/libnv/msgio.c  Mon Apr 15 01:27:15 2019(r346217)
+++ head/lib/libnv/msgio.c  Mon Apr 15 03:31:02 2019(r346218)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -58,7 +59,12 @@ __FBSDID("$FreeBSD$");
 #definePJDLOG_ABORT(...)   abort()
 #endif
 
+#ifdef __linux__
+/* Linux: arbitrary size, but must be lower than SCM_MAX_FD. */
+#definePKG_MAX_SIZE((64U - 1) * CMSG_SPACE(sizeof(int)))
+#else
 #definePKG_MAX_SIZE(MCLBYTES / CMSG_SPACE(sizeof(int)) - 1)
+#endif
 
 static int
 msghdr_add_fd(struct cmsghdr *cmsg, int fd)
@@ -74,31 +80,6 @@ msghdr_add_fd(struct cmsghdr *cmsg, int fd)
return (0);
 }
 
-static int
-msghdr_get_fd(struct cmsghdr *cmsg)
-{
-   int fd;
-
-   if (cmsg == NULL || cmsg->cmsg_level != SOL_SOCKET ||
-   cmsg->cmsg_type != SCM_RIGHTS ||
-   cmsg->cmsg_len != CMSG_LEN(sizeof(fd))) {
-   errno = EINVAL;
-   return (-1);
-   }
-
-   bcopy(CMSG_DATA(cmsg), , sizeof(fd));
-#ifndef MSG_CMSG_CLOEXEC
-   /*
-* If the MSG_CMSG_CLOEXEC flag is not available we cannot set the
-* close-on-exec flag atomically, but we still want to set it for
-* consistency.
-*/
-   (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
-#endif
-
-   return (fd);
-}
-
 static void
 fd_wait(int fd, bool doread)
 {
@@ -157,14 +138,7 @@ msg_send(int sock, const struct msghdr *msg)
return (0);
 }
 
-/*
- * MacOS/Linux do not define struct cmsgcred but we need to bootstrap libnv
- * when building on non-FreeBSD systems. Since they are not used during
- * bootstrap we can just omit these two functions there.
- */
-#ifndef __FreeBSD__
-#warning "cred_send() not supported on non-FreeBSD systems"
-#else
+#ifdef __FreeBSD__
 int
 cred_send(int sock)
 {
@@ -326,29 +300,53 @@ fd_package_recv(int sock, int *fds, size_t nfds)
if (msg_recv(sock, ) == -1)
goto end;
 
-   for (i = 0, cmsg = CMSG_FIRSTHDR(); i < nfds && cmsg != NULL;
-   i++, cmsg = CMSG_NXTHDR(, cmsg)) {
-   fds[i] = msghdr_get_fd(cmsg);
-   if (fds[i] < 0)
+   i = 0;
+   cmsg = CMSG_FIRSTHDR();
+   while (cmsg && i < nfds) {
+   unsigned int n;
+
+   if (cmsg->cmsg_level != SOL_SOCKET ||
+   cmsg->cmsg_type != SCM_RIGHTS) {
+   errno = EINVAL;
break;
+   }
+   n = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
+   if (i + n > nfds) {
+   errno = EINVAL;
+   break;
+   }
+   bcopy(CMSG_DATA(cmsg), fds + i, sizeof(int) * n);
+   cmsg = CMSG_NXTHDR(, cmsg);
+   i += n;
}
 
if (cmsg != NULL || i < nfds) {
-   int fd;
+   unsigned int last;
 
/*
 * We need to close all received descriptors, even if we have
 * different control message (eg. SCM_CREDS) in between.
 */
-   for (cmsg = CMSG_FIRSTHDR(); cmsg != NULL;
-   cmsg = CMSG_NXTHDR(, cmsg)) {
-   fd = msghdr_get_fd(cmsg);
-   if (fd >= 0)
-   close(fd);
+   last = i;
+   for (i = 0; i < last; i++) {
+   if (fds[i] >= 0) {
+   close(fds[i]);
+   }
}
errno = EINVAL;
goto end;
}
+
+#ifndef MSG_CMSG_CLOEXEC
+   /*
+* If the MSG_CMSG_CLOEXEC flag is not available we cannot set the
+* close-on-exec flag atomically, but we still want to set it for
+* consistency.
+*/
+   for (i = 0; i < nfds; i++) {
+   (void) fcntl(fds[i], F_SETFD, FD_CLOEXEC);
+   }
+#endif
 
ret = 0;
 end:
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r345875 - in head: contrib/elftoolchain/strings usr.bin/strings

2019-04-14 Thread Mariusz Zaborski
On Sun, Apr 14, 2019 at 08:19:22AM -0700, Adrian Chadd wrote:
> This exposed a fun bug - gcc mips 6.4.0 complains about an unused arg (fa)
> in fileargs_fopen() in the strings change when you compile without casper
> support. I do that on mips.
> 
> I have a local change that converts the #define to an inline function so
> the unused arg can be (void)'ed away. Mind if I commit it?
Sounds good to me.
Although you don't have an issue with others services?

-- 
Mariusz Zaborski
oshogbo//vx | http://oshogbo.vexillium.org
FreeBSD committer   | https://freebsd.org
Software developer  | http://wheelsystems.com
If it's not broken, let's fix it till it is!!1

> 
> On Thu, 4 Apr 2019 at 09:32, Mariusz Zaborski  wrote:
> 
> > Author: oshogbo
> > Date: Thu Apr  4 16:32:27 2019
> > New Revision: 345875
> > URL: https://svnweb.freebsd.org/changeset/base/345875
> >
> > Log:
> >   strings: capsicumize it
> >
> >   Reviewed by:  cem
> >   Discussed with: emaste
> >   Differential Revision:https://reviews.freebsd.org/D18038
> >
> > Modified:
> >   head/contrib/elftoolchain/strings/strings.c
> >   head/usr.bin/strings/Makefile
> >
> > Modified: head/contrib/elftoolchain/strings/strings.c
> >
> > ==
> > --- head/contrib/elftoolchain/strings/strings.c Thu Apr  4 12:02:48 2019
> >   (r345874)
> > +++ head/contrib/elftoolchain/strings/strings.c Thu Apr  4 16:32:27 2019
> >   (r345875)
> > @@ -25,8 +25,10 @@
> >   */
> >
> >  #include 
> > +#include 
> >  #include 
> >
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -44,6 +46,9 @@
> >  #include 
> >  #include 
> >
> > +#include 
> > +#include 
> > +
> >  #include "_elftc.h"
> >
> >  ELFTC_VCSID("$Id: strings.c 3648 2018-11-22 23:26:43Z emaste $");
> > @@ -85,7 +90,7 @@ static struct option strings_longopts[] = {
> >  };
> >
> >  intgetcharacter(FILE *, long *);
> > -inthandle_file(const char *);
> > +inthandle_file(fileargs_t *fa, const char *);
> >  inthandle_elf(const char *, FILE *);
> >  inthandle_binary(const char *, FILE *, size_t);
> >  intfind_strings(const char *, FILE *, off_t, off_t);
> > @@ -99,6 +104,8 @@ void usage(void);
> >  int
> >  main(int argc, char **argv)
> >  {
> > +   fileargs_t *fa;
> > +   cap_rights_t rights;
> > int ch, rc;
> >
> > rc = 0;
> > @@ -187,27 +194,41 @@ main(int argc, char **argv)
> > argc -= optind;
> > argv += optind;
> >
> > +   cap_rights_init(, CAP_READ, CAP_SEEK, CAP_FSTAT, CAP_FCNTL);
> > +   fa = fileargs_init(argc, argv, O_RDONLY, 0, );
> > +   if (fa == NULL)
> > +   err(1, "Unable to initialize casper fileargs");
> > +
> > +   caph_cache_catpages();
> > +   if (caph_limit_stdio() < 0 && caph_enter_casper() < 0) {
> > +   fileargs_free(fa);
> > +   err(1, "Unable to enter capability mode");
> > +   }
> > +
> > if (min_len == 0)
> > min_len = 4;
> > if (*argv == NULL)
> > rc = find_strings("{standard input}", stdin, 0, 0);
> > else while (*argv != NULL) {
> > -   if (handle_file(*argv) != 0)
> > +   if (handle_file(fa, *argv) != 0)
> > rc = 1;
> > argv++;
> > }
> > +
> > +   fileargs_free(fa);
> > +
> > return (rc);
> >  }
> >
> >  int
> > -handle_file(const char *name)
> > +handle_file(fileargs_t *fa, const char *name)
> >  {
> > FILE *pfile;
> > int rt;
> >
> > if (name == NULL)
> > return (1);
> > -   pfile = fopen(name, "rb");
> > +   pfile = fileargs_fopen(fa, name, "rb");
> > if (pfile == NULL) {
> > warnx("'%s': %s", name, strerror(errno));
> > return (1);
> >
> > Modified: head/usr.bin/strings/Makefile
> >
> > ==
> > --- head/usr.bin/strings/Makefile   Thu Apr  4 12:02:48 2019
> > (r345874)
> > +++ head/usr.bin/strings/Makefile   Thu Apr  4 16:32:27 2019
> > (r345875)
> > @@ -10,6 +10,12 @@ PROG=strings
> >
> >  LIBADD=elftc elf
> >
> > +.if ${MK_CASPER} != "no" && !defined(BOOTSTRAPPING)
> > +LIBADD+=   casper
> > +LIBADD+=   cap_fileargs
> > +CFLAGS+=   -DWITH_CASPER
> > +.endif
> > +
> >  CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
> >
> >  .include 
> >
> >


signature.asc
Description: PGP signature


svn commit: r346115 - head/sys/contrib/libnv

2019-04-10 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr 11 04:24:41 2019
New Revision: 346115
URL: https://svnweb.freebsd.org/changeset/base/346115

Log:
  The nvlist_report_missing is also used by the cnvlist.
  It can't be a static one.
  
  Reported by:  jenkins
  MFC after:2 weeks

Modified:
  head/sys/contrib/libnv/nvlist.c

Modified: head/sys/contrib/libnv/nvlist.c
==
--- head/sys/contrib/libnv/nvlist.c Thu Apr 11 04:22:06 2019
(r346114)
+++ head/sys/contrib/libnv/nvlist.c Thu Apr 11 04:24:41 2019
(r346115)
@@ -324,7 +324,7 @@ nvlist_set_flags(nvlist_t *nvl, int flags)
nvl->nvl_flags = flags;
 }
 
-static void
+void
 nvlist_report_missing(int type, const char *name)
 {
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346113 - head/sys/contrib/libnv

2019-04-10 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr 11 04:21:58 2019
New Revision: 346113
URL: https://svnweb.freebsd.org/changeset/base/346113

Log:
  libnv: fix compilation warnings
  
  When building libnv without a debug those arguments are no longer used
  because assertions will be changed to NOP.
  
  Submitted by: Mindaugas Rasiukevicius 
  MFC after:2 weeks

Modified:
  head/sys/contrib/libnv/nvpair.c

Modified: head/sys/contrib/libnv/nvpair.c
==
--- head/sys/contrib/libnv/nvpair.c Thu Apr 11 03:47:53 2019
(r346112)
+++ head/sys/contrib/libnv/nvpair.c Thu Apr 11 04:21:58 2019
(r346113)
@@ -108,7 +108,7 @@ struct nvpair_header {
 
 
 void
-nvpair_assert(const nvpair_t *nvp)
+nvpair_assert(const nvpair_t *nvp __unused)
 {
 
NVPAIR_ASSERT(nvp);
@@ -235,7 +235,8 @@ nvpair_remove_nvlist_array(nvpair_t *nvp)
 }
 
 void
-nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl)
+nvpair_remove(struct nvl_head *head, nvpair_t *nvp,
+const nvlist_t *nvl __unused)
 {
 
NVPAIR_ASSERT(nvp);
@@ -359,7 +360,7 @@ nvpair_pack_header(const nvpair_t *nvp, unsigned char 
 }
 
 unsigned char *
-nvpair_pack_null(const nvpair_t *nvp, unsigned char *ptr,
+nvpair_pack_null(const nvpair_t *nvp __unused, unsigned char *ptr,
 size_t *leftp __unused)
 {
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346112 - head/sys/contrib/libnv

2019-04-10 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr 11 03:47:53 2019
New Revision: 346112
URL: https://svnweb.freebsd.org/changeset/base/346112

Log:
  libnv: fix compilation warnings
  
  When building libnv without a debug those arguments are no longer used
  because assertions will be changed to NOP.
  
  Submitted by: Mindaugas Rasiukevicius 
  MFC after:2 weeks

Modified:
  head/sys/contrib/libnv/nvlist.c

Modified: head/sys/contrib/libnv/nvlist.c
==
--- head/sys/contrib/libnv/nvlist.c Thu Apr 11 00:41:07 2019
(r346111)
+++ head/sys/contrib/libnv/nvlist.c Thu Apr 11 03:47:53 2019
(r346112)
@@ -324,7 +324,7 @@ nvlist_set_flags(nvlist_t *nvl, int flags)
nvl->nvl_flags = flags;
 }
 
-void
+static void
 nvlist_report_missing(int type, const char *name)
 {
 
@@ -1374,7 +1374,7 @@ nvlist_first_nvpair(const nvlist_t *nvl)
 }
 
 nvpair_t *
-nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
+nvlist_next_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
 {
nvpair_t *retnvp;
 
@@ -1390,7 +1390,7 @@ nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t
 }
 
 nvpair_t *
-nvlist_prev_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
+nvlist_prev_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
 {
nvpair_t *retnvp;
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346029 - head/sys/kern

2019-04-08 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Apr  8 14:23:52 2019
New Revision: 346029
URL: https://svnweb.freebsd.org/changeset/base/346029

Log:
  In the unlinkat syscall, the operation is performed on the directory
  descriptor, not the file descriptor. The file descriptor is used only for
  verification so do not expect any additional capabilities on it.
  
  Reported by:  antoine
  Tested by:antoine
  Discussed with:   kib, emaste, bapt
  Sponsored by: Fudo Security

Modified:
  head/sys/kern/vfs_syscalls.c

Modified: head/sys/kern/vfs_syscalls.c
==
--- head/sys/kern/vfs_syscalls.cMon Apr  8 13:40:46 2019
(r346028)
+++ head/sys/kern/vfs_syscalls.cMon Apr  8 14:23:52 2019
(r346029)
@@ -1809,13 +1809,11 @@ kern_funlinkat(struct thread *td, int dfd, const char 
struct vnode *vp;
struct nameidata nd;
struct stat sb;
-   cap_rights_t rights;
int error;
 
fp = NULL;
if (fd != FD_NONE) {
-   error = getvnode(td, fd, cap_rights_init(, CAP_LOOKUP),
-   );
+   error = getvnode(td, fd, _no_rights, );
if (error != 0)
return (error);
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346023 - head/usr.bin/strings

2019-04-07 Thread Mariusz Zaborski
Author: oshogbo
Date: Mon Apr  8 03:35:47 2019
New Revision: 346023
URL: https://svnweb.freebsd.org/changeset/base/346023

Log:
  strings: disable Casper support while building native-xtools
  
  Reported by:  Charlie Li
  Tested by:Charlie Li

Modified:
  head/usr.bin/strings/Makefile

Modified: head/usr.bin/strings/Makefile
==
--- head/usr.bin/strings/Makefile   Sun Apr  7 21:01:02 2019
(r346022)
+++ head/usr.bin/strings/Makefile   Mon Apr  8 03:35:47 2019
(r346023)
@@ -10,7 +10,7 @@ PROG= strings
 
 LIBADD=elftc elf
 
-.if ${MK_CASPER} != "no" && !defined(BOOTSTRAPPING)
+.if ${MK_CASPER} != "no" && !defined(BOOTSTRAPPING) && !defined(NXB_TARGET)
 LIBADD+=   casper
 LIBADD+=   cap_fileargs
 CFLAGS+=   -DWITH_CASPER
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r345982 - in head: include lib/libc/sys sys/cddl/compat/opensolaris/sys sys/compat/cloudabi sys/compat/freebsd32 sys/compat/linux sys/kern sys/sys sys/ufs/ffs

2019-04-07 Thread Mariusz Zaborski
In the https://wiki.freebsd.org/AddingSyscalls we mentions that we need to bump
__FreeBSD_version. I confirmed that with Warner. So this was my mistake.

Thanks Shawn.
-- 
Mariusz Zaborski
oshogbo//vx | http://oshogbo.vexillium.org
FreeBSD committer   | https://freebsd.org
Software developer  | http://wheelsystems.com
If it's not broken, let's fix it till it is!!1

On Sun, Apr 07, 2019 at 08:35:07AM -0700, Cy Schubert wrote:
> In message <201904071510.x37fa7tm050...@gndrsh.dnsmgr.net>, "Rodney W. 
> Grimes"
> writes:
> > > On April 7, 2019 7:11:52 AM PDT, Shawn Webb  
> > > wr
> > ote:
> > > >On Sat, Apr 06, 2019 at 09:34:26AM +, Mariusz Zaborski wrote:
> > > >> Author: oshogbo
> > > >> Date: Sat Apr  6 09:34:26 2019
> > > >> New Revision: 345982
> > > >> URL: https://svnweb.freebsd.org/changeset/base/345982
> > > >> 
> > > >> Log:
> > > >>   Introduce funlinkat syscall that always us to check if we are
> > > >removing
> > > >>   the file associated with the given file descriptor.
> > > >>   
> > > >>   Reviewed by: kib, asomers
> > > >>   Reviewed by: cem, jilles, brooks (they reviewed previous version)
> > > >>   Discussed with:  pjd, and many others
> > > >>   Differential Revision:   https://reviews.freebsd.org/D14567
> > > >
> > > >Hey Mariusz,
> > > >
> > > >Is __FreeBSD_version supposed to be bumped after adding new syscalls?
> > > >I can't remember off-hand.
> > > >
> > > >Thanks,
> > > 
> > > I don't think so. Why force the rebuild of all ports through poudriere 
> > > over
> >  something that would never affect any of them?
> >
> > So that you can if version >= foo to know it is safe to use the new syscal?
> > Or if version  < foo you must use the old way.
> 
> Granted. However we do need something to avoid gratuitous rebuilds of 
> ports.
> 
> Personally, my poudriere script adjusts the pkg version 
> ($JAILPATH/data/packages/${JAIL}-${PORTS}/.building/.jailversion) with 
> that of the jail version (reported by poudriere jail -i -j $JAIL), 
> rebuilding all ports when I (the human) determines when the machine 
> should rebuild all ports with -c.
> 
> In that regard FreeBSD version bumps occasionally seem a little 
> gratuitous. Using the same indicator to tell whether software should be 
> able to use a new feature and when ports build infrastructure should 
> summarily delete all packages forcing a rebuild of absolutely 
> everything is probably not the best.
> 
> Just throwing out an idea, what if poudriere considers the first N 
> bytes of __FreeBSD_version significant? Having said that, looking at 
> __FreeBSD_version, I don't think we have enough digits to do what I was 
> planning on suggesting. But, you get the idea of what I'm driving at. 
> Maybe a new macro such as __FreeBSD_ports that is incremented every 
> time a change that affects ports?
> 
> Anyhow, I'm not too terribly concerned as what I have (selfishly 
> speaking) works. But we may as a group might want to consider this at 
> some point to build some efficiency into the ports part of the equation.
> 
> 
> -- 
> Cheers,
> Cy Schubert 
> FreeBSD UNIX: Web:  http://www.FreeBSD.org
> 
>   The need of the many outweighs the greed of the few.
>  
> 


signature.asc
Description: PGP signature


svn commit: r346012 - head/sys/sys

2019-04-07 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Apr  7 16:07:41 2019
New Revision: 346012
URL: https://svnweb.freebsd.org/changeset/base/346012

Log:
  Bump FreeBSD version after r345982.
  
  Reported by:  Shawn Webb 
  Discussed with: imp, cy, rgrimes

Modified:
  head/sys/sys/param.h

Modified: head/sys/sys/param.h
==
--- head/sys/sys/param.hSun Apr  7 14:30:17 2019(r346011)
+++ head/sys/sys/param.hSun Apr  7 16:07:41 2019(r346012)
@@ -60,7 +60,7 @@
  * in the range 5 to 9.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1300017  /* Master, propagated to newvers */
+#define __FreeBSD_version 1300018  /* Master, propagated to newvers */
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r345984 - head/lib/libutil

2019-04-06 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Apr  6 11:24:43 2019
New Revision: 345984
URL: https://svnweb.freebsd.org/changeset/base/345984

Log:
  Use funlinkat in pidfile to ensure we are removing the right file.

Modified:
  head/lib/libutil/pidfile.c

Modified: head/lib/libutil/pidfile.c
==
--- head/lib/libutil/pidfile.c  Sat Apr  6 09:37:10 2019(r345983)
+++ head/lib/libutil/pidfile.c  Sat Apr  6 11:24:43 2019(r345984)
@@ -293,8 +293,11 @@ _pidfile_remove(struct pidfh *pfh, int freeit)
return (-1);
}
 
-   if (unlinkat(pfh->pf_dirfd, pfh->pf_filename, 0) == -1)
+   if (funlinkat(pfh->pf_dirfd, pfh->pf_filename, pfh->pf_fd, 0) == -1) {
+   if (errno == EDEADLK)
+   return (-1);
error = errno;
+   }
if (close(pfh->pf_fd) == -1 && error == 0)
error = errno;
if (close(pfh->pf_dirfd) == -1 && error == 0)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r345983 - in head/sys: compat/freebsd32 kern sys

2019-04-06 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Apr  6 09:37:10 2019
New Revision: 345983
URL: https://svnweb.freebsd.org/changeset/base/345983

Log:
  Regen after r345982.

Modified:
  head/sys/compat/freebsd32/freebsd32_syscall.h
  head/sys/compat/freebsd32/freebsd32_syscalls.c
  head/sys/compat/freebsd32/freebsd32_sysent.c
  head/sys/compat/freebsd32/freebsd32_systrace_args.c
  head/sys/kern/init_sysent.c
  head/sys/kern/syscalls.c
  head/sys/kern/systrace_args.c
  head/sys/sys/syscall.h
  head/sys/sys/syscall.mk
  head/sys/sys/sysproto.h

Modified: head/sys/compat/freebsd32/freebsd32_syscall.h
==
--- head/sys/compat/freebsd32/freebsd32_syscall.h   Sat Apr  6 09:34:26 
2019(r345982)
+++ head/sys/compat/freebsd32/freebsd32_syscall.h   Sat Apr  6 09:37:10 
2019(r345983)
@@ -494,4 +494,5 @@
 #defineFREEBSD32_SYS_fhlink565
 #defineFREEBSD32_SYS_fhlinkat  566
 #defineFREEBSD32_SYS_fhreadlink567
-#defineFREEBSD32_SYS_MAXSYSCALL568
+#defineFREEBSD32_SYS_funlinkat 568
+#defineFREEBSD32_SYS_MAXSYSCALL569

Modified: head/sys/compat/freebsd32/freebsd32_syscalls.c
==
--- head/sys/compat/freebsd32/freebsd32_syscalls.c  Sat Apr  6 09:34:26 
2019(r345982)
+++ head/sys/compat/freebsd32/freebsd32_syscalls.c  Sat Apr  6 09:37:10 
2019(r345983)
@@ -604,4 +604,5 @@ const char *freebsd32_syscallnames[] = {
"fhlink",   /* 565 = fhlink */
"fhlinkat", /* 566 = fhlinkat */
"fhreadlink",   /* 567 = fhreadlink */
+   "funlinkat",/* 568 = funlinkat */
 };

Modified: head/sys/compat/freebsd32/freebsd32_sysent.c
==
--- head/sys/compat/freebsd32/freebsd32_sysent.cSat Apr  6 09:34:26 
2019(r345982)
+++ head/sys/compat/freebsd32/freebsd32_sysent.cSat Apr  6 09:37:10 
2019(r345983)
@@ -651,4 +651,5 @@ struct sysent freebsd32_sysent[] = {
{ AS(fhlink_args), (sy_call_t *)sys_fhlink, AUE_NULL, NULL, 0, 0, 0, 
SY_THR_STATIC },   /* 565 = fhlink */
{ AS(fhlinkat_args), (sy_call_t *)sys_fhlinkat, AUE_NULL, NULL, 0, 0, 
0, SY_THR_STATIC },   /* 566 = fhlinkat */
{ AS(fhreadlink_args), (sy_call_t *)sys_fhreadlink, AUE_NULL, NULL, 0, 
0, 0, SY_THR_STATIC },   /* 567 = fhreadlink */
+   { AS(funlinkat_args), (sy_call_t *)sys_funlinkat, AUE_UNLINKAT, NULL, 
0, 0, SYF_CAPENABLED, SY_THR_STATIC },/* 568 = funlinkat */
 };

Modified: head/sys/compat/freebsd32/freebsd32_systrace_args.c
==
--- head/sys/compat/freebsd32/freebsd32_systrace_args.c Sat Apr  6 09:34:26 
2019(r345982)
+++ head/sys/compat/freebsd32/freebsd32_systrace_args.c Sat Apr  6 09:37:10 
2019(r345983)
@@ -3310,6 +3310,16 @@ systrace_args(int sysnum, void *params, uint64_t *uarg
*n_args = 3;
break;
}
+   /* funlinkat */
+   case 568: {
+   struct funlinkat_args *p = params;
+   iarg[0] = p->dfd; /* int */
+   uarg[1] = (intptr_t) p->path; /* const char * */
+   iarg[2] = p->fd; /* int */
+   iarg[3] = p->flag; /* int */
+   *n_args = 4;
+   break;
+   }
default:
*n_args = 0;
break;
@@ -8905,6 +8915,25 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *d
break;
};
break;
+   /* funlinkat */
+   case 568:
+   switch(ndx) {
+   case 0:
+   p = "int";
+   break;
+   case 1:
+   p = "userland const char *";
+   break;
+   case 2:
+   p = "int";
+   break;
+   case 3:
+   p = "int";
+   break;
+   default:
+   break;
+   };
+   break;
default:
break;
};
@@ -10771,6 +10800,11 @@ systrace_return_setargdesc(int sysnum, int ndx, char *
break;
/* fhreadlink */
case 567:
+   if (ndx == 0 || ndx == 1)
+   p = "int";
+   break;
+   /* funlinkat */
+   case 568:
if (ndx == 0 || ndx == 1)
p = "int";
break;

Modified: head/sys/kern/init_sysent.c
==
--- head/sys/kern/init_sysent.c Sat Apr  6 09:34:26 2019(r345982)
+++ head/sys/kern/init_sysent.c Sat Apr  6 

svn commit: r345982 - in head: include lib/libc/sys sys/cddl/compat/opensolaris/sys sys/compat/cloudabi sys/compat/freebsd32 sys/compat/linux sys/kern sys/sys sys/ufs/ffs

2019-04-06 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Apr  6 09:34:26 2019
New Revision: 345982
URL: https://svnweb.freebsd.org/changeset/base/345982

Log:
  Introduce funlinkat syscall that always us to check if we are removing
  the file associated with the given file descriptor.
  
  Reviewed by:  kib, asomers
  Reviewed by:  cem, jilles, brooks (they reviewed previous version)
  Discussed with:   pjd, and many others
  Differential Revision:https://reviews.freebsd.org/D14567

Modified:
  head/include/unistd.h
  head/lib/libc/sys/Makefile.inc
  head/lib/libc/sys/Symbol.map
  head/lib/libc/sys/unlink.2
  head/sys/cddl/compat/opensolaris/sys/vnode.h
  head/sys/compat/cloudabi/cloudabi_file.c
  head/sys/compat/freebsd32/syscalls.master
  head/sys/compat/linux/linux_file.c
  head/sys/kern/capabilities.conf
  head/sys/kern/syscalls.master
  head/sys/kern/vfs_mountroot.c
  head/sys/kern/vfs_syscalls.c
  head/sys/sys/fcntl.h
  head/sys/sys/syscallsubr.h
  head/sys/ufs/ffs/ffs_alloc.c

Modified: head/include/unistd.h
==
--- head/include/unistd.h   Sat Apr  6 09:00:06 2019(r345981)
+++ head/include/unistd.h   Sat Apr  6 09:34:26 2019(r345982)
@@ -585,6 +585,7 @@ off_t__syscall(quad_t, ...);
 int undelete(const char *);
 int unwhiteout(const char *);
 void   *valloc(size_t);/* obsoleted by malloc() */
+int funlinkat(int, const char *, int, int);
 
 #ifndef _OPTRESET_DECLARED
 #define_OPTRESET_DECLARED

Modified: head/lib/libc/sys/Makefile.inc
==
--- head/lib/libc/sys/Makefile.inc  Sat Apr  6 09:00:06 2019
(r345981)
+++ head/lib/libc/sys/Makefile.inc  Sat Apr  6 09:34:26 2019
(r345982)
@@ -485,6 +485,7 @@ MLINKS+=timer_settime.2 timer_getoverrun.2 \
 MLINKS+=thr_kill.2 thr_kill2.2
 MLINKS+=truncate.2 ftruncate.2
 MLINKS+=unlink.2 unlinkat.2
+MLINKS+=unlink.2 funlinkat.2
 MLINKS+=utimensat.2 futimens.2
 MLINKS+=utimes.2 futimes.2 \
utimes.2 futimesat.2 \

Modified: head/lib/libc/sys/Symbol.map
==
--- head/lib/libc/sys/Symbol.mapSat Apr  6 09:00:06 2019
(r345981)
+++ head/lib/libc/sys/Symbol.mapSat Apr  6 09:34:26 2019
(r345982)
@@ -406,6 +406,7 @@ FBSD_1.6 {
fhlinkat;
fhreadlink;
getfhat;
+   funlinkat;
 };
 
 FBSDprivate_1.0 {

Modified: head/lib/libc/sys/unlink.2
==
--- head/lib/libc/sys/unlink.2  Sat Apr  6 09:00:06 2019(r345981)
+++ head/lib/libc/sys/unlink.2  Sat Apr  6 09:34:26 2019(r345982)
@@ -28,7 +28,7 @@
 .\" @(#)unlink.2   8.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd November 11, 2018
+.Dd April 6, 2019
 .Dt UNLINK 2
 .Os
 .Sh NAME
@@ -42,7 +42,9 @@
 .Ft int
 .Fn unlink "const char *path"
 .Ft int
-.Fn unlinkat "int fd" "const char *path" "int flag"
+.Fn unlinkat "int dfd" "const char *path" "int flag"
+.Ft int
+.Fn funlinkat "int dfd" "const char *path" "int fd" "int flag"
 .Sh DESCRIPTION
 The
 .Fn unlink
@@ -74,7 +76,7 @@ except in the case where
 specifies a relative path.
 In this case the directory entry to be removed is determined
 relative to the directory associated with the file descriptor
-.Fa fd
+.Fa dfd
 instead of the current working directory.
 .Pp
 The values for
@@ -113,6 +115,26 @@ or
 respectively, depending on whether or not the
 .Dv AT_REMOVEDIR
 bit is set in flag.
+.Pp
+The
+.Fn funlinkat
+system call can be used to unlink an already-opened file, unless that
+file has been replaced since it was opened.
+It is equivalent to
+.Fn unlinkat
+in the case where
+.Fa path
+is already open as the file descriptor
+.Fa fd .
+Otherwise, the path will not be removed and an error will be returned.
+The
+.Fa fd
+can be set the
+.Dv FD_NONE .
+In that case
+.Fn funlinkat
+behaves exactly like
+.Fn unlinkat .
 .Sh RETURN VALUES
 .Rv -std unlink
 .Sh ERRORS
@@ -227,6 +249,15 @@ or the relative
 .Fa path
 escapes it.
 .El
+.Pp
+In addition to the errors returned by
+.Fn unlinkat ,
+.Fn funlinkat
+may fail if:
+.Bl -tag -width Er
+.It Bq Er EDEADLK
+The file descriptor is not associated with the path.
+.El
 .Sh SEE ALSO
 .Xr chflags 2 ,
 .Xr close 2 ,
@@ -246,6 +277,10 @@ The
 .Fn unlinkat
 system call appeared in
 .Fx 8.0 .
+The
+.Fn funlinkat
+system call appeared in
+.Fx 13.0 .
 .Pp
 The
 .Fn unlink

Modified: head/sys/cddl/compat/opensolaris/sys/vnode.h
==
--- head/sys/cddl/compat/opensolaris/sys/vnode.hSat Apr  6 09:00:06 
2019(r345981)
+++ head/sys/cddl/compat/opensolaris/sys/vnode.hSat Apr  6 09:34:26 
2019(r345982)
@@ -278,7 +278,8 @@ vn_remove(char *fnamep, enum uio_seg seg, enum rm dirf
ASSERT(seg == 

svn commit: r345875 - in head: contrib/elftoolchain/strings usr.bin/strings

2019-04-04 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr  4 16:32:27 2019
New Revision: 345875
URL: https://svnweb.freebsd.org/changeset/base/345875

Log:
  strings: capsicumize it
  
  Reviewed by:  cem
  Discussed with: emaste
  Differential Revision:https://reviews.freebsd.org/D18038

Modified:
  head/contrib/elftoolchain/strings/strings.c
  head/usr.bin/strings/Makefile

Modified: head/contrib/elftoolchain/strings/strings.c
==
--- head/contrib/elftoolchain/strings/strings.c Thu Apr  4 12:02:48 2019
(r345874)
+++ head/contrib/elftoolchain/strings/strings.c Thu Apr  4 16:32:27 2019
(r345875)
@@ -25,8 +25,10 @@
  */
 
 #include 
+#include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -44,6 +46,9 @@
 #include 
 #include 
 
+#include 
+#include 
+
 #include "_elftc.h"
 
 ELFTC_VCSID("$Id: strings.c 3648 2018-11-22 23:26:43Z emaste $");
@@ -85,7 +90,7 @@ static struct option strings_longopts[] = {
 };
 
 intgetcharacter(FILE *, long *);
-inthandle_file(const char *);
+inthandle_file(fileargs_t *fa, const char *);
 inthandle_elf(const char *, FILE *);
 inthandle_binary(const char *, FILE *, size_t);
 intfind_strings(const char *, FILE *, off_t, off_t);
@@ -99,6 +104,8 @@ void usage(void);
 int
 main(int argc, char **argv)
 {
+   fileargs_t *fa;
+   cap_rights_t rights;
int ch, rc;
 
rc = 0;
@@ -187,27 +194,41 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
 
+   cap_rights_init(, CAP_READ, CAP_SEEK, CAP_FSTAT, CAP_FCNTL);
+   fa = fileargs_init(argc, argv, O_RDONLY, 0, );
+   if (fa == NULL)
+   err(1, "Unable to initialize casper fileargs");
+
+   caph_cache_catpages();
+   if (caph_limit_stdio() < 0 && caph_enter_casper() < 0) {
+   fileargs_free(fa);
+   err(1, "Unable to enter capability mode");
+   }
+
if (min_len == 0)
min_len = 4;
if (*argv == NULL)
rc = find_strings("{standard input}", stdin, 0, 0);
else while (*argv != NULL) {
-   if (handle_file(*argv) != 0)
+   if (handle_file(fa, *argv) != 0)
rc = 1;
argv++;
}
+
+   fileargs_free(fa);
+
return (rc);
 }
 
 int
-handle_file(const char *name)
+handle_file(fileargs_t *fa, const char *name)
 {
FILE *pfile;
int rt;
 
if (name == NULL)
return (1);
-   pfile = fopen(name, "rb");
+   pfile = fileargs_fopen(fa, name, "rb");
if (pfile == NULL) {
warnx("'%s': %s", name, strerror(errno));
return (1);

Modified: head/usr.bin/strings/Makefile
==
--- head/usr.bin/strings/Makefile   Thu Apr  4 12:02:48 2019
(r345874)
+++ head/usr.bin/strings/Makefile   Thu Apr  4 16:32:27 2019
(r345875)
@@ -10,6 +10,12 @@ PROG=strings
 
 LIBADD=elftc elf
 
+.if ${MK_CASPER} != "no" && !defined(BOOTSTRAPPING)
+LIBADD+=   casper
+LIBADD+=   cap_fileargs
+CFLAGS+=   -DWITH_CASPER
+.endif
+
 CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common
 
 .include 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r345870 - head/tools/build

2019-04-03 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Apr  4 04:14:20 2019
New Revision: 345870
URL: https://svnweb.freebsd.org/changeset/base/345870

Log:
  Add cap_fileargs.h to -legacy if needed.
  
  Reviewed by:  arichardson
  Differential Revision:https://reviews.freebsd.org/D19685

Modified:
  head/tools/build/Makefile

Modified: head/tools/build/Makefile
==
--- head/tools/build/Makefile   Thu Apr  4 02:08:36 2019(r345869)
+++ head/tools/build/Makefile   Thu Apr  4 04:14:20 2019(r345870)
@@ -4,10 +4,11 @@
 
 LIB=   egacy
 SRC=
-INCSGROUPS=INCS SYSINCS
+INCSGROUPS=INCS SYSINCS CASPERINC
 INCS=
 
 SYSINCSDIR=${INCLUDEDIR}/sys
+CASPERINCDIR=  ${INCLUDEDIR}/casper
 
 BOOTSTRAPPING?=0
 
@@ -58,6 +59,10 @@ INCS+=   capsicum_helpers.h
 INCS+= libcasper.h
 .endif
 
+.if !exists(/usr/include/casper/cap_fileargs.h)
+CASPERINC+=${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h
+.endif
+
 .if empty(SRCS)
 SRCS=  dummy.c
 .endif
@@ -116,7 +121,7 @@ host-symlinks:
 # and cross-tools stages. We do this here using mkdir since mtree may not exist
 # yet (this happens if we are crossbuilding from Linux/Mac).
 installdirs:
-.for _dir in bin usr/lib usr/include lib/geom lib/casper
+.for _dir in bin usr/lib usr/include usr/include/casper lib/geom lib/casper
mkdir -p "${DESTDIR}/${_dir}"
 .endfor
 # Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r345431 - head/contrib/elftoolchain/strings

2019-03-22 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Mar 23 02:17:07 2019
New Revision: 345431
URL: https://svnweb.freebsd.org/changeset/base/345431

Log:
  strings: return an error code and the char value separately
  
  If we returning 32 bits value it's hard to distinguish if the returned value
  is a valid one or if its an error (in case of EOF). For that reason separate
  exit code of the function from the returned character.
  
  Reported by:  cem, se

Modified:
  head/contrib/elftoolchain/strings/strings.c

Modified: head/contrib/elftoolchain/strings/strings.c
==
--- head/contrib/elftoolchain/strings/strings.c Sat Mar 23 01:07:51 2019
(r345430)
+++ head/contrib/elftoolchain/strings/strings.c Sat Mar 23 02:17:07 2019
(r345431)
@@ -84,7 +84,7 @@ static struct option strings_longopts[] = {
{ NULL, 0, NULL, 0 }
 };
 
-long   getcharacter(FILE *);
+intgetcharacter(FILE *, long *);
 inthandle_file(const char *);
 inthandle_elf(const char *, FILE *);
 inthandle_binary(const char *, FILE *, size_t);
@@ -291,42 +291,43 @@ handle_elf(const char *name, FILE *pfile)
  * Retrieves a character from input stream based on the encoding
  * type requested.
  */
-long
-getcharacter(FILE *pfile)
+int
+getcharacter(FILE *pfile, long *rt)
 {
-   long rt;
int i, c;
char buf[4];
 
for(i = 0; i < encoding_size; i++) {
c = getc(pfile);
if (c == EOF)
-   return (EOF);
+   return (-1);
buf[i] = c;
}
 
-   rt = EOF;
switch (encoding) {
case ENCODING_7BIT:
case ENCODING_8BIT:
-   rt = buf[0];
+   *rt = buf[0];
break;
case ENCODING_16BIT_BIG:
-   rt = (buf[0] << 8) | buf[1];
+   *rt = (buf[0] << 8) | buf[1];
break;
case ENCODING_16BIT_LITTLE:
-rt = buf[0] | (buf[1] << 8);
-break;
+   *rt = buf[0] | (buf[1] << 8);
+   break;
case ENCODING_32BIT_BIG:
-   rt = ((long) buf[0] << 24) | ((long) buf[1] << 16) |
+   *rt = ((long) buf[0] << 24) | ((long) buf[1] << 16) |
((long) buf[2] << 8) | buf[3];
break;
case ENCODING_32BIT_LITTLE:
-   rt = buf[0] | ((long) buf[1] << 8) | ((long) buf[2] << 16) |
+   *rt = buf[0] | ((long) buf[1] << 8) | ((long) buf[2] << 16) |
((long) buf[3] << 24);
break;
+   default:
+   return (-1);
}
-   return (rt);
+
+   return (0);
 }
 
 /*
@@ -357,8 +358,7 @@ find_strings(const char *name, FILE *pfile, off_t offs
start_off = cur_off;
memset(obuf, 0, min_len + 1);
for(i = 0; i < min_len; i++) {
-   c = getcharacter(pfile);
-   if (c == EOF)
+   if (getcharacter(pfile, ) < 0)
goto _exit1;
if (PRINTABLE(c)) {
obuf[i] = c;
@@ -400,15 +400,16 @@ find_strings(const char *name, FILE *pfile, off_t offs
if ((offset + size) &&
(cur_off >= offset + size))
break;
-   c = getcharacter(pfile);
-   cur_off += encoding_size;
-   if (!PRINTABLE(c) || c == EOF)
+   if (getcharacter(pfile, ) < 0)
break;
+   cur_off += encoding_size;
if (encoding == ENCODING_8BIT &&
(uint8_t)c > 127) {
putchar(c);
continue;
}
+   if (!PRINTABLE(c))
+   break;
putchar(c);
}
putchar('\n');
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r345364 - head/contrib/elftoolchain/strings

2019-03-21 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Mar 21 06:31:14 2019
New Revision: 345364
URL: https://svnweb.freebsd.org/changeset/base/345364

Log:
  In case of ENCODING_8BIT the EOF code will be pass to putchar.
  EOF check should be done before (uint8_t)c > 127 test.
  
  Reported by:  cem

Modified:
  head/contrib/elftoolchain/strings/strings.c

Modified: head/contrib/elftoolchain/strings/strings.c
==
--- head/contrib/elftoolchain/strings/strings.c Thu Mar 21 06:27:58 2019
(r345363)
+++ head/contrib/elftoolchain/strings/strings.c Thu Mar 21 06:31:14 2019
(r345364)
@@ -402,13 +402,13 @@ find_strings(const char *name, FILE *pfile, off_t offs
break;
c = getcharacter(pfile);
cur_off += encoding_size;
+   if (!PRINTABLE(c) || c == EOF)
+   break;
if (encoding == ENCODING_8BIT &&
(uint8_t)c > 127) {
putchar(c);
continue;
}
-   if (!PRINTABLE(c) || c == EOF)
-   break;
putchar(c);
}
putchar('\n');
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r345362 - head/contrib/elftoolchain/strings

2019-03-21 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Mar 21 06:20:33 2019
New Revision: 345362
URL: https://svnweb.freebsd.org/changeset/base/345362

Log:
  Fix powerpc and arm builds after r345361.
  
  Reported by:  jenkins

Modified:
  head/contrib/elftoolchain/strings/strings.c

Modified: head/contrib/elftoolchain/strings/strings.c
==
--- head/contrib/elftoolchain/strings/strings.c Thu Mar 21 05:24:44 2019
(r345361)
+++ head/contrib/elftoolchain/strings/strings.c Thu Mar 21 06:20:33 2019
(r345362)
@@ -295,8 +295,8 @@ long
 getcharacter(FILE *pfile)
 {
long rt;
-   int i;
-   char buf[4], c;
+   int i, c;
+   char buf[4];
 
for(i = 0; i < encoding_size; i++) {
c = getc(pfile);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r345361 - head/contrib/elftoolchain/strings

2019-03-20 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Mar 21 05:24:44 2019
New Revision: 345361
URL: https://svnweb.freebsd.org/changeset/base/345361

Log:
  strings: do not continue if getc or getcharacter returns EOF
  
  Reported by:  cem

Modified:
  head/contrib/elftoolchain/strings/strings.c

Modified: head/contrib/elftoolchain/strings/strings.c
==
--- head/contrib/elftoolchain/strings/strings.c Thu Mar 21 05:00:24 2019
(r345360)
+++ head/contrib/elftoolchain/strings/strings.c Thu Mar 21 05:24:44 2019
(r345361)
@@ -300,7 +300,7 @@ getcharacter(FILE *pfile)
 
for(i = 0; i < encoding_size; i++) {
c = getc(pfile);
-   if (feof(pfile) != 0)
+   if (c == EOF)
return (EOF);
buf[i] = c;
}
@@ -358,7 +358,7 @@ find_strings(const char *name, FILE *pfile, off_t offs
memset(obuf, 0, min_len + 1);
for(i = 0; i < min_len; i++) {
c = getcharacter(pfile);
-   if (c == EOF && feof(pfile) != 0)
+   if (c == EOF)
goto _exit1;
if (PRINTABLE(c)) {
obuf[i] = c;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r345360 - head/contrib/elftoolchain/strings

2019-03-20 Thread Mariusz Zaborski
Author: oshogbo
Date: Thu Mar 21 05:00:24 2019
New Revision: 345360
URL: https://svnweb.freebsd.org/changeset/base/345360

Log:
  strings: do not depend on stdin
  
  Instead of depending on one stdin FILE structure and use freopen(3), pass to
  the functions appropriate FILE structure.
  
  Reviewed by:  cem
  Discussed with:   emaste
  Differential Revision:https://reviews.freebsd.org/D18037

Modified:
  head/contrib/elftoolchain/strings/strings.c

Modified: head/contrib/elftoolchain/strings/strings.c
==
--- head/contrib/elftoolchain/strings/strings.c Thu Mar 21 02:52:22 2019
(r345359)
+++ head/contrib/elftoolchain/strings/strings.c Thu Mar 21 05:00:24 2019
(r345360)
@@ -84,11 +84,11 @@ static struct option strings_longopts[] = {
{ NULL, 0, NULL, 0 }
 };
 
-long   getcharacter(void);
+long   getcharacter(FILE *);
 inthandle_file(const char *);
-inthandle_elf(const char *, int);
-inthandle_binary(const char *, int);
-intfind_strings(const char *, off_t, off_t);
+inthandle_elf(const char *, FILE *);
+inthandle_binary(const char *, FILE *, size_t);
+intfind_strings(const char *, FILE *, off_t, off_t);
 void   show_version(void);
 void   usage(void);
 
@@ -190,7 +190,7 @@ main(int argc, char **argv)
if (min_len == 0)
min_len = 4;
if (*argv == NULL)
-   rc = find_strings("{standard input}", 0, 0);
+   rc = find_strings("{standard input}", stdin, 0, 0);
else while (*argv != NULL) {
if (handle_file(*argv) != 0)
rc = 1;
@@ -202,19 +202,19 @@ main(int argc, char **argv)
 int
 handle_file(const char *name)
 {
-   int fd, rt;
+   FILE *pfile;
+   int rt;
 
if (name == NULL)
return (1);
-   if (freopen(name, "rb", stdin) == NULL) {
+   pfile = fopen(name, "rb");
+   if (pfile == NULL) {
warnx("'%s': %s", name, strerror(errno));
return (1);
}
 
-   fd = fileno(stdin);
-   if (fd < 0)
-   return (1);
-   rt = handle_elf(name, fd);
+   rt = handle_elf(name, pfile);
+   fclose(pfile);
return (rt);
 }
 
@@ -223,15 +223,11 @@ handle_file(const char *name)
  * treated as a binary file. This would include text file, core dumps ...
  */
 int
-handle_binary(const char *name, int fd)
+handle_binary(const char *name, FILE *pfile, size_t size)
 {
-   struct stat buf;
 
-   memset(, 0, sizeof(buf));
-   (void)lseek(fd, 0, SEEK_SET);
-   if (!fstat(fd, ))
-   return (find_strings(name, 0, buf.st_size));
-   return (1);
+   (void)fseeko(pfile, 0, SEEK_SET);
+   return (find_strings(name, pfile, 0, size));
 }
 
 /*
@@ -241,24 +237,29 @@ handle_binary(const char *name, int fd)
  * different archs as flat binary files(has to overridden using -a).
  */
 int
-handle_elf(const char *name, int fd)
+handle_elf(const char *name, FILE *pfile)
 {
+   struct stat buf;
GElf_Ehdr elfhdr;
GElf_Shdr shdr;
Elf *elf;
Elf_Scn *scn;
-   int rc;
+   int rc, fd;
 
rc = 0;
+   fd = fileno(pfile);
+   if (fstat(fd, ) < 0)
+   return (1);
+
/* If entire file is chosen, treat it as a binary file */
if (entire_file)
-   return (handle_binary(name, fd));
+   return (handle_binary(name, pfile, buf.st_size));
 
(void)lseek(fd, 0, SEEK_SET);
elf = elf_begin(fd, ELF_C_READ, NULL);
if (elf_kind(elf) != ELF_K_ELF) {
(void)elf_end(elf);
-   return (handle_binary(name, fd));
+   return (handle_binary(name, pfile, buf.st_size));
}
 
if (gelf_getehdr(elf, ) == NULL) {
@@ -269,7 +270,7 @@ handle_elf(const char *name, int fd)
 
if (elfhdr.e_shnum == 0 && elfhdr.e_type == ET_CORE) {
(void)elf_end(elf);
-   return (handle_binary(name, fd));
+   return (handle_binary(name, pfile, buf.st_size));
} else {
scn = NULL;
while ((scn = elf_nextscn(elf, scn)) != NULL) {
@@ -277,7 +278,7 @@ handle_elf(const char *name, int fd)
continue;
if (shdr.sh_type != SHT_NOBITS &&
(shdr.sh_flags & SHF_ALLOC) != 0) {
-   rc = find_strings(name, shdr.sh_offset,
+   rc = find_strings(name, pfile, shdr.sh_offset,
shdr.sh_size);
}
}
@@ -291,20 +292,20 @@ handle_elf(const char *name, int fd)
  * type requested.
  */
 long
-getcharacter(void)
+getcharacter(FILE *pfile)
 {
long rt;
int i;
char buf[4], c;
 
-   rt = EOF;
for(i = 0; i < encoding_size; i++) {
-   c 

svn commit: r344236 - head/sys/contrib/libnv

2019-02-17 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Feb 17 18:32:19 2019
New Revision: 344236
URL: https://svnweb.freebsd.org/changeset/base/344236

Log:
  libnv: fix revert
  
  Reported by:  jenkins

Modified:
  head/sys/contrib/libnv/nvpair.c

Modified: head/sys/contrib/libnv/nvpair.c
==
--- head/sys/contrib/libnv/nvpair.c Sun Feb 17 18:26:27 2019
(r344235)
+++ head/sys/contrib/libnv/nvpair.c Sun Feb 17 18:32:19 2019
(r344236)
@@ -229,8 +229,8 @@ nvpair_remove_nvlist_array(nvpair_t *nvp)
nvlarray = __DECONST(nvlist_t **,
nvpair_get_nvlist_array(nvp, ));
for (i = 0; i < count; i++) {
-   nvlist_set_array_next(nvl, NULL);
-   nvlist_set_parent(nvl, NULL);
+   nvlist_set_array_next(nvlarray[i], NULL);
+   nvlist_set_parent(nvlarray[i], NULL);
}
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r344235 - head/sys/contrib/libnv

2019-02-17 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Feb 17 18:26:27 2019
New Revision: 344235
URL: https://svnweb.freebsd.org/changeset/base/344235

Log:
  libnv: fix double free
  
  In r343986 we introduced a double free. The structure was already
  freed fixed in the r302966. This problem was introduced
  because the GitHub version was out of sync with the FreeBSD one.
  
  Submitted by: Mindaugas Rasiukevicius 
  MFC with: r343986

Modified:
  head/sys/contrib/libnv/nvpair.c

Modified: head/sys/contrib/libnv/nvpair.c
==
--- head/sys/contrib/libnv/nvpair.c Sun Feb 17 17:47:08 2019
(r344234)
+++ head/sys/contrib/libnv/nvpair.c Sun Feb 17 18:26:27 2019
(r344235)
@@ -229,14 +229,6 @@ nvpair_remove_nvlist_array(nvpair_t *nvp)
nvlarray = __DECONST(nvlist_t **,
nvpair_get_nvlist_array(nvp, ));
for (i = 0; i < count; i++) {
-   nvlist_t *nvl;
-   nvpair_t *nnvp;
-
-   nvl = nvlarray[i];
-   nnvp = nvlist_get_array_next_nvpair(nvl);
-   if (nnvp != NULL) {
-   nvpair_free_structure(nnvp);
-   }
nvlist_set_array_next(nvl, NULL);
nvlist_set_parent(nvl, NULL);
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r343987 - head/sys/contrib/libnv

2019-02-10 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Feb 10 23:30:54 2019
New Revision: 343987
URL: https://svnweb.freebsd.org/changeset/base/343987

Log:
  libnv: fix memory leaks
  
  Free the data array for NV_TYPE_DESCRIPTOR_ARRAY case.
  
  MFC after:2 weeks

Modified:
  head/sys/contrib/libnv/nvpair.c

Modified: head/sys/contrib/libnv/nvpair.c
==
--- head/sys/contrib/libnv/nvpair.c Sun Feb 10 23:28:55 2019
(r343986)
+++ head/sys/contrib/libnv/nvpair.c Sun Feb 10 23:30:54 2019
(r343987)
@@ -2061,6 +2061,7 @@ nvpair_free(nvpair_t *nvp)
case NV_TYPE_DESCRIPTOR_ARRAY:
for (i = 0; i < nvp->nvp_nitems; i++)
close(((int *)(intptr_t)nvp->nvp_data)[i]);
+   nv_free((int *)(intptr_t)nvp->nvp_data);
break;
 #endif
case NV_TYPE_NVLIST:
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r343986 - in head: lib/libnv/tests sys/contrib/libnv

2019-02-10 Thread Mariusz Zaborski
Author: oshogbo
Date: Sun Feb 10 23:28:55 2019
New Revision: 343986
URL: https://svnweb.freebsd.org/changeset/base/343986

Log:
  libnv: fix memory leaks
  
  nvpair_create_stringv: free the temporary string; this fix affects
  nvlist_add_stringf() and nvlist_add_stringv().
  
  nvpair_remove_nvlist_array (NV_TYPE_NVLIST_ARRAY case): free the chain
  of nvpairs (as resetting it prevents nvlist_destroy() from freeing it).
  Note: freeing the chain in nvlist_destroy() is not sufficient, because
  it would still leak through nvlist_take_nvlist_array().  This affects
  all nvlist_*_nvlist_array() use
  
  Submitted by: Mindaugas Rasiukevicius 
  Reported by:  clang/gcc ASAN
  MFC after:2 weeks

Modified:
  head/lib/libnv/tests/nvlist_send_recv_test.c
  head/sys/contrib/libnv/nv_impl.h
  head/sys/contrib/libnv/nvlist.c
  head/sys/contrib/libnv/nvpair.c

Modified: head/lib/libnv/tests/nvlist_send_recv_test.c
==
--- head/lib/libnv/tests/nvlist_send_recv_test.cSun Feb 10 23:07:46 
2019(r343985)
+++ head/lib/libnv/tests/nvlist_send_recv_test.cSun Feb 10 23:28:55 
2019(r343986)
@@ -304,6 +304,8 @@ parent(int sock)
 
name = nvlist_next(nvl, , );
CHECK(name == NULL);
+
+   nvlist_destroy(nvl);
 }
 
 static void

Modified: head/sys/contrib/libnv/nv_impl.h
==
--- head/sys/contrib/libnv/nv_impl.hSun Feb 10 23:07:46 2019
(r343985)
+++ head/sys/contrib/libnv/nv_impl.hSun Feb 10 23:28:55 2019
(r343986)
@@ -103,6 +103,7 @@ bool nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp);
 
 void nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent);
 void nvlist_set_array_next(nvlist_t *nvl, nvpair_t *ele);
+nvpair_t *nvlist_get_array_next_nvpair(nvlist_t *nvl);
 
 const nvpair_t *nvlist_get_nvpair(const nvlist_t *nvl, const char *name);
 

Modified: head/sys/contrib/libnv/nvlist.c
==
--- head/sys/contrib/libnv/nvlist.c Sun Feb 10 23:07:46 2019
(r343985)
+++ head/sys/contrib/libnv/nvlist.c Sun Feb 10 23:28:55 2019
(r343986)
@@ -247,6 +247,15 @@ nvlist_set_array_next(nvlist_t *nvl, nvpair_t *ele)
nvl->nvl_array_next = ele;
 }
 
+nvpair_t *
+nvlist_get_array_next_nvpair(nvlist_t *nvl)
+{
+
+   NVLIST_ASSERT(nvl);
+
+   return (nvl->nvl_array_next);
+}
+
 bool
 nvlist_in_array(const nvlist_t *nvl)
 {

Modified: head/sys/contrib/libnv/nvpair.c
==
--- head/sys/contrib/libnv/nvpair.c Sun Feb 10 23:07:46 2019
(r343985)
+++ head/sys/contrib/libnv/nvpair.c Sun Feb 10 23:28:55 2019
(r343986)
@@ -229,8 +229,16 @@ nvpair_remove_nvlist_array(nvpair_t *nvp)
nvlarray = __DECONST(nvlist_t **,
nvpair_get_nvlist_array(nvp, ));
for (i = 0; i < count; i++) {
-   nvlist_set_array_next(nvlarray[i], NULL);
-   nvlist_set_parent(nvlarray[i], NULL);
+   nvlist_t *nvl;
+   nvpair_t *nnvp;
+
+   nvl = nvlarray[i];
+   nnvp = nvlist_get_array_next_nvpair(nvl);
+   if (nnvp != NULL) {
+   nvpair_free_structure(nnvp);
+   }
+   nvlist_set_array_next(nvl, NULL);
+   nvlist_set_parent(nvl, NULL);
}
 }
 
@@ -1193,8 +1201,7 @@ nvpair_create_stringv(const char *name, const char *va
if (len < 0)
return (NULL);
nvp = nvpair_create_string(name, str);
-   if (nvp == NULL)
-   nv_free(str);
+   nv_free(str);
return (nvp);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r343471 - head/lib/libcasper/libcasper

2019-01-26 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Jan 26 14:10:49 2019
New Revision: 343471
URL: https://svnweb.freebsd.org/changeset/base/343471

Log:
  libcasper: do not run registered exit functions
  
  Casper library should not use exit(3) function because before setting it up
  applications may register it. Casper doesn't depend on any registered exit
  function, so it safe to change this.
  
  Reported by:  jceel
  MFC after:2 weeks

Modified:
  head/lib/libcasper/libcasper/libcasper_service.c
  head/lib/libcasper/libcasper/service.c
  head/lib/libcasper/libcasper/zygote.c

Modified: head/lib/libcasper/libcasper/libcasper_service.c
==
--- head/lib/libcasper/libcasper/libcasper_service.cSat Jan 26 13:53:00 
2019(r343470)
+++ head/lib/libcasper/libcasper/libcasper_service.cSat Jan 26 14:10:49 
2019(r343471)
@@ -148,20 +148,20 @@ service_execute(int chanfd)
 
nvl = nvlist_recv(chanfd, 0);
if (nvl == NULL)
-   exit(1);
+   _exit(1);
if (!nvlist_exists_string(nvl, "service"))
-   exit(1);
+   _exit(1);
servname = nvlist_get_string(nvl, "service");
casserv = service_find(servname);
if (casserv == NULL)
-   exit(1);
+   _exit(1);
service = casserv->cs_service;
procfd = nvlist_take_descriptor(nvl, "procfd");
nvlist_destroy(nvl);
 
service_start(service, chanfd, procfd);
/* Not reached. */
-   exit(1);
+   _exit(1);
 }
 
 static int
@@ -231,7 +231,7 @@ casper_main_loop(int fd)
int sock, maxfd, ret;
 
if (zygote_init() < 0)
-   exit(1);
+   _exit(1);
 
/*
 * Register core services.
@@ -256,7 +256,7 @@ casper_main_loop(int fd)
}
if (maxfd == -1) {
/* Nothing to do. */
-   exit(0);
+   _exit(0);
}
maxfd++;
 
@@ -267,7 +267,7 @@ casper_main_loop(int fd)
if (ret == -1) {
if (errno == EINTR)
continue;
-   exit(1);
+   _exit(1);
}
 
TAILQ_FOREACH(casserv, _services, cs_next) {

Modified: head/lib/libcasper/libcasper/service.c
==
--- head/lib/libcasper/libcasper/service.c  Sat Jan 26 13:53:00 2019
(r343470)
+++ head/lib/libcasper/libcasper/service.c  Sat Jan 26 14:10:49 2019
(r343471)
@@ -427,7 +427,7 @@ service_start(struct service *service, int sock, int p
service_clean(sock, procfd, service->s_flags);
 
if (service_connection_add(service, sock, NULL) == NULL)
-   exit(1);
+   _exit(1);
 
for (;;) {
FD_ZERO();
@@ -443,7 +443,7 @@ service_start(struct service *service, int sock, int p
nfds = select(maxfd + 1, , NULL, NULL, NULL);
if (nfds < 0) {
if (errno != EINTR)
-   exit(1);
+   _exit(1);
continue;
} else if (nfds == 0) {
/* Timeout. */
@@ -468,5 +468,5 @@ service_start(struct service *service, int sock, int p
}
}
 
-   exit(0);
+   _exit(0);
 }

Modified: head/lib/libcasper/libcasper/zygote.c
==
--- head/lib/libcasper/libcasper/zygote.c   Sat Jan 26 13:53:00 2019
(r343470)
+++ head/lib/libcasper/libcasper/zygote.c   Sat Jan 26 14:10:49 2019
(r343471)
@@ -122,7 +122,7 @@ zygote_main(int sock)
if (nvlin == NULL) {
if (errno == ENOTCONN) {
/* Casper exited. */
-   exit(0);
+   _exit(0);
}
continue;
}
@@ -134,7 +134,7 @@ zygote_main(int sock)
func = service_execute;
break;
default:
-   exit(0);
+   _exit(0);
}
 
/*
@@ -161,7 +161,7 @@ zygote_main(int sock)
close(chanfd[0]);
func(chanfd[1]);
/* NOTREACHED */
-   exit(1);
+   _exit(1);
default:
/* Parent. */
close(chanfd[1]);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r343470 - head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs

2019-01-26 Thread Mariusz Zaborski
Author: oshogbo
Date: Sat Jan 26 13:53:00 2019
New Revision: 343470
URL: https://svnweb.freebsd.org/changeset/base/343470

Log:
  zfs: allow to change cache flush sysctl
  
  There is no reason for this variable to be tunable.
  This variable is used as a barrier in few places.
  
  Discussed with:   pjd
  MFC after:2 weeks
  Sponsored by: Fudo Security

Modified:
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c
==
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c   Sat Jan 26 
13:36:06 2019(r343469)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c   Sat Jan 26 
13:53:00 2019(r343470)
@@ -103,7 +103,7 @@ SYSCTL_INT(_vfs_zfs, OID_AUTO, zil_replay_disable, CTL
  * out-of-order write cache is enabled.
  */
 boolean_t zfs_nocacheflush = B_FALSE;
-SYSCTL_INT(_vfs_zfs, OID_AUTO, cache_flush_disable, CTLFLAG_RDTUN,
+SYSCTL_INT(_vfs_zfs, OID_AUTO, cache_flush_disable, CTLFLAG_RWTUN,
 _nocacheflush, 0, "Disable cache flush");
 boolean_t zfs_trim_enabled = B_TRUE;
 SYSCTL_DECL(_vfs_zfs_trim);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r342001 - head/lib/libcapsicum

2018-12-12 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Dec 12 20:32:17 2018
New Revision: 342001
URL: https://svnweb.freebsd.org/changeset/base/342001

Log:
  libcapsicum: add missing links
  
  Reported by:  manu

Modified:
  head/lib/libcapsicum/Makefile

Modified: head/lib/libcapsicum/Makefile
==
--- head/lib/libcapsicum/Makefile   Wed Dec 12 20:19:56 2018
(r342000)
+++ head/lib/libcapsicum/Makefile   Wed Dec 12 20:32:17 2018
(r342001)
@@ -9,6 +9,8 @@ MAN+=   capsicum_helpers.3
 MLINKS+=capsicum_helpers.3 caph_enter.3
 MLINKS+=capsicum_helpers.3 caph_enter_casper.3
 MLINKS+=capsicum_helpers.3 caph_rights_limit.3
+MLINKS+=capsicum_helpers.3 caph_fcntls_limit.3
+MLINKS+=capsicum_helpers.3 caph_ioctls_limit.3
 MLINKS+=capsicum_helpers.3 caph_limit_stream.3
 MLINKS+=capsicum_helpers.3 caph_limit_stdin.3
 MLINKS+=capsicum_helpers.3 caph_limit_stderr.3
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r341348 - in head/usr.sbin: ctld iscsid

2018-11-30 Thread Mariusz Zaborski
Author: oshogbo
Date: Fri Nov 30 19:40:16 2018
New Revision: 341348
URL: https://svnweb.freebsd.org/changeset/base/341348

Log:
  iscsi: simplify the capsicumization
  
  Approved by:  trasz
  Differential Revision:https://reviews.freebsd.org/D17962

Modified:
  head/usr.sbin/ctld/kernel.c
  head/usr.sbin/iscsid/iscsid.c

Modified: head/usr.sbin/ctld/kernel.c
==
--- head/usr.sbin/ctld/kernel.c Fri Nov 30 19:27:14 2018(r341347)
+++ head/usr.sbin/ctld/kernel.c Fri Nov 30 19:40:16 2018(r341348)
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1313,22 +1314,17 @@ kernel_receive(struct pdu *pdu)
 void
 kernel_capsicate(void)
 {
-   int error;
cap_rights_t rights;
const unsigned long cmds[] = { CTL_ISCSI };
 
cap_rights_init(, CAP_IOCTL);
-   error = cap_rights_limit(ctl_fd, );
-   if (error != 0 && errno != ENOSYS)
+   if (caph_rights_limit(ctl_fd, ) < 0)
log_err(1, "cap_rights_limit");
 
-   error = cap_ioctls_limit(ctl_fd, cmds, nitems(cmds));
-
-   if (error != 0 && errno != ENOSYS)
+   if (caph_ioctls_limit(ctl_fd, cmds, nitems(cmds)) < 0)
log_err(1, "cap_ioctls_limit");
 
-   error = cap_enter();
-   if (error != 0 && errno != ENOSYS)
+   if (caph_enter() < 0)
log_err(1, "cap_enter");
 
if (cap_sandboxed())

Modified: head/usr.sbin/iscsid/iscsid.c
==
--- head/usr.sbin/iscsid/iscsid.c   Fri Nov 30 19:27:14 2018
(r341347)
+++ head/usr.sbin/iscsid/iscsid.c   Fri Nov 30 19:40:16 2018
(r341348)
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -349,7 +350,6 @@ fail(const struct connection *conn, const char *reason
 static void
 capsicate(struct connection *conn)
 {
-   int error;
cap_rights_t rights;
 #ifdef ICL_KERNEL_PROXY
const unsigned long cmds[] = { ISCSIDCONNECT, ISCSIDSEND, ISCSIDRECEIVE,
@@ -360,17 +360,13 @@ capsicate(struct connection *conn)
 #endif
 
cap_rights_init(, CAP_IOCTL);
-   error = cap_rights_limit(conn->conn_iscsi_fd, );
-   if (error != 0 && errno != ENOSYS)
+   if (caph_rights_limit(conn->conn_iscsi_fd, ) < 0)
log_err(1, "cap_rights_limit");
 
-   error = cap_ioctls_limit(conn->conn_iscsi_fd, cmds, nitems(cmds));
-
-   if (error != 0 && errno != ENOSYS)
+   if (caph_ioctls_limit(conn->conn_iscsi_fd, cmds, nitems(cmds)) < 0)
log_err(1, "cap_ioctls_limit");
 
-   error = cap_enter();
-   if (error != 0 && errno != ENOSYS)
+   if (caph_enter() != 0)
log_err(1, "cap_enter");
 
if (cap_sandboxed())
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r341347 - head/lib/libcasper/services/cap_fileargs

2018-11-30 Thread Mariusz Zaborski
Author: oshogbo
Date: Fri Nov 30 19:27:14 2018
New Revision: 341347
URL: https://svnweb.freebsd.org/changeset/base/341347

Log:
  libcasper: do not fail if Capsicum is not avilable
  
  Casper service can be also used on the kernels without Capsicum support.
  
  Reported by:  sbruno
  Tested by:sbruno

Modified:
  head/lib/libcasper/services/cap_fileargs/cap_fileargs.c

Modified: head/lib/libcasper/services/cap_fileargs/cap_fileargs.c
==
--- head/lib/libcasper/services/cap_fileargs/cap_fileargs.c Fri Nov 30 
18:02:59 2018(r341346)
+++ head/lib/libcasper/services/cap_fileargs/cap_fileargs.c Fri Nov 30 
19:27:14 2018(r341347)
@@ -363,7 +363,7 @@ open_file(const char *name)
return (-1);
 
if (caprightsp != NULL) {
-   if (cap_rights_limit(fd, caprightsp) < 0) {
+   if (cap_rights_limit(fd, caprightsp) < 0 && errno != ENOSYS) {
serrno = errno;
close(fd);
errno = serrno;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


  1   2   3   4   >