From owner-svn-src-head@freebsd.org Wed Jun 27 07:00:01 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3972C100AB0D for ; Wed, 27 Jun 2018 07:00:01 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: from mail-yw0-x22c.google.com (mail-yw0-x22c.google.com [IPv6:2607:f8b0:4002:c05::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BAB1D97BB9 for ; Wed, 27 Jun 2018 07:00:00 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: by mail-yw0-x22c.google.com with SMTP id n187-v6so341177ywd.1 for ; Wed, 27 Jun 2018 00:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=hagwpEx3PMTNM/5joEFz067hGnb5jhJOldTOXGrq8dI=; b=XFy0F7V9K5QyBLKvoekKeBZHNeOySTiILjKcdPmQIUgDNTkFZVgGqbaqQ3zEYOuUU8 vMuZ6/UisNtHsXkvsJo4SZMs01IDP0H5/H8CqnlXOyndLzaYut3hwtohidkcKQNWvRYq h2MiPXkPinN5dKXo4DK7MjCg8aezAfQYOiZ6SWXpaEc6VQudVvjLDtIrgYHYDVrGkzsD upbd2D7RmEPcLJqwnNmMCP53SGLle0la/Ml/aJxsVhFuqflmaipNVh+fyGBTxDmmr1ZC hJY6zGtKt5eS1J3kd83KBiXUNUl3nEJydq0Mf8zIDW+y8Yu/RgXdWcBFEla8vmBW4PxF Sjqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=hagwpEx3PMTNM/5joEFz067hGnb5jhJOldTOXGrq8dI=; b=J6hES1M+QkuJbZTkU0qzFCejvvIF/yIo2Uw2rehuWoLw/aHZcrC4GTvPpnO4v9XzGD egV3Ls9IghXcuL+UHaSj18dhPVViumaH1ZPDHtl7+LbRGvO37mfrbt9jCGd3unlbP+zA GdU51bSCu08jbp8w9wjk/kNA6y+ExPDpOQ+zIzHpURYv2dZ67KbWZICOlZVsTnVUeAK7 KqhHzZJ+Nh6LyIOR3ekuqJ1rR7sy+0yr2Zi1bNmTJfuj68KzllVs1ynPpsQnFGryMKUa TwZlm/g7jOdyf/avQcF0qrXmitrv8pxFS0KrjMEtu3DVew4dNxT2BEBrWShrw1y73ktY Vj2Q== X-Gm-Message-State: APt69E1eieGlpDvqmIZBCrBiYmZOoa0Hy+3N5FQuyNaqmDUqapPWaHEV aReiv82GDB/HE1yWd+qrEMGJjxdDDse9mfT0amk1bw== X-Google-Smtp-Source: AAOMgpfLeXgaA+EKXYxirPIxumnH7y08JcnmqaF48hfRM+1T8FWV7KkrlbUQKxZCHs0I2dPHJoj9FcMG8Rb18wBpbzM= X-Received: by 2002:a81:351:: with SMTP id 78-v6mr2344488ywd.104.1530082800196; Wed, 27 Jun 2018 00:00:00 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:db86:0:0:0:0:0 with HTTP; Tue, 26 Jun 2018 23:59:59 -0700 (PDT) In-Reply-To: <201806270411.w5R4B9ZB078994@repo.freebsd.org> References: <201806270411.w5R4B9ZB078994@repo.freebsd.org> From: Oliver Pinter Date: Wed, 27 Jun 2018 08:59:59 +0200 Message-ID: Subject: Re: svn commit: r335690 - head/sys/kern To: Warner Losh Cc: "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.26 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jun 2018 07:00:01 -0000 On Wednesday, June 27, 2018, Warner Losh wrote: > Author: imp > Date: Wed Jun 27 04:11:09 2018 > New Revision: 335690 > URL: https://svnweb.freebsd.org/changeset/base/335690 > > Log: > Fix devctl generation for core files. > > We have a problem with vn_fullpath_global when the file exists. Work > around it by printing the full path if the core file name starts with /, > or current working directory followed by the filename if not. > > Sponsored by: Netflix > Differential Review: https://reviews.freebsd.org/D16026 > > Modified: > head/sys/kern/kern_sig.c > > Modified: head/sys/kern/kern_sig.c > ============================================================ > ================== > --- head/sys/kern/kern_sig.c Wed Jun 27 04:10:48 2018 (r335689) > +++ head/sys/kern/kern_sig.c Wed Jun 27 04:11:09 2018 (r335690) > @@ -3431,24 +3431,6 @@ out: > return (0); > } > > -static int > -coredump_sanitise_path(const char *path) > -{ > - size_t i; > - > - /* > - * Only send a subset of ASCII to devd(8) because it > - * might pass these strings to sh -c. > - */ > - for (i = 0; path[i]; i++) > - if (!(isalpha(path[i]) || isdigit(path[i])) && > - path[i] != '/' && path[i] != '.' && > - path[i] != '-') > - return (0); This part of code existed to prevent shell code injection via file names. After this commit we lose this. > - > - return (1); > -} > - > /* > * Dump a process' core. The main routine does some > * policy checking, and creates the name of the coredump; > @@ -3469,11 +3451,8 @@ coredump(struct thread *td) > char *name; /* name of corefile */ > void *rl_cookie; > off_t limit; > - char *data = NULL; > char *fullpath, *freepath = NULL; > - size_t len; > - static const char comm_name[] = "comm="; > - static const char core_name[] = "core="; > + struct sbuf *sb; > > PROC_LOCK_ASSERT(p, MA_OWNED); > MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td); > @@ -3556,23 +3535,35 @@ coredump(struct thread *td) > */ > if (error != 0 || coredump_devctl == 0) > goto out; > - len = MAXPATHLEN * 2 + sizeof(comm_name) - 1 + > - sizeof(' ') + sizeof(core_name) - 1; > - data = malloc(len, M_TEMP, M_WAITOK); > + sb = sbuf_new_auto(); > if (vn_fullpath_global(td, p->p_textvp, &fullpath, &freepath) != 0) > - goto out; > - if (!coredump_sanitise_path(fullpath)) > - goto out; > - snprintf(data, len, "%s%s ", comm_name, fullpath); > + goto out2; > + sbuf_printf(sb, "comm=\""); > + devctl_safe_quote_sb(sb, fullpath); > free(freepath, M_TEMP); > - freepath = NULL; > - if (vn_fullpath_global(td, vp, &fullpath, &freepath) != 0) > - goto out; > - if (!coredump_sanitise_path(fullpath)) > - goto out; > - strlcat(data, core_name, len); > - strlcat(data, fullpath, len); > - devctl_notify("kernel", "signal", "coredump", data); > + sbuf_printf(sb, "\" core=\""); > + > + /* > + * We can't lookup core file vp directly. When we're replacing a > core, and > + * other random times, we flush the name cache, so it will fail. > Instead, > + * if the path of the core is relative, add the current dir in > front if it. > + */ > + if (name[0] != '/') { > + fullpath = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); > + if (kern___getcwd(td, fullpath, UIO_SYSSPACE, MAXPATHLEN, > MAXPATHLEN) != 0) { > + free(fullpath, M_TEMP); > + goto out2; > + } > + devctl_safe_quote_sb(sb, fullpath); > + free(fullpath, M_TEMP); > + sbuf_putc(sb, '/'); > + } > + devctl_safe_quote_sb(sb, name); > + sbuf_printf(sb, "\""); > + if (sbuf_finish(sb) == 0) > + devctl_notify("kernel", "signal", "coredump", > sbuf_data(sb)); > +out2: > + sbuf_delete(sb); > out: > error1 = vn_close(vp, FWRITE, cred, td); > if (error == 0) > @@ -3580,8 +3571,6 @@ out: > #ifdef AUDIT > audit_proc_coredump(td, name, error); > #endif > - free(freepath, M_TEMP); > - free(data, M_TEMP); > free(name, M_TEMP); > 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-unsubscribe@freebsd.org" >