Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp201209rdh; Tue, 13 Feb 2024 14:11:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVQacDMRLvIdKxWg0AB2xrTE5UE8228BGzQCuKhy001GbE59c5/aEnXfzZjshrpHgDH9bsPg7TSL3JL4tYkjOQBKwELpEUxuWt18v9jgQ== X-Google-Smtp-Source: AGHT+IHTyoxftxth+8kv8b6m5PlHDqPvHWQDxqK5YSS5saqjIjActUIBsgpou1mqpnpP4aW1QZP2 X-Received: by 2002:a05:6a20:6f8f:b0:19f:c0d3:475c with SMTP id gv15-20020a056a206f8f00b0019fc0d3475cmr896542pzb.3.1707862268613; Tue, 13 Feb 2024 14:11:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707862268; cv=pass; d=google.com; s=arc-20160816; b=loyQdR9gV72MZ5Kxj9snCm73FfOr5ZFJQy2N7F0ZXY3rufiv/ZnWVUGqJ34FRoKEIM Ce10fopVCTA3A+em2k3j9h1BKyPTpgbAo18cp8oHOQiwraDt+Xhi9vooffLEg4MQdEQj HeGSGyNrhy4M3IbZKJzCrRVfJwIPKW+04WIlQLNWe01UQi5KoweoNLMsz6iX4eKG0zwG s2fj9TOZTUfmrskOGTwoafwYraxhI2fO1g0f4dVeuFshoboTc3VRXqSYUcA4AzYrgfEr lZ+SEGUAceZgkI9qbNAuuZnMN0vH6wiRoSIUKED0c6yVteZmi+8+NaT9OZMJLyzU1IcL wvHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=ukCGGXI9Jxb1GstaggI2PMFSAmqWV+ZT0DPIrBgA8Ns=; fh=3io8rmGfbJEgL0YPT46wKkC8ZGxXsE1yFCchjc5hCMM=; b=eReb4+o744IBXZw+FOAe5Sbrmx9QfRHcaS7/SbXsuYWRXQuJp/sjlgRHVel0mStqVU CA2PupF1CbYs+vXtrAhlb7ls+vkbDBsMaMeL2/SsqCnPwgoXUpltQ2ol6qb/BqQgKCMj 8VN+SimHGAPVUYRfbW3p1vRKpOeeFG3u1wN8ivABu0Mhzupn+rRR8qMxQGwiAl8yo9BB 7wFPawx77ljAmQVyYARI+GL//oXXJWtjFiP9/KZCfcMOVi9sqOX3psmnL5gPBrQB9dEv rN6O0C/K8XJpl/MpXw/ZthWgeu4KzsPBQfOObMZb0E/07efDKMqtMIlN2rAu9jI6VbVK EA4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=hFwIPqHd; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-64408-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64408-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com X-Forwarded-Encrypted: i=2; AJvYcCWm3FcwDbNjdU3rFin213kx7gVQdZXQCix0meZ+92FQtcyaf1P9a2gX/f8eH6sQfiprdmZhQ6AbFVs2ivJAAVZ3b+HzwEI0WDbjHLZekA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h64-20020a625343000000b006e0914ba858si7294970pfb.19.2024.02.13.14.11.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:11:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64408-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=hFwIPqHd; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-64408-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64408-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E07B6292895 for ; Tue, 13 Feb 2024 22:04:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF666634EE; Tue, 13 Feb 2024 21:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="hFwIPqHd" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 5B9FD69D00; Tue, 13 Feb 2024 21:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861550; cv=none; b=f6LkcAkr73xXd7di63hR+uJ2zhE3x6zi0LhBlegOjasuYjfN9YWac2aRMygkXnb+wvniEI0LjJN1BSp7RWBuJN6nAHOTMn7oTbd2O6eHMQxFJ5FWcdcLgR8WVWAqsOiJ4GHKovTTEsL0pCFGcXYS+Lfeief2wVvcWiAsxORIzYs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707861550; c=relaxed/simple; bh=JJZKe2t0kamyMzVROuPedbDxFm+zHMjxwqHfKjv86Vs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hNNx/AKoi6sNludGWLhIl+rJF7ZEZIkprNKtEAd3LJJvsCHg7Rb4ZSPKAZ0C6m9b9I2Qiuy8Q3ty2gGtoegGsrkkdFVSUaRrjSgpIX+WRC6IkDAoiAxttn98ei4rE5+k7y12cbbeyxsa0Lnm+CsjYeheuRA9FakQLOvp60SRxuE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=hFwIPqHd; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41DL4fIu001929; Tue, 13 Feb 2024 21:59:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2023-11-20; bh=ukCGGXI9Jxb1GstaggI2PMFSAmqWV+ZT0DPIrBgA8Ns=; b=hFwIPqHdkoDZYsVMHJ8zXgJ+TLgjlWOfxhztM+UJgYDB/AWOR/3a984ul5nwA8gnexMD i2V7x9UOLzu2YlSdaCrIH9yAZYVhuetntb8L1SNgT0bRzg9aLZ6Mwr5D0guvTNOudA+x KLXRDsLvFFFnEsrHxvZ5LGr6B4+jFRUu/i2Cd3rwZ/NskzqDODb5HID+pXZL7ryJ4m9f VVixqT6zm3xj70AINFvCMrEjhDlRvMkXBtLayIl7LXq1EX5gk+fG9NBUmer1bF3WPTrS kF3fRfvr/fZeyerU0eCJZO+rqqbCZL/2B8iGMaTBVKg+oDziNTRRhbiMtBRgtlApHTud Cg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3w8cxr8p2w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Feb 2024 21:58:59 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 41DLFAtr015276; Tue, 13 Feb 2024 21:58:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3w5yk80tj9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Feb 2024 21:58:59 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 41DLwwaX037838; Tue, 13 Feb 2024 21:58:58 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3w5yk80thj-1; Tue, 13 Feb 2024 21:58:58 +0000 From: Samasth Norway Ananda To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, jolsa@kernel.org Cc: samasth.norway.ananda@oracle.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH ] perf daemon: Fix file leak in daemon_session__control Date: Tue, 13 Feb 2024 13:58:57 -0800 Message-ID: <20240213215857.3081841-1-samasth.norway.ananda@oracle.com> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-13_14,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402130173 X-Proofpoint-GUID: UmyLGXzZ-iwIc4jmZcmbUW1efb5iKuvz X-Proofpoint-ORIG-GUID: UmyLGXzZ-iwIc4jmZcmbUW1efb5iKuvz 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 --- 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