From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D729258EF9 for ; Tue, 7 Apr 2026 14:32:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775572323; cv=none; b=UEhkXjtA5WPXmhM8MQDNh3Ct/iLFVzf8+/eZPJ0l4uuvp5fFhpL6rOxIHrMCoB/CRAoyIBPVfXyRCyEkBXlX/nslgExZtj6UIlaRntZwVkDqHn6+eA/KzzeEemaJIBea5d88Y4M/4EpE1RO5iZEm8/T14ZMJGufq8T6WNObWic4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775572323; c=relaxed/simple; bh=Hwkc18V7UnWYvRKdBZWpOF4mija3KB5Yt4sYIH5szJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FOOPONW+5q4CeHcoyBtJRJ+VeXr+yGWCVOWewOkEPCfnbqU2TY1NP/WjhEMLM1oO+YSOym+Jt/QGNfWH9U+OluRqH0/dPsWMclCzSZacmM8+m8lAhDUdkBIwoVHuV27I7mV+vnseFBLvKQw8C8mN+ThyyG/HiMDKnxrRHerwnBw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=rQPVVxhk; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rQPVVxhk" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2aae4816912so32301055ad.2 for ; Tue, 07 Apr 2026 07:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775572321; x=1776177121; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aWlqSctU1ZNN/z0ZDozfOPMSEatR6CHgCywrgmA5uDE=; b=rQPVVxhkEd0o5tOJeTOk+/cyi1lcobMbxZSrqRFcS64TBGiDKHrbmu4LNIN6kM47+l y0Yq0kjwilOQWNDfUXumKd0w05uC6l3YaY1tudxXSybFmrvjC73Zp2pIUdHVfhZpZgaU a1oD2iVjv6uTVZFpd3gAOmNdHv9H2ddYQddP+l03Qmzk5NdJMWDihKtVCAcUZ6AD155L pJUJn55FEo7OECVUTuNGucISw6ijNLMYGxat4IGxQ1gfSt2/WhCanVjfjVKwYwszpRTs T219MzKD7ol/JFtdSEb4/t6qwMQnV0cFNU6Z4zGIhtQxTszONf+nv9TOv0er9Z+ag98i 8EKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775572321; x=1776177121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=aWlqSctU1ZNN/z0ZDozfOPMSEatR6CHgCywrgmA5uDE=; b=DuBUEacup42Gbs2ixea7oQb5IdMybzP0/wrr/aQcmGr6EQVHlnfIXmKGY1zEoaTnvq ta1wpbNfIohI/fZ3VAAAWdkyigzv2Us5bwWgE0XwqdtuO7E8x/0fKl4jm/qA8Ecao5Fn G+8t4yaKy3FrHPWHMcHm5CcVhHQ75bp/sCdWWm6Ev4YI+RKapAy+RKvreixkmFtzMqHn BU2vUd1vilXqUr4QTW5OL0mReQX0DT3pnxwITvtuwxwrH3/ZUqLIK7bgmsu/1ZKMwJsM yaqeYqKN6/fE0QpWoFGQpXuhwH+RH97Dx4azSDtuU4TlGl3tfZMMPbT0ulkWc+KjWi6I UIRg== X-Forwarded-Encrypted: i=1; AJvYcCXcALe5MiwOPCRFOYT/3kp4nAocsVYuS4k80PFAZwpL//UOW9aY6LxLNljfu/LahUBmOQXZI+IxkvOo/fE=@vger.kernel.org X-Gm-Message-State: AOJu0YylbD/Wkv913YBbAvT1o4M10f6LYzfTEpl1euHwZO9yM2CQkQtr 9mbS/XSZJLiB4Q3ChkYKcFSmx7iCPUKAyvfkAyKdXdbA2MP1Ey0OspQh X-Gm-Gg: AeBDiettMubD6dFmfulVvLbot7wsO9M/+npaeClwlfc+I5pvZQpb67WtgSG10M6baiR sqEVZFMfDJwXL9gYMt5nUngAz6MAM4/CdQjP0ZU8MwYo+hEi2tTGfdLZiLyf96BxVetxw8xsQ/B qAoDfA+P3Q2fRLmMoDoEcz1FId/+719jBZtjixHcI1O3xNUAUA7hwrFyYHnj1Ej/jBst4WcS0f/ 8gR2PvTlxQf5iGbtNldO4sPnG7XmF8I9pQIEpX3cVqF6HmJhPrZVHK3bnq4/BZwNWrt5ZaIdkvP 2D0xGhFwss8jNNsi0tzw88Ys9OnYdDNo3uhlDpJkAeRlNqyf/ESqxEHCTXF6Go6tqtoYITqgipP jWfUAxjvI1uYjzeSCaYF99N0pkZSFF9WBLQVVzwe65xC02dV748WzGZmblsaIPQTHL1kTlf0y8+ EzEnxkm4crYh/MDZKvlFLrhdWJ5LX8xes19eiv89P966J1XU6nEHEel2zjqsRD X-Received: by 2002:a17:903:3b84:b0:2b2:4728:aa6f with SMTP id d9443c01a7336-2b2818016cemr160584395ad.26.1775572321227; Tue, 07 Apr 2026 07:32:01 -0700 (PDT) Received: from Mac.localdomain.com ([49.205.216.49]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b2749cbc58sm181201525ad.78.2026.04.07.07.31.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 Apr 2026 07:32:00 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org, Haren Myneni Cc: Madhavan Srinivasan , Christophe Leroy , Venkat Rao Bagalkote , Nicholas Piggin , linux-kernel@vger.kernel.org, "Ritesh Harjani (IBM)" , Christian Brauner Subject: [RFC v1 1/6] pseries/papr-hvpipe: Fix null ptr deref in papr_hvpipe_dev_create_handle Date: Tue, 7 Apr 2026 20:01:35 +0530 Message-ID: <5984bd91ad6d3541d08dc9f3c99e6de0214dbfcc.1775569027.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Getting the following kernel panic in papr_hvpipe_dev_create_handle() when trying to add src_info to the list. Kernel attempted to write user page (0) - exploit attempt? (uid: 0) BUG: Kernel NULL pointer dereference on write at 0x00000000 Faulting instruction address: 0xc0000000001b44a0 Oops: Kernel access of bad area, sig: 11 [#1] ... Call Trace: papr_hvpipe_dev_ioctl+0x1f4/0x48c (unreliable) sys_ioctl+0x528/0x1064 system_call_exception+0x128/0x360 system_call_vectored_common+0x15c/0x2ec The error handling with FD_PREPARE's file cleanup and __free(kfree) auto cleanup is getting too convoluted. This is mainly because we need to ensure only 1 user get the srcID handle. To simplify this, we allocate prepare the src_info in the beginning and add it to the global list under a spinlock after checking that no duplicates exist. This simplify the error handling where if the FD_ADD fails, we can simply remove the src_info from the list. Cc: Christian Brauner Fixes: 6d3789d347a7 ("papr-hvpipe: convert papr_hvpipe_dev_create_handle() to FD_PREPARE()") Reported-by: Haren Myneni Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/platforms/pseries/papr-hvpipe.c | 50 +++++++++----------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/arch/powerpc/platforms/pseries/papr-hvpipe.c b/arch/powerpc/platforms/pseries/papr-hvpipe.c index 14ae480d060a..ef10f5a5a4fa 100644 --- a/arch/powerpc/platforms/pseries/papr-hvpipe.c +++ b/arch/powerpc/platforms/pseries/papr-hvpipe.c @@ -479,21 +479,8 @@ static const struct file_operations papr_hvpipe_handle_ops = { static int papr_hvpipe_dev_create_handle(u32 srcID) { - struct hvpipe_source_info *src_info __free(kfree) = NULL; - - spin_lock(&hvpipe_src_list_lock); - /* - * Do not allow more than one process communicates with - * each source. - */ - src_info = hvpipe_find_source(srcID); - if (src_info) { - spin_unlock(&hvpipe_src_list_lock); - pr_err("pid(%d) is already using the source(%d)\n", - src_info->tsk->pid, srcID); - return -EALREADY; - } - spin_unlock(&hvpipe_src_list_lock); + struct hvpipe_source_info *src_info; + int fd; src_info = kzalloc_obj(*src_info, GFP_KERNEL_ACCOUNT); if (!src_info) @@ -503,26 +490,33 @@ static int papr_hvpipe_dev_create_handle(u32 srcID) src_info->tsk = current; init_waitqueue_head(&src_info->recv_wqh); - FD_PREPARE(fdf, O_RDONLY | O_CLOEXEC, - anon_inode_getfile("[papr-hvpipe]", &papr_hvpipe_handle_ops, - (void *)src_info, O_RDWR)); - if (fdf.err) - return fdf.err; - - retain_and_null_ptr(src_info); - spin_lock(&hvpipe_src_list_lock); /* - * If two processes are executing ioctl() for the same - * source ID concurrently, prevent the second process to - * acquire FD. + * Do not allow more than one process communicates with + * each source. */ - if (hvpipe_find_source(srcID)) { + spin_lock(&hvpipe_src_list_lock); + if(hvpipe_find_source(srcID)) { spin_unlock(&hvpipe_src_list_lock); + pr_err("pid(%d) could not get the source(%d)\n", + src_info->tsk->pid, srcID); + kfree(src_info); return -EALREADY; } list_add(&src_info->list, &hvpipe_src_list); spin_unlock(&hvpipe_src_list_lock); - return fd_publish(fdf); + + fd = FD_ADD(O_RDONLY | O_CLOEXEC, + anon_inode_getfile("[papr-hvpipe]", &papr_hvpipe_handle_ops, + (void *)src_info, O_RDWR)); + if (fd < 0) { + spin_lock(&hvpipe_src_list_lock); + list_del(&src_info->list); + spin_unlock(&hvpipe_src_list_lock); + kfree(src_info); + return fd; + } + + return fd; } /* -- 2.39.5