From nobody Thu Jun 18 08:03:14 2026 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.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 D1D191AF0BB for ; Mon, 20 Apr 2026 02:05:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776650719; cv=none; b=LKYBiPA47GgrCHSFXk34UvpI2YmqWeNP5vvRLkUe/a/QS4+MGPOpu6cg517QEW7CcLLiUFAf/WKPkpdIVRymxi6jIlNb88BebyJmInFJI55cql4ahLjo/4EEQBQMBpWm0UZJgefqHdR5QCQJ11iQnXUy47KfyT+9rRlepwI1FJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776650719; c=relaxed/simple; bh=jQBR9CkQWQd7EuOKvr6gloNXng7hI1A6WAA1mkPzRsA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AMcuR7NPw+nAZVFDx/eMUMabEfOTJcX1+rm2f1xVbGbL2DUaROub0jKLtSt7BZoxJrFXcd4A9UT7/7P7tI8iDrrT0QIqh+oZi7XOnbsJZC6yNFE0x2IGeqLQA1lsPSBvHlEQy+gGQE6iX2mlwRvhpzCyC4h8mHXwTNFrPibAfo0= 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.172 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-f172.google.com with SMTP id 00721157ae682-7b186dfc1d0so33134697b3.1 for ; Sun, 19 Apr 2026 19:05:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776650717; x=1777255517; 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=Gxw07dZGozsSlHhhVNHLtxH0zskFbDiC5pVnF35l/f4=; b=qIaa+tacypLEfbmqUeBGAbC5H6LDlDUcdtQf5+joTYSTieFGMncpnt6MaSmL1NByir BpaCVPCSup2VNv46nKno8HkpkG9+RTOEiq4jjr6pvFvai3fYFt6l1khukpfgi5YAnfBO WBaT2F/cq507rXtwjfg0C6aXgmnzyZZIgMdPrzph9WTIbe9ds1HgfJHqyGJhLdLja1fP F0FJdBfyxmexMDynXt7OSiQ+a2E1GHoCHzF7I64XOugT5vY/0zCksG65UL9mErJpvTQ4 TdeT/vpCvOvMHSDlYmAAzkFkx6SaBG48MLG+d8Q+rw7ZVjEHuHSAbN/V+UN/NHun2WsE b1Cw== X-Forwarded-Encrypted: i=1; AFNElJ8fUUCMqsfnnl7BqNyFY5hXEXpPnz3IJ39gQnIBKpwao9p6CIzdoH9JoujgRqm1G0yPXeuVxNmSFbngNOs=@vger.kernel.org X-Gm-Message-State: AOJu0YzcO7JTJ6XAWKNzRTTK2JQ365zkIm/AcWNJdKtsJwMiWEFs3A9P oxzjye0BEZLxhZWhS/Kj/dDlJKk0Oy3cIAZvUPznYOnrbc5ib81W0irF X-Gm-Gg: AeBDiesziW9HDS+NAP5tGQZ+MSuxFsEnpYrd0B1PJ7aujOFB6Lut2cD0rqFK2v00+Z9 Bnh/lKCqWLxy6tTsuP3zpmqzqg1AMwYeAVFaK+Q4Mmi0QrTGibPbl1KbeN90u4Dh3RXrCasCKgy /Kidc/qfstxpZkabiuaJE+27bieMqVi/tPPi+BfNzOuv8E5aKYReNbk8DelSoMFKDeRIEZFC5gt 3NHZWkOeAW/3Icwd58LAgpCGHGuUrQW8JONbaXF4V3d8qgOATY/HdRyjHatZipM8vBKI0iK1W0o KHNoxv6KWMDUtXC4o9WsNDkVAQZhuBFVVWfJCNqlppl4j9vmusIewDpWx6YY5v5Wmx5nXYqEnse Cj3VNG76QJ7FVfDbJXucCkl1ujCKT60YIJBlXGzP/b+dYPc1hRaOQ4/fpwXTytNLSCqwsgUKPnZ jK5yHwG0PSfgEWTncm4rvNO7oWEG5E/s4= X-Received: by 2002:a05:690e:480c:b0:651:b61a:4b5f with SMTP id 956f58d0204a3-65311989a3amr5415786d50.17.1776650716836; Sun, 19 Apr 2026 19:05:16 -0700 (PDT) Received: from tofu.. ([128.210.0.165]) by smtp.googlemail.com with ESMTPSA id 956f58d0204a3-65314b5faf0sm4518980d50.5.2026.04.19.19.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2026 19:05:16 -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 v3] Fix null-ptr-deref in bio_integrity_map_user() Date: Sun, 19 Apr 2026 22:03:28 -0400 Message-ID: <20260420020327.1667156-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. 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 --- V2: https://lore.kernel.org/linux-block/20260330230256.4160820-2-iam@sung-w= oo.kim/ V2->V3 - Added a reproducer - V2 incorrectly assumed pin_user_pages_fast() returns pages. block/bio-integrity.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index e79eaf047794..c8cfd15fb589 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -402,6 +402,20 @@ int bio_integrity_map_user(struct bio *bio, struct iov= _iter *iter) extraction_flags, &offset); if (unlikely(ret < 0)) goto free_bvec; + /* Handle partial pinning. This can happen when pin_user_pages_fast() + * returns fewer pages than requested + */ + if (unlikely(ret !=3D bytes)) { + 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; + } =20 nr_bvecs =3D bvec_from_pages(bvec, pages, nr_vecs, bytes, offset, &is_p2p); --=20 2.47.3