Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp539053lqo; Fri, 10 May 2024 07:29:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWtQWzSJYtufexAc6n9jc7iD8hFABtVr21PG04TKXf3UC4M/nN+G4wTpmwNw+hBYYnnCLlGjq3A2mK73r57DahYz0oTBaaZAkhKBauJEQ== X-Google-Smtp-Source: AGHT+IECoczJOfkEi3wkO46SVPv+IbEYCmWLFEh8Ol0ZAMALd94IOpVfaVQVBuJggbGmFcmRxdZo X-Received: by 2002:a17:906:2510:b0:a59:a7b7:2b9e with SMTP id a640c23a62f3a-a5a2d53ae41mr174970966b.8.1715351359732; Fri, 10 May 2024 07:29:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715351359; cv=pass; d=google.com; s=arc-20160816; b=SmvCGuGEcA+uPJMU2HC2g5YgQg3o9EX8LlikKH33CTkoh8h3cGi+C/Ek1BEBFHYNsV lobTTYFojmxnCN4VVtw15ZR63C5ePPsmm1/CHb8XeILcYbwa3qpq4qvAtBFkcGV8hQ0/ nV+d+FLvdoZSYObZKD2Cwsh4iKB8QmHy3UV+Dy7JRR1XGBqOuC11f3hqQvaq0rqKROu0 wL86qVZEL0wl0M7kS7TNR7JcMDgzYSGRxp1Ivg0WTieCCLG1s0s9psubltH4OFbUADma LOYljH9ruWXT7MB4KuOVm/TVG1Wx0jqgE5bdKxNQoL9jktR3SvnnbIgtZHObo5ytzPDs /i5A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LhXFn2qd8xft0a0Ixm7P9NB15y+HRWWxkIQmtp0U9aY=; fh=oEnc3yB2Gf/3TN8q+c86zpdVzwuYSzaXN1tRdpzs+D4=; b=owuGwzKpdoYtU4068wxzGzksmpzC0MExzBWMASRr/wKicbvVBBNUrc1qZT0M4WhGVz 7bqF8Ye6KpO60Q3jdL+dFowxK6SK0TIEAWThc8eMLJgB4hMyFP2mssdL6boUmAFPV6qJ b4Gky/DXIhdKVsXfaMITVVBW15oK3YArttFDp+ep4XDSUu75KUTbAYfuaT480sosJigj raM9p0OVuxvL0bMtEXcD0EoNDw5FbhbBgMUlVbGxRyYndtiAmorDWEddRzasX+Bky5FD 9913Vlx2FBSR201C8k9VwaZLqISneQtWYQcgrQMhMXMdS9I+uRLIXThnBLoOuU+KQNP1 4eoQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PFsB9Tf9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-175903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175903-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17945d0bsi206707166b.138.2024.05.10.07.29.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 07:29:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PFsB9Tf9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-175903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175903-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 75D491F249E0 for ; Fri, 10 May 2024 14:29:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C90A8481DB; Fri, 10 May 2024 14:29:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PFsB9Tf9" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1A1616E898; Fri, 10 May 2024 14:29:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715351342; cv=none; b=dOo2xdoE5/INSWiyTDqQ6c7o3OUZBy9UVVpc5i5Hi6qnEoxvhvgLeOXbJeUloKmdfjwKSge+tjApYomg3iVNIVFFGWi0n3QFEzMZgkwvfnKpwSRbv4eRymfKIHtTW5wYxuXoGgb86Nt+ff17vdDZ06jU8TTgTrAPii32Y4hvB2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715351342; c=relaxed/simple; bh=bkyDcW4SzquH0cCfq7aZdUGB8FDuymzITPFrA/FnaYE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O+i0VRJ4tyoXnziZ/va+Lx6+oAmP1rDS/lG3UFPV9qkxZrCI3E9XtifKL0SMTb6SkbwqY86b4+womLKx9TxGjAZEx37OueID2kC2eYTrzLijl76gKjLoklGdOZGk+0Ts35J8XBCEddcbF8+B/tM2Ka+3bDC0F5oiYUOkQMvjIcE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PFsB9Tf9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D6DAC113CC; Fri, 10 May 2024 14:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715351341; bh=bkyDcW4SzquH0cCfq7aZdUGB8FDuymzITPFrA/FnaYE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PFsB9Tf9/uP6IFQZ2dJapq18nQUgwgPKUNV1ASDadJQTo/IymTBjSckwJusU92T3m nYm23NT9VA9nOwADhFrc6u6gWHfdpvU/RWfEB9AVCXbsMnCs3iodzVs0XnwY7BEROg ylGMqGg3ClHRvD1u3Ts+zee9kY83KZ4OvKwNSVR6v3/5xes+a631N5wpPmR8jyvAvn +SgZuegx7KDsnNk1WJzkZdeonf90Ev6+Y/usDmf7xm7+QZDu9Ge1BqH0nyuo+YuGpe vqgJfk+w1Ih8ZGxBaDroiyUtHpUpEE44e6v5sdqgp/lJ2r2qZIbZjnEDovjzvtaWHj +7t7aEQV6GQCQ== Date: Fri, 10 May 2024 11:28:58 -0300 From: Arnaldo Carvalho de Melo To: Samasth Norway Ananda Cc: namhyung@kernel.org, peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RESEND] perf daemon: Fix file leak in daemon_session__control Message-ID: References: <20240510003424.2016914-1-samasth.norway.ananda@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240510003424.2016914-1-samasth.norway.ananda@oracle.com> On Thu, May 09, 2024 at 05:34:24PM -0700, Samasth Norway Ananda wrote: > The open() function returns -1 on error. > 'control' and 'ack' both initialized with open() and further > validated with 'if' statement. 'if (!control)' would evaluate > to 'true' if returned value on error were '0' but it is actually '-1'. > > Fixes: edcaa47958c7 ("perf daemon: Add 'ping' command") > Signed-off-by: Samasth Norway Ananda Thanks, applied to perf-tools-next, - Arnaldo > --- > Found this error through static analysis. This has only been compile > tested. > --- > tools/perf/builtin-daemon.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c > index 83954af36753..de76bbc50bfb 100644 > --- a/tools/perf/builtin-daemon.c > +++ b/tools/perf/builtin-daemon.c > @@ -523,7 +523,7 @@ static int daemon_session__control(struct daemon_session *session, > session->base, SESSION_CONTROL); > > control = open(control_path, O_WRONLY|O_NONBLOCK); > - if (!control) > + if (control < 0) > return -1; > > if (do_ack) { > @@ -532,7 +532,7 @@ static int daemon_session__control(struct daemon_session *session, > session->base, SESSION_ACK); > > ack = open(ack_path, O_RDONLY, O_NONBLOCK); > - if (!ack) { > + if (ack < 0) { > close(control); > return -1; > } > -- > 2.42.0