From nobody Wed Jun 17 07:22:58 2026 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (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 EC089258EC1 for ; Mon, 27 Apr 2026 04:10:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777263015; cv=none; b=ZcFsp2LO/f88Z/R1eR6VdzkojRyOGbDarPBGsZEOAp5B/EXHJWnV1QGEDSRVLZF4s9wuqLBGEMIyVmLocZ8NVXeZ5TKIG2G0uXPcpWdEi2KgblWCPGa0rq/WM8/OUWM1pr9ZyEBstBoq3DbGQORSl8GKxPFT49X628rpO/unxBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777263015; c=relaxed/simple; bh=hD1dIg0Pn8kTzh7W/SVqNi4Q4KZaffb3XL6M8RlhPHs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lLHzq0/bVBije69BrpdFFzFUxoD385gfY9DPXPeAXirhCLcjO9A9m3OHvGHw6lHjU0un9+3JweaNhVKNRU6NpwJbXhstYnsZGGaEfRUMCKvWWCjXtHFLqKtk5hZdSuFzBC6cCq/WVLIL/hGF1M22PsN6p/eT2crSfI2JSx4SDL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sung-woo.kim; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sung-woo.kim Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-79ab5fd969aso107163477b3.0 for ; Sun, 26 Apr 2026 21:10:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777263013; x=1777867813; 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=Hl0WAnQ535tE4CWpSeGGP4i6YyUr6DuMKmnrzyCP4e0=; b=Pf6sHSPMRSa3f87ng91aH5cUJn7ENLU3bXLlaT2pzbhd65eLkdK9q9eAxf6ftS9bZc LnE6Nnj81QS48igInj8QLxV5SPrjz6cqp26jPbDGYvwZm6XriAiWFKmq0b4K1JNh8RBx mZc6ZrecufVy13mIcw3iXmOKAoozDYlXHoabORJ4V2kU1ZK6UVSxlfpNrub/X81RTfLA q31DkTOGQzvQVo9tinWQdKKb52nERmbwHRaiudXDmOzPKlDerbyci6pKZt2lIEcclx2e NN4HfSZ+sWb9TifsB2xMUucLocul2u/XdDgutK6X7/5e1QqBW5Nk7JSJXHGdA3WbPQRk I5eA== X-Forwarded-Encrypted: i=1; AFNElJ/RomGXi03boYRq3cVBTQdQLLffHaz1AKgBQlTELyeaxCI5CF4A6NWavuRoIF2bTITUGjwFz4zMkyV1qEQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxBsW/U3hSW4xkRmHMxSiB3K/5+UuEbGb7GjbcjdhA0mcJFHl89 oTtV6+VbFYAnsTrs7QY5v0l1TH2au7p167dMCpl4k61D0iY0fC1wSdKQ X-Gm-Gg: AeBDieuhDVIr1HYp8RE0SZQdjMYb5WHlwVoXl7Jm4Uky+g1i0vEcWG4UIkHQu7OxNtv 2K3O9SAKrHXw4ku4WGI0s+7E7JzYkHgUtxwi/D5bmIa37sHYPq7bNOeU65N9WqxuqgoYinAArK0 DYXAVwcxq1NNX4N69aF6wAE27Sql6qa6XjJwNAlu8tNFeV1X0KavnHU/rEJ6o2IvDHVUqJUvf/v itrRuvHSEfS16nK5OKHs5+eckTVp0vM2Dv+eIeqqCgsZftdwK5JIfWVgNTkeTuYiuezZNmp0FpS nHemQp8DCwc4R72ku88cT+ngW9zYUgcD31Mz4J1QEOF8pbuuPgcMuKKMPIA394LjET73Cdm8t9+ uoevmnnZQq856izwURsLVna1KHYzQlMf59U4W5AQYrgbXcKq0MNTQMFikR7PhZBAcGlbtzunaGl LjfhRjprPvh9WLcLd2METo X-Received: by 2002:a05:690c:6e86:b0:7a2:f14d:5a1 with SMTP id 00721157ae682-7b9ed06a19emr407417907b3.49.1777263012862; Sun, 26 Apr 2026 21:10:12 -0700 (PDT) Received: from tofu.. ([128.210.0.165]) by smtp.googlemail.com with ESMTPSA id 00721157ae682-7b9ee8e2bb7sm120822077b3.22.2026.04.26.21.10.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2026 21:10:12 -0700 (PDT) From: Sungwoo Kim To: Jens Axboe , Keith Busch Cc: Sungwoo Kim , Chao Shi , Weidong Zhu , Dave Tian , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4] block: bio-integrity: Fix null-ptr-deref in bio_integrity_map_user() Date: Mon, 27 Apr 2026 00:09:26 -0400 Message-ID: <20260427040926.987166-3-iam@sung-woo.kim> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" pin_user_pages_fast() can partially succeed and return the number of pages that were actually pinned. However, the bio_integrity_map_user() does not handle this partial pinning. This leads to a general protection fault since bvec_from_pages() dereferences an unpinned page address, which is 0. To fix this, add a check to verify that all requested memory is pinned. If partial pinning occurs, unpin the memory and return -EFAULT. Reproducer in blktest: https://github.com/linux-blktests/blktests/pull/244 Kernel Oops: Oops: general protection fault, probably for non-canonical address 0xdffffc= 0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] CPU: 0 UID: 0 PID: 1061 Comm: nvme-passthroug Not tainted 7.0.0-11783-g9095= 7f9314e8-dirty #16 PREEMPT(lazy) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.17.0-0-gb= 52ca86e094d-prebuilt.qemu.org 04/01/2014 RIP: 0010:bio_integrity_map_user.cold+0x1b0/0x9d6 Fixes: 492c5d455969 ("block: bio-integrity: directly map user buffers") Acked-by: Chao Shi Acked-by: Weidong Zhu Acked-by: Dave Tian Signed-off-by: Sungwoo Kim Tested-by: Shin'ichiro Kawasaki --- V3: https://lore.kernel.org/linux-block/20260420020327.1667156-3-iam@sung-w= oo.kim/ V3->V4 - Addressed a sashiko's comments [1], if it makes sense. - V3 wrongly assumed that iov_iter_extract_pages() always pins user memory. - V3 insufficiently handled the return value range. [1] https://sashiko.dev/#/patchset/20260420020327.1667156-3-iam%40sung-woo.= kim block/bio-integrity.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index e54c6e06e1cb..766cc2d1d51c 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -403,6 +403,23 @@ int bio_integrity_map_user(struct bio *bio, struct iov= _iter *iter) if (unlikely(ret < 0)) goto free_bvec; =20 + /* Handle partial pinning. This can happen when pin_user_pages_fast() + * returns fewer pages than requested + */ + if (user_backed_iter(iter) && unlikely(ret !=3D bytes)) { + if (0 < ret) { + int npinned =3D DIV_ROUND_UP(offset + ret, PAGE_SIZE); + int i; + + for (i =3D 0; i < npinned; i++) + unpin_user_page(pages[i]); + } + if (pages !=3D stack_pages) + kvfree(pages); + ret =3D -EFAULT; + goto free_bvec; + } + nr_bvecs =3D bvec_from_pages(bvec, pages, nr_vecs, bytes, offset, &is_p2p); if (pages !=3D stack_pages) --=20 2.47.3