Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4614565rwb; Tue, 17 Jan 2023 03:17:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXueb3TsDgrV5tGf1VzeWeocQn5R5b64A+TplPHRlHhzl51vgvC8O8vJMt4dOUqTmBoEbJsQ X-Received: by 2002:a05:6a20:2a94:b0:9d:efd3:66c1 with SMTP id v20-20020a056a202a9400b0009defd366c1mr3231032pzh.8.1673954250662; Tue, 17 Jan 2023 03:17:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673954250; cv=none; d=google.com; s=arc-20160816; b=vRoHzPd4UgiWwtiD9Afhi8qZ6QESCQSmC/hvm7MmE0VcpdEcPZ9+LaIVBVNXKiOHHX HURukXVaZtNCK+qJ87xEDWfaMrVWMKhDpjvsK/MmdRSvuaSMKBG7UIFeee71HGfaG3yr BktK/nGHuLn3v97sFV4pCqgTveNJi/v0sr+ifabTrwaDuqzDnwtheJYYResVReNSyzAi RW1XceDvq7KOYMBit6/ospYEiTMEgvDElUuJB8uNJNJ97lw8HqSPR4VI6JAXjfApf9ei 3azxJw7LM00Ec+vH6ZtNcfEQZdtUXBv2KmTUdzW7Yird5D6FU+TWJ46kRsPMh+Jefh8i zxBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=W+6gRdef0k52Vjrjx/yONZ2ai8LdoBBFD8BbNXJ1V2c=; b=o2kWWV55zyyif0UTgkQ5KHqItNffgV54fXArZSrlyaJuO7gH5zHMBzrplGFZZGG5Rh sNjo6f7wjCTqrgizHT90YZKyrnji9ilN6MbK+7y0WbK/PUpMAmKKSUR4wlrHcKkrvEjb KxFA4+UWJfFhrsXqvwibfzX2tOZFiK0kU4PzEHBqfHttyUe6/KtGuOzXT18DltbaqVEA pPmobNLh+N2AvrwtGbZmLeJHZGuOJzWRdYSqBdKn95dwzBPCiHcwUL0ea8bej/nu96T+ El5J6FPOAX7X2CDQme+m2NNfiwaB0iT4wIFXXPHod0s9Aylqy6fDerI8OEFEgxi1ALvm PZrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b="JXjJ/Oh1"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020a656642000000b004891755d4besi34308393pgv.78.2023.01.17.03.17.24; Tue, 17 Jan 2023 03:17:30 -0800 (PST) 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; dkim=pass header.i=@ispras.ru header.s=default header.b="JXjJ/Oh1"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236129AbjAQKxT (ORCPT + 49 others); Tue, 17 Jan 2023 05:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236589AbjAQKwm (ORCPT ); Tue, 17 Jan 2023 05:52:42 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B2C8305E6 for ; Tue, 17 Jan 2023 02:52:40 -0800 (PST) Received: from fedcomp.intra.ispras.ru (unknown [46.242.14.200]) by mail.ispras.ru (Postfix) with ESMTPSA id 930C244C101D; Tue, 17 Jan 2023 10:52:38 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 930C244C101D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1673952758; bh=W+6gRdef0k52Vjrjx/yONZ2ai8LdoBBFD8BbNXJ1V2c=; h=From:To:Cc:Subject:Date:From; b=JXjJ/Oh1TAsyFP1lGsmOot3Tk42JjCLmdAKckewn58wdNJsTLW5g04eIp/ygFKxhs 6DMH1CK+kmRdcn9Rjry+bbthNsP2Bod7P6pHHLYQjKxU/F3QyFu9m5/k0/nzROy+0l LGLqj1T92uQvz/cXV5X+k9zq3/A77Tr72hueA9dM= From: Fedor Pchelkin To: Phillip Lougher , Andrew Morton Cc: Fedor Pchelkin , linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org Subject: [PATCH 0/1] squashfs: harden sanity check in squashfs_read_xattr_id_table Date: Tue, 17 Jan 2023 13:52:25 +0300 Message-Id: <20230117105226.329303-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 Hello, Syzkaller reports the following problem [1]. null-ptr-deref in cache_first_page() happens because 'data[i]' is not properly initialized in squashfs_read_table(): this is due to its 'length' argument being zero (thus causing 'pages' being zero, too). squashfs_read_table() is called twice from squashfs_read_xattr_id_table(). After the first call, 'id_table->xattr_ids' signed value is processed: if a filesystem is corrupted, I suppose, a negative value is written to it (in copy_bio_to_actor(), as I understand). So then 'len' and 'indexes' values become incorrect (in this case, equal to zero), and it causes the bug. I've added the additional check for '*xattr_ids' not being negative. But, actually, I don't quite understand why 'xattr_ids' field has different types in 'struct squashfs_xattr_id_table' and 'struct squashfs_sb_info'. Probably that would be an issue. For example, in squashfs_xattr_lookup() we compare unsigned 'index' with signed 'msblk->xattr_ids'. So maybe convert 'xattr_ids' field in 'struct squashfs_sb_info' to unsigned type? And that, I think, would fix the problem described in the patch as well. [1] https://syzkaller.appspot.com/bug?id=8cf937ba2cde11be769fe8a1330c8d9153e3d7fa -- Regards, Fedor