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 9FD3732470A for ; Wed, 1 Jul 2026 09:26:58 +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=1782898019; cv=none; b=jD9i5qPo5C6CzoYbtPgeXHRfTSl+5TfnumQ8t0/u1L3y0BJpDo0RbbO9xrjqmnktGQfHVvYv5wjXZxKsu3gNbKMbGtfshQtSyxIL33oIZt6NHR7E0WlRiC1iXS6XTXbnxG0Q78aTB7UirI19wPTUr/Y1bWJ6IVUbcv8GYOqNL1A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782898019; c=relaxed/simple; bh=tdHKaWa0Gt4+LZ4Wk7MfneHiBviRjXEooHrfKoQ+v7w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FljHkCy+npe0fTG/T8eQC+pAE5BI4naS8YRXLK5/utsjv9clOvsHHqejLovJLJd6kiiKMIzKJRJRNU48f67eZlPPw7d82lKEp27iYDJunbqRTomYaL7rfrcRHt+ZNA/updR4r6uu6Lc2ZRPzdA1KIrwpQ1G9Auc71kdVCdt/eto= 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=oFeXFDH+; 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="oFeXFDH+" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2c9c9916f75so2064185ad.0 for ; Wed, 01 Jul 2026 02:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782898018; x=1783502818; 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=b1WR74p3+F3IkoziGHyid7Q9TSWQf8pWT/tkboKzlew=; b=oFeXFDH+YYS/BGChorJN1uPTVz/cxEET/eQUrY5mOTEtxwhBWyBZnXXkmjT33IiRgb ekhgAjCpg5eTCXlAMewYktCFV9sw3VBbbi+9jajjpOfq4aRq0ZAa5Tc8UHWo74js0s3k DHti43mkIhrm4e+LmT6ewb53rcpPswNUp9OAxeUWqbJyHODejQqz2UQpQeZ2N2cGkaoD vf7sQQcgB/NR1Jn9fRPeNEIRCL++HXE5akLbZ7KTDmMiDEEIf/ZjiDXuq6+HSijZtYiK /jlylRhD5SatM4VdvONr7rHqsFaIL04ybafIqTLSO87yA1VJBBautMs2+8BtVBwiFDE+ FR9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782898018; x=1783502818; 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=b1WR74p3+F3IkoziGHyid7Q9TSWQf8pWT/tkboKzlew=; b=Poo9zeS7tVUxzEF26LByUeap26g6yRb6BoO+p/SkBh6kEvMqYtCGcFfVgtbRWrNaMv KfaoazCJ9+oI+Q3iBrRaKZnQt9T6V/u36cs+Ew2LWJWrMGs+/p5PRyT+Jz1E/wM9NPzH Xm8HUsxjkGgfL2AdFFB4pGGQdrt6x5mpDPqkMIFqz7t14SIEgj1S35+d5NIJDhQ3irSn 2KUlqZXf15vJ0tOD2NScoLSEcCP6jlo4qj1zaflc4yaaw+uvc19qdtl0PXWj3cNqzyy2 QPqYlLujLI9z07zG+NM89niL6S35emalaGH3doTR9m/+ymhep1iakfanfwPiUqMiToX5 mONQ== X-Forwarded-Encrypted: i=1; AHgh+RpI+yMH7yqKYR8g0xlvdWn6q2mZfO8JmH2mFuq4A6u7UlEIRMcEJKfB3crYPnffFs6143Vj1WG4Of5xSfY=@vger.kernel.org X-Gm-Message-State: AOJu0YxFCZapmGRSHHHY2tBDVWQxDJVgknoFOa2guq+WThz/nuDOUy8s 2nWGM8BaMk14WoyUrYJtxxIH9EOeG4KEbDMO43tUMYKCLZziQnJVb8zf X-Gm-Gg: AfdE7cmFKczOY3hdYmCvcTA7mzhUwfv9AaPOHkNoMA/sq42vKTI8zuySsfq+7rJ+JRB nCRUNMR8tB2Eg4frKTBloVp5flcaGGcrbwuCez3W/v+Yk3lsJUXHhu1NKXRddGRXuEBtxdb8zG2 S8irVIOGBW7QqdhXOmDABUqzCRuoB46a16WzjEOkDteiXXAC5Mevz5pd9rmhri0AJxMnK8+6c6V Us6mt0/gQ4Oji3YQsFcdrWMRkjJBCqEWHS/Ziq3CasPF0SzxRrHXRA55gFp1vzrF9RWnshDpHkz qID9pXESGRiDj+r+pxOpxW9pAC/hyui6KsOqoU6ARcdwk1nmWYit0SnnaIbOfB+AAkWt0o0yDpH 40A9A+K1ACXa1OYiSSwwVcBCPzQaPGPcSPPmqII7PRMY1fMMxuFrOcEOpACSC7ga5svrsqx7afm t/EwZ+KezqZJnzSziZ68ZEAUAcwsRlEu+Z1G9Jy3UJ X-Received: by 2002:a17:902:ecc6:b0:2c9:fa31:84f9 with SMTP id d9443c01a7336-2ca7e682af0mr8905515ad.5.1782898017723; Wed, 01 Jul 2026 02:26:57 -0700 (PDT) Received: from trigkey (FL1-133-202-37-214.tky.mesh.ad.jp. [133.202.37.214]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ca6853f616sm11138795ad.37.2026.07.01.02.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 02:26:57 -0700 (PDT) From: Daisuke Matsuda To: yilun.xu@intel.com, mdf@kernel.org, trix@redhat.com Cc: linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org, Daisuke Matsuda , Daisuke Matsuda Subject: [PATCH 1/2] fpga: altera-cvp: Avoid out-of-bounds read in trailing byte write Date: Wed, 1 Jul 2026 09:26:32 +0000 Message-ID: <20260701092633.5146-1-dskmtsd@gmail.com> X-Mailer: git-send-email 2.53.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 From: Daisuke Matsuda The trailing byte path in altera_cvp_send_block() dereferences a u32 pointer even when only 1-3 bytes remain in the input buffer. If the buffer ends at a page or scatterlist boundary, this can read past the valid image data and fault. Copy the remaining bytes into a zero-initialized u32 before writing the final word so only valid bytes are read from the input buffer. Fixes: 34d1dc17ce97 ("fpga manager: Add Altera CvP driver") Signed-off-by: Daisuke Matsuda --- drivers/fpga/altera-cvp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/fpga/altera-cvp.c b/drivers/fpga/altera-cvp.c index 44badfd11e1b..c00292370a8e 100644 --- a/drivers/fpga/altera-cvp.c +++ b/drivers/fpga/altera-cvp.c @@ -16,6 +16,7 @@ #include #include #include +#include #define CVP_BAR 0 /* BAR used for data transfer in memory mode */ #define CVP_DUMMY_WR 244 /* dummy writes to clear CvP state machine */ @@ -261,7 +262,7 @@ static int altera_cvp_v2_wait_for_credit(struct fpga_manager *mgr, static int altera_cvp_send_block(struct altera_cvp_conf *conf, const u32 *data, size_t len) { - u32 mask, words = len / sizeof(u32); + u32 word, words = len / sizeof(u32); int i, remainder; for (i = 0; i < words; i++) @@ -270,9 +271,9 @@ static int altera_cvp_send_block(struct altera_cvp_conf *conf, /* write up to 3 trailing bytes, if any */ remainder = len % sizeof(u32); if (remainder) { - mask = BIT(remainder * 8) - 1; - if (mask) - conf->write_data(conf, *data & mask); + word = 0; + memcpy(&word, data, remainder); + conf->write_data(conf, word); } return 0; -- 2.47.3