From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 2D5E930FF20 for ; Thu, 14 May 2026 03:45:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778730332; cv=none; b=bhre9du5asra8ZxTVakTlOvXLGVuMrpQmgKke2qyi+W+ypimUkfC2mPLAa4yRf/QqHFbfw7i/Zx/6j/wTIlyaElzh82IpdBSV0w2EaN7h9eZ4nR7XvjI4OzwWrQ34EnPihAkZsoCt6Hno8G7CfOvvEkubrBbrqEypkEpnIdggG4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778730332; c=relaxed/simple; bh=7fzvXNkKyCgXZZTF525bDdETOC4962M9Zz1rkuNpoXU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XmaBgKibK2F/BtuJ9tlN4pmYyzAOgom4/aG04jOVDbCE2NUu3f/Q9/2752mcfycDW0f+e6AoGHeVhAQshO5zTUwir2TBdLkD9c+cPguPCDg+grZbKM76oD+w6rgBFMp3rTn9aZy84fLDbKSqdBIuVTsAuuCZH2lbktMUIz2LN8M= 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=MSh5gt1O; arc=none smtp.client-ip=209.85.216.53 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="MSh5gt1O" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-366375c4076so3588458a91.3 for ; Wed, 13 May 2026 20:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778730330; x=1779335130; 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=8zuozrY6hf5U3ahVFjB+fzD34V5OcD0q+0qREX/Mock=; b=MSh5gt1OOBybQyMBdfIlc6YkaGFjaLmyLnTLuRCdeAhY4NPnT06YbkKD8cfYQoTjlZ ngbCOkYHqjO+8DIykBSDhJqrdxg0z/nuz7uUul3eQa+9EDYEMuLrzsQy4n+iI3Y5UPI+ AoU4uy4X5KZl2DFY1/G1Jdy7ZyC9Uy1++4PFvx0VnEb62m7uzhAFBGZ0XlAhC6gZhaf+ LW1HWggTS8IxFPLjFlEkefTurFSkfKppclMy76YZ6L2kZBpNBBrZTkH2KcPLElZq08lv VWaInzn3rVMb9AfreKv/VVeIMK8kPR/m4mFSJVMjL5HNMt00dCvDZckNxZ8rBjWJmjEU t2sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778730330; x=1779335130; 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=8zuozrY6hf5U3ahVFjB+fzD34V5OcD0q+0qREX/Mock=; b=BvLnvlgLmDTNhL04Llpfk2me7Xw+iutrbPRie/2zLacGYdpN+Zn2yUc2BU1Taxszf0 bZWUexKR283c+uzPP/AKkmCl3BnifMVVPFkzonASyxB2y61cYD1TviaitQ9A0YL7+BRR EKghkkK21hgjfkBj1dtpFyHASiqcMZKoWlAEcjOFbUJjjw3ArAKzSlq0z8PQfngCzK3c AgZvwbhY8z8DVlqEX7XdtN69WudM4E7qvtE/8O8a07R2Rkzy12CNTZyqljCwSmyfV0v9 AEEIw04TDRnqVdprFNFeUMLpOWTstBASqcuXCnmbfo8p57FX5mGbOQzf6mkVUg/xn8Ai xikQ== X-Forwarded-Encrypted: i=1; AFNElJ8jirtVNk/G5fHtQizaIHjCrmKfp08FzHxCnfzP6wIg7Q2E3FftUfa8sMfWroSscdkaTDO7R2p8/WNjUjE=@vger.kernel.org X-Gm-Message-State: AOJu0YzQbQMNTydp1RXPcyfhDUhaqlp3FZfgRU1lC7Vb5pqMaOzSZLWC PLecowFPJBFzhRu3bcfdlMiHrHyiJABvFy7BgGtuu6/Ftm2lyNc+Dxh9 X-Gm-Gg: Acq92OEIPo2UWlJTckxpb4uB7IOtHzjcI+mf1fT0Kwaj7L/Dw7s+5+uI6NeHUTn6e2N U8LiowCZQysw+jr6t9Q1iU5ICfHlTtVNTx5a9HoYdQOyqC1mWFy6r5lDYb7OCiEAYtT0rjRPyMb ensGzfMzd7tMvo7wiHP0hkbnV0zUr026KHtc64hf7xXbXN/PKO5o5e5P5pnyEn9Pn2R3xfPlaKM AM6k0EZFeyOcBYk2RS1bz79KwVEHzH7jNqqRUrIsd4FjQ8NIje66UT+6iEtH74MVx2eYQUTiCAm Us7m/qtO2X2IHhCRFDMOcS2sYV+lsXjWWxPFIuqkNSBNVDKA5Iz12R3NnunZKibuycn3G5g0+5g t7OjfJJeWkgvT+xd4tS0aUhIKpm9Fow8Tr5yFJbiG4heGQf4imcv+l/8dw8QYvQrREIN3o7qa79 txyzlfuyOcvfs3JrPaO+ti7wtTkO2pquxlHkTUcvrGzsvGPkDpjzTSpuCWVgncgfxIQ9gEDo5qg A== X-Received: by 2002:a17:90b:2d4c:b0:366:1bab:c3d6 with SMTP id 98e67ed59e1d1-368f3ab59c9mr6146223a91.10.1778730330166; Wed, 13 May 2026 20:45:30 -0700 (PDT) Received: from PC.asost.local (fs8572fbce.fkol001.ap.nuro.jp. [133.114.251.206]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-368edf4d940sm4434485a91.7.2026.05.13.20.45.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 20:45:29 -0700 (PDT) From: Rion Kiguchi To: gregkh@linuxfoundation.org Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Rion Kiguchi Subject: [PATCH v4] staging: vme_user: validate slave window size against buffer size Date: Thu, 14 May 2026 12:45:10 +0900 Message-ID: <20260514034511.4244-1-kiguchi.r.sec@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <2026050947-easily-choosing-2f91@gregkh> References: <2026050947-easily-choosing-2f91@gregkh> 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 VME_SET_SLAVE ioctl in drivers/staging/vme_user/vme_user.c accepts a user-controlled slave.size and forwards it to vme_slave_set() without comparing it against image[minor].size_buf. The slave-image kernel buffer is allocated at probe time with a fixed size of PCI_BUF_SIZE (0x20000 / 128 KiB), but the configured VME window size can be made much larger via the ioctl. Additionally, a slave.size of 0 is permitted, which causes vme_get_size() to return 0. In vme_user_read() and vme_user_write(), the boundary check (*ppos > image_size - 1) suffers from an integer underflow because image_size is size_t. This bypasses the bounds check entirely, allowing offsets beyond the actual allocation. Result: a local user with read/write access to /dev/bus/vme/s* can trigger out-of-bounds read and write of the kernel slab adjacent to the slave-image buffer. Fix: reject slave.size == 0 and slave.size > size_buf in the VME_SET_SLAVE handler. With this check in place, the existing bounds checks in vme_user_read() / vme_user_write() against vme_get_size() are sufficient to prevent OOB access. Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Rion Kiguchi --- Changes in v4: - Add check for slave.size == 0 to prevent integer underflow in bounds check. - Remove trailing whitespaces inadvertently added in previous versions. - Remove Fixes and Cc: stable tags to resolve checkpatch warnings based on maintainer feedback. Changes in v3: - Drop redundant checks in buffer_to_user() / buffer_from_user(); the existing vme_get_size()-based bounds checks in vme_user_read() / vme_user_write() are sufficient once VME_SET_SLAVE rejects oversized windows. Changes in v2: - Use git send-email instead of Gmail web compose. - Drop redundant Reported-by tag. - Add Assisted-by tag. drivers/staging/vme_user/vme_user.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/staging/vme_user/vme_user.c b/drivers/staging/vme_user/vme_user.c index 11e25c2f6..ba4c9a6d0 100644 --- a/drivers/staging/vme_user/vme_user.c +++ b/drivers/staging/vme_user/vme_user.c @@ -394,6 +394,16 @@ static int vme_user_ioctl(struct inode *inode, struct file *file, return -EFAULT; } + /* + * Reject window sizes larger than the kernel buffer + * allocated at probe time, otherwise subsequent + * read/write would access memory beyond kern_buf. + * Also reject size == 0 to prevent integer underflow + * in the boundary check (*ppos > image_size - 1). + */ + if (slave.size == 0 || slave.size > image[minor].size_buf) + return -EINVAL; + /* XXX We do not want to push aspace, cycle and width * to userspace as they are */ -- 2.43.0