Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 6F9AD330662 for ; Wed, 24 Jun 2026 17:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782321572; cv=none; b=TEe1MOX/xjDpJTqBBG9YNM1/aW2d7jAicItkL/dbaIPNb5Pa7aJkOm0Y4IPW6EJVlenSPJrkURnZa6HLoPAdbwC46LFX+m6bYk5HszSbxN0thUT9erba6vAurGNe1CImUgEnaxvRwC0c4/nWR/mUMKsYTPXxfRQzlmWYWbeb1SA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782321572; c=relaxed/simple; bh=XYMYAAsvP1GLDeLb85eDbVtSDEfQPGCthhX46UuiuGs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LeFWO/OrDtumIADz3U6boamaIXNyw4fxAE5ajwJpVwwQTvsuSDl+IPK8G9RkjYufLlQc4bEr1Ve6qwEV9lSqyFWo1ozoQgL+yEes34rM/NK1aOaZGSAG86VticspDyv4j7aZZkUZDR4snStc1/BypYy+qvsrDVP3HfOIVfV34SA= 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=Op8MFjF7; arc=none smtp.client-ip=209.85.128.175 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="Op8MFjF7" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-809b19a7f25so6582067b3.3 for ; Wed, 24 Jun 2026 10:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782321570; x=1782926370; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=R2uBNA27A4c4lL+ol2c64v9Ghehwy3z4aoSxA5is8jM=; b=Op8MFjF73LBXjLcspjY2VAnJybN/EJ6f0nt9yYQSzIfrl2YL58eO3H7XCPvMdYVg66 8AyxVxW90+MWjOEowWG4sIxWEwOsEV5qHwBX1qfZ1EX45ikWOyb/VDqTc7NltVSRLyst rZS2R4117xqtngJJn7xxN5MCXrJ3NxRtS/ICOVOoKKSBjY6Do4qWT9z/sSm7JVXy413m IUde1v705DcKRHDibtyG7Xa5uczm9WHH+faMZV//fDq3NXEpM0jq736geyXeEuUfDH2R c6MiiaOM32TBJOvViZLkXDXXwtE0Cf4fnCv3dmWi1ZVX2ys+2eXlH5zKbhHoGA2JDEHy vNrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782321570; x=1782926370; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=R2uBNA27A4c4lL+ol2c64v9Ghehwy3z4aoSxA5is8jM=; b=Pu+ht8gerLGs2dsPqxQ5/v1+v6C4wXk1gXRVDpSwiXuTUQitvjupkASU77iPx38gnQ +3hLm5MKDgH0rvgGNHd6pYLC1hbHVUccs/W1IICkTCDaF11tPr+kVRil8ZDcaUZh9dYD 1Vr52Lq1ZxLpFKkCUZH3+zIYQNj+inzKvJyfQqI0wkb7cylUG2zP7aM8RMVJyIGk+ST1 St3jE9PBcNKF4fXH9kzT7g0OWmblZe/ayYWkMio6ahSiD5t+pYfMLyIefm63UGqPLwFm 3CZgIrEQHXGLoBRT8TTMwqi4y5SzuuALM05aH3rWniZFCk1sAZEYOg2IUwyq8az5/b4W YTGg== X-Gm-Message-State: AOJu0YwlJhkkjGo/TpY87fg0qJih+A1aFVitJTJnqtsjNMpoVy9UUbb1 QL2qhm81c3bKUzNHoHBF6JekvnH/ep1dSlO7pIcZpIcG8KUxV3hmbbeA X-Gm-Gg: AfdE7cn8wT9fUk762SSb8SX6aiyPlsg7bWrj6LVW7GBvnFob6A7y1wigklpjVzWekF3 P/U+wXdtE9PNcKmD5awSCnB5NjSeNokEmcr7fbU0/GmW1hLeTZibB4+N3LpA9oWoIgGgLpeT2bk FCK3OkTwmmrTN+UQW4bY7vu17Rv7sn0U70vDSnFhPJuKez2N/m5sxThqmiEUsC9glvekBb9MIsR 3u1iADMGgnsUYZKY2r2HPZKxzXnAlcksOH1GzCx1nq39hVszhixSjR+VUW83/HeD5fMCPtlfdaP YNStUht3paBtXCuZrSIrjLwrhRPw8WE3qZEXwxhf2a85nKapX2+hLCwZYJ9Q8yBFQ+Zfb9IgqNt 5cS6LnEQ4GtD14HW/WWh658c2O5hJedye0jtqqnH6dehn1I+xLje+YVKVwrO5XzmaxBKTkSZMpx KseIHjpkAQerWkgfI2sTcYOs2WXg== X-Received: by 2002:a05:690c:3683:b0:7bb:712:a755 with SMTP id 00721157ae682-807ed8be041mr42180187b3.7.1782321570502; Wed, 24 Jun 2026 10:19:30 -0700 (PDT) Received: from Dev-Null-MSI ([2a0d:3344:52ac:a808:98a4:4381:be45:536f]) by smtp.gmail.com with ESMTPSA id 00721157ae682-802601b86casm62202437b3.39.2026.06.24.10.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 10:19:30 -0700 (PDT) From: Yousef Alhouseen To: Matt Porter , Alexandre Bounine Cc: linux-kernel@vger.kernel.org, Yousef Alhouseen Subject: [PATCH] rapidio: avoid out-of-bounds copies in CM list ioctls Date: Wed, 24 Jun 2026 19:18:34 +0200 Message-ID: <20260624171834.2179-1-alhouseenyousef@gmail.com> X-Mailer: git-send-email 2.54.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 The RapidIO channelized messaging list ioctls allocate response buffers for the number of entries that will be copied into the buffer, but two paths copy back a larger count to userspace. cm_ep_get_list() caps the endpoint entries at min(user_count, npeers), while cm_mport_get_list() stores at most the user-supplied capacity. Both functions still used the uncapped count in copy_to_user(), which can read beyond the allocated buffer and leak adjacent kernel memory. Copy only the header and the entries that were actually written to the temporary buffer. The reported count remains the real total so callers can retry with a larger buffer. Signed-off-by: Yousef Alhouseen --- drivers/rapidio/rio_cm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/rapidio/rio_cm.c b/drivers/rapidio/rio_cm.c index c55af5924..9dec8be5f 100644 --- a/drivers/rapidio/rio_cm.c +++ b/drivers/rapidio/rio_cm.c @@ -1602,7 +1602,7 @@ static int cm_ep_get_list(void __user *arg) ((u32 *)buf)[0] = i; /* report an updated number of entries */ ((u32 *)buf)[1] = info[1]; /* put back an mport ID */ - if (copy_to_user(arg, buf, sizeof(u32) * (info[0] + 2))) + if (copy_to_user(arg, buf, sizeof(u32) * (i + 2))) ret = -EFAULT; kfree(buf); @@ -1619,7 +1619,7 @@ static int cm_mport_get_list(void __user *arg) void *buf; struct cm_dev *cm; u32 *entry_ptr; - int count = 0; + int copied = 0, count = 0; if (copy_from_user(&entries, arg, sizeof(entries))) return -EFAULT; @@ -1637,12 +1637,13 @@ static int cm_mport_get_list(void __user *arg) *entry_ptr = (cm->mport->id << 16) | cm->mport->host_deviceid; entry_ptr++; + copied++; } } up_read(&rdev_sem); *((u32 *)buf) = count; /* report a real number of entries */ - if (copy_to_user(arg, buf, sizeof(u32) * (count + 1))) + if (copy_to_user(arg, buf, sizeof(u32) * (copied + 1))) ret = -EFAULT; kfree(buf); -- 2.54.0