Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5437206rwp; Mon, 17 Jul 2023 04:19:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlF8+Zk1wyegWXCqoZ9MEHjfU5ISNoW8Z0BGy8GPJBdvD+mdC6yIhRUmF9E+sfz3HQd5Nak/ X-Received: by 2002:aa7:cd52:0:b0:51e:3558:5eb6 with SMTP id v18-20020aa7cd52000000b0051e35585eb6mr11009643edw.3.1689592770625; Mon, 17 Jul 2023 04:19:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689592770; cv=none; d=google.com; s=arc-20160816; b=RLWMAxfj5/bLBXcFwHtUFirroVh7Bn6NpknXxvGvT0Ojh/nAhQlqfXkJYw+pQu62SC s6HEip6x7HEiFrYLAvRogY01svbb0tccFuLUFfDrJwiqb7YGYRJixF90jsVHqih6Zkv4 tUysYuE04O35UEJK9TbU/PDEel34s13DwlbrBOfJF47wvVM2JM0ygjmXf6zadPy1T6gc iVJMEzHpKrYZaP0sFMa/zGs6gHyThMON4hyjPFQ3J4lffgHR/BtTv+taLKabVhzR3EKt uNUAM1t5xpUpk4F/hSrdlcC9rgxUCeRx33Lyq+4CGuwPUbaDIDTgFG+/CbP3g12+VHCJ VjxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=Vakf4GhiOiJaP70qd9pfvOgFRKucgdVWuf6PgoY2C78=; fh=5/Fl1n2QZOSNOaKofH7xjE1yymfVIG8/Kz0ugT55xbk=; b=eFJ2ek+cLv7cQFzn8/3Y6Rp/pDJF2XrQGoC5WJsaDtAN02eqSd4OIGKiVPHhmP55o5 aUAJO5+RbsOBQ/cHGHee/jG3F6Klh+6oGPIqz8vGyMWFOSRXH+yRrTCtoYGD05JuUs9l gzsw3jEz0OiXLR86ssTnrLVg3zdwy7TCI/LI0/Hl+l4yEo+bdUpbRfRhwXMvf8B0PHKE 8gwBJgI3/oQGwpf6dGtnxZvJkcZSnefaPhDxPogo31nn0By48TouS+57HdZqbv+EA2dG 39ZiXY8lAxoUIsrj9mRIHfZlhpo3MwjXQ6WC6bQWJl2OV0v1r2+uMMbEJk9XpHv4bMHO jelQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020aa7da86000000b0051ff079875csi7840137eds.55.2023.07.17.04.19.06; Mon, 17 Jul 2023 04:19:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230356AbjGQLDP convert rfc822-to-8bit (ORCPT + 99 others); Mon, 17 Jul 2023 07:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbjGQLDN (ORCPT ); Mon, 17 Jul 2023 07:03:13 -0400 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7DF6E48 for ; Mon, 17 Jul 2023 04:03:11 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 26144634203B; Mon, 17 Jul 2023 13:03:10 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id fG7YnavCyVgh; Mon, 17 Jul 2023 13:03:09 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id AB868634203A; Mon, 17 Jul 2023 13:03:09 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id B_LkhE8nHIJf; Mon, 17 Jul 2023 13:03:09 +0200 (CEST) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 829A66342026; Mon, 17 Jul 2023 13:03:09 +0200 (CEST) Date: Mon, 17 Jul 2023 13:03:09 +0200 (CEST) From: Richard Weinberger To: Stephan Wurm Cc: Miquel Raynal , Vignesh Raghavendra , linux-mtd , linux-kernel , Johannes Eigner Message-ID: <260741266.3681.1689591789332.JavaMail.zimbra@nod.at> In-Reply-To: References: <736980270.3262.1689586950735.JavaMail.zimbra@nod.at> Subject: Re: ubiblock: null pointer dereference using scatterlist in work_queue MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF97 (Linux)/8.8.12_GA_3809) Thread-Topic: ubiblock: null pointer dereference using scatterlist in work_queue Thread-Index: ss6EAmPjKXAVOTJ0bHjviSj8oPd3/Q== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, T_SPF_PERMERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Stephan, ----- Ursprüngliche Mail ----- > Von: "Stephan Wurm" >> So reading from ubiblock works as long you don't access it via dm-verity? >> How about other stacked devices such as dmcrypt? > > We did not check other stacked devices, but we'll give this a try. Please apply this patch too: diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c index 75eaecc8639f0..795e2d0f61086 100644 --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c @@ -304,7 +304,7 @@ static void ubiblock_do_work(struct work_struct *work) * the number of sg entries is limited to UBI_MAX_SG_COUNT * and ubi_read_sg() will check that limit. */ - blk_rq_map_sg(req->q, req, pdu->usgl.sg); + ubi_assert(blk_rq_map_sg(req->q, req, pdu->usgl.sg) > 0); ret = ubiblock_read(pdu); I fear the assert will fail. But let's see. :-D At least it would explain the NULL deref. >> Did you print the LEB number, read length and offset in ubiblock_read()? >> Maybe there is a bug related to setting up the correct device geometry >> and the read request is off. > Here is some excerpt from another try with KASAN enabled and full debug output: Hm, we are within bounds. And looks like other reads worked. > ================================================================== > [ 293.343675] BUG: KASAN: null-ptr-deref in ubi_io_read+0x1d4/0x46c > [ 293.349822] Read of size 1 at addr 00000000 by task kworker/0:3/18 > [ 293.356037] > [ 293.357551] CPU: 0 PID: 18 Comm: kworker/0:3 Not tainted 6.1.36 #1 > [ 293.363774] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree) > [ 293.370331] Workqueue: ubiblock0_2 ubiblock_do_work > [ 293.375269] unwind_backtrace from show_stack+0x10/0x14 > [ 293.380557] show_stack from dump_stack_lvl+0x34/0x48 > [ 293.385668] dump_stack_lvl from kasan_report+0xb8/0xe8 > [ 293.390956] kasan_report from ubi_io_read+0x1d4/0x46c > [ 293.396146] ubi_io_read from ubi_eba_read_leb+0x3c4/0x5cc > [ 293.401686] ubi_eba_read_leb from ubi_eba_read_leb_sg+0x84/0x1f8 > [ 293.407831] ubi_eba_read_leb_sg from ubi_leb_read_sg+0xb4/0x110 Can you please double check whether the very first call to ubi_eba_read_leb_sg() fails or a later one? Thanks, //richard