From owner-svn-src-head@freebsd.org Tue Jun 30 00:11:33 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2E01D359196; Tue, 30 Jun 2020 00:11:33 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-oo1-f68.google.com (mail-oo1-f68.google.com [209.85.161.68]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49wlC83Rcyz4cw1; Tue, 30 Jun 2020 00:11:32 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-oo1-f68.google.com with SMTP id c4so228724oou.6; Mon, 29 Jun 2020 17:11:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yqk1f22U/vatzVGSxSzkVo6fVwY3l789/x7F7fQe98M=; b=ekoPO0eOLB6qLg/unVTbD263yeW15Wp3PNNq4b2E1ef+dJ8PuMnhAEqzAWDQqoc1FC y7VCk+hnu7elP5lcQaOd60K99UeO/Rwz7lxlLlqHyWVk+JauV+uePv4vNCnvn1jN2XH8 qsgVdIN1wZifk1dD63Irf+xEfQE/iHj4h7DSqjgxJ+ijZePuROxEhDj8Fcf85HEr2uWI idsMkQnHPCFdp0Q2hw4l52c82HtiMCIamRVdsaSc+0ut1B+y1OEVtDjEQnwxxZeJ9Tbx xc01y/HliYWV7abfroXweMmN+9fL/heynan/C/898c/WGJ1q3L4BCm5oBPLieJew7QCk 7/kg== X-Gm-Message-State: AOAM532V8joL+q9f4trwMgLMTGDw19l7AVATycO+Asx4bA5OTfdSh9hV M4S6M4hyloT0fukvN64un74YB0iDeFdcUrjcmWhXZU1/ X-Google-Smtp-Source: ABdhPJxcXZdix7Yy4yvZsEek0bKPdiWQQAxqzw0aUrM/3tlkpzLHCch7EPsxIwgpEGprHhiJGP+ulrFIVEtXL1Or0gU= X-Received: by 2002:a4a:b181:: with SMTP id c1mr4514111ooo.74.1593475890765; Mon, 29 Jun 2020 17:11:30 -0700 (PDT) MIME-Version: 1.0 References: <201901021709.x02H9ZPM004185@repo.freebsd.org> <20200629005538.GB7202@raichu> In-Reply-To: <20200629005538.GB7202@raichu> From: Alan Somers Date: Mon, 29 Jun 2020 18:11:19 -0600 Message-ID: Subject: Re: svn commit: r342699 - head/sbin/savecore To: Mark Johnston Cc: src-committers , svn-src-all , svn-src-head X-Rspamd-Queue-Id: 49wlC83Rcyz4cw1 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; REPLY(-4.00)[] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.33 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 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: Tue, 30 Jun 2020 00:11:33 -0000 On Sun, Jun 28, 2020 at 6:55 PM Mark Johnston wrote: > On Sun, Jun 28, 2020 at 06:40:59PM -0600, Alan Somers wrote: > > On Wed, Jan 2, 2019 at 10:09 AM Mark Johnston wrote: > > > > > Author: markj > > > Date: Wed Jan 2 17:09:35 2019 > > > New Revision: 342699 > > > URL: https://svnweb.freebsd.org/changeset/base/342699 > > > > > > Log: > > > Capsicumize savecore(8). > > > > > > - Use cap_fileargs(3) to open dump devices after entering capability > > > mode, and use cap_syslog(3) to log messages. > > > - Use a relative directory fd to open output files. > > > - Use zdopen(3) to compress kernel dumps in capability mode. > > > > > > Reviewed by: cem, oshogbo > > > MFC after: 2 months > > > Sponsored by: The FreeBSD Foundation > > > Differential Revision: https://reviews.freebsd.org/D18458 > > > > > > Modified: > > > head/sbin/savecore/Makefile > > > head/sbin/savecore/savecore.c > > > > > > Modified: head/sbin/savecore/savecore.c > > > > > > > ============================================================================== > > > --- head/sbin/savecore/savecore.c Wed Jan 2 16:42:07 2019 > > > (r342698) > > > +++ head/sbin/savecore/savecore.c Wed Jan 2 17:09:35 2019 > > > (r342699) > > > > > > +static char ** > > > +enum_dumpdevs(int *argcp) > > > +{ > > > + struct fstab *fsp; > > > + char **argv; > > > + int argc, n; > > > + > > > + /* > > > + * We cannot use getfsent(3) in capability mode, so we must > > > + * scan /etc/fstab and build up a list of candidate devices > > > + * before proceeding. > > > + */ > > > + argc = 0; > > > + n = 8; > > > + argv = malloc(n * sizeof(*argv)); > > > > > > > It looks like the memory allocated here > > > > > > > + if (argv == NULL) { > > > + logmsg(LOG_ERR, "malloc(): %m"); > > > + exit(1); > > > + } > > > + for (;;) { > > > + fsp = getfsent(); > > > + if (fsp == NULL) > > > + break; > > > + if (strcmp(fsp->fs_vfstype, "swap") != 0 && > > > + strcmp(fsp->fs_vfstype, "dump") != 0) > > > + continue; > > > + if (argc >= n) { > > > + n *= 2; > > > + argv = realloc(argv, n * sizeof(*argv)); > > > > > > > and here > > > > > > > + if (argv == NULL) { > > > + logmsg(LOG_ERR, "realloc(): %m"); > > > + exit(1); > > > + } > > > + } > > > + argv[argc] = strdup(fsp->fs_spec); > > > > > > > and here is leaked. I can't find any corresponding free. However, > neither > > Valgrind nor Coverity complains. What am I missing? Does this memory > > sneakily get freed by a subroutine somewhere, or does Capsicum confuse > our > > tools? > > I'm not sure why Capsicum would change anything. It would be worth > testing devel/valgrind-devel with https://reviews.freebsd.org/D25452 > applied, to see if it's able to detect that bug. > Using that new valgrind-devel did not find the leaks. However, it _did_ print a helpful error message explaining why Capsicum interferes. Commenting out caph_enter_casper allowed valgrind to find the leaks. It also found two more than I didn't know about. Thanks for the tip. https://www.valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq -Alan