From owner-svn-src-head@freebsd.org Mon Jun 29 00:49:50 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 6CC0335A513; Mon, 29 Jun 2020 00:49:50 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (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 49w85n2FyYz46sg; Mon, 29 Jun 2020 00:49:48 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-oi1-f169.google.com with SMTP id k4so13069238oik.2; Sun, 28 Jun 2020 17:49:48 -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=1se5j/jegIz2sk9NM7GqTWB4Ppod3w2V1YbECNIbHFQ=; b=UNf3XwUOB6otK3fIBZqVNG26eZYmpHvGMQOR5yEPmOIDC+wXP6heVTfcDabIdlTwyC vlGwO+y4QVnTYUKWlPc8miONBPzXnH3zjzsgHKbZlIjD5duo/QVdM9Ne6oK9ktkqIXB9 gyBXtJpMOEX5sU6uvP7NFHUpkxmixzi7xyzxXHKOx4w+bCxMngRpOvu8XPJHQBdQb5WI NN56r/n5534YwjdNBj2bsWaTA2b0OfrKXRTKDljDH5aYtPVs2CyXoo5utzOxEh/lBZ6t iHQmBbFEPaIoL1mIn3byF1AyDR+6ViOA7NDrhCKnlTaZI6XkOD7bAGMbTOLYNhwcV6Fu 9nnA== X-Gm-Message-State: AOAM532svIEEsR0AjjWFgZU8pJ0ReUcqDU8AyJzH7QkozwB3TEDgnPj4 gyW6ow89dYvGU7ErTUWZZaD4kAZtZZSgd5Q4U5ABmw== X-Google-Smtp-Source: ABdhPJw4cAKLUZQZwqvvfA45Wb3bOUE+9hU3uqOFZD4mZebojN/m9J0MPIdr4P+sPFfEr/NOdSXMdZjaml2YqbxkrVo= X-Received: by 2002:aca:c391:: with SMTP id t139mr1921570oif.57.1593391787494; Sun, 28 Jun 2020 17:49:47 -0700 (PDT) MIME-Version: 1.0 References: <201901021709.x02H9ZPM004185@repo.freebsd.org> In-Reply-To: From: Alan Somers Date: Sun, 28 Jun 2020 18:49:36 -0600 Message-ID: Subject: Re: svn commit: r342699 - head/sbin/savecore To: Warner Losh Cc: Mark Johnston , src-committers , svn-src-all , svn-src-head X-Rspamd-Queue-Id: 49w85n2FyYz46sg X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of asomers@gmail.com designates 209.85.167.169 as permitted sender) smtp.mailfrom=asomers@gmail.com X-Spamd-Result: default: False [-1.57 / 15.00]; ARC_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; NEURAL_HAM_MEDIUM(-0.81)[-0.809]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; NEURAL_HAM_LONG(-0.70)[-0.698]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DMARC_NA(0.00)[freebsd.org]; RCPT_COUNT_FIVE(0.00)[5]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; NEURAL_HAM_SHORT(-0.06)[-0.059]; RCVD_IN_DNSWL_NONE(0.00)[209.85.167.169:from]; FORGED_SENDER(0.30)[asomers@freebsd.org,asomers@gmail.com]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.167.169:from]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; RCVD_TLS_ALL(0.00)[]; FROM_NEQ_ENVFROM(0.00)[asomers@freebsd.org,asomers@gmail.com]; RCVD_COUNT_TWO(0.00)[2] 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: Mon, 29 Jun 2020 00:49:50 -0000 On Sun, Jun 28, 2020 at 6:46 PM Warner Losh wrote: > > > On Sun, Jun 28, 2020, 6:41 PM 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? >> > > So the other spots adjusted large, but this one sets one of its elements. > Help me understand how that is a leak? I'm sure I'm just confused. > Because strdup itself allocates new memory. strdup's return value is always supposed to be freed. -Alan