From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F9F5C433EF for ; Tue, 25 Jan 2022 17:01:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344901AbiAYRBs (ORCPT ); Tue, 25 Jan 2022 12:01:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351746AbiAYQ7X (ORCPT ); Tue, 25 Jan 2022 11:59:23 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4F5FC061783 for ; Tue, 25 Jan 2022 08:59:20 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id r25so4387581wrc.12 for ; Tue, 25 Jan 2022 08:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0EPBTQB+lrJUfmAenKtP4vKFgFhxTwuJuGHovZ9LsFE=; b=QhaQEJdMKLqtIqzHjLgydhsRceWU0PhhmbNDNtwNqt62yw+clPUDRqeO3McjtGcb5h 61ADGpP/FdrSZSlir/xDTOpCLQ/cIGQ9gRs1zV6v6jwSqOzqt4aDGp3rCAglx/OXuoi3 /AkO3meyRxOgscSoNR5Nrf8CQuswv+9iEq2Jpq+OWoaB23diYL2HtGV4WE7uVIAC1xZw 7gPEk2TtkO6Yn3oRbB2kXY6SIxoa4uXzB/WHnfTZCnX9H5OCHPhrf3tqZT6NvZPHBhzt qggN4D0baZrmfIGrOebWZDVojORI4G2+B1tAlZPzXOA1OqXdncZOk1rgb81f/0bEM3j9 zrow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0EPBTQB+lrJUfmAenKtP4vKFgFhxTwuJuGHovZ9LsFE=; b=wqI+N0xHi6swGzRnJmS2RK/ZF2i052tLXpQNwF+DCqk3YWpfJo5KBibebSapuH/vUx ALiIHa0b5LTNc3FeKsjisHjNl+zlC94cf+OLt/XaQDrqM8DWDTiUs8lod+g6uXo6MsY3 z5HqKJsO/RUWzdj+w1Nld803+lmE9ipNiYiuWJmE5vGi5HgQ+rFm5lV43/d9gSbmVovU LQIphh5chZh+UpcE7sZAq/oDx/86ZmYAHsxS29t9LERTTNMPWSNR+IPjmhN7A0nOjIWG YnsyB/r+xvdt+DexyTR7ZBu7BaEPu3QRf8tT50gmCxdJoXAzVpj1ELlslKHHHa9rZYix emXQ== X-Gm-Message-State: AOAM531ZleFUQ0F8JKb1PYHKiYgLEoBlBllWihcWDgEFbiTrVk0GP/B4 XfJif9z1ckyrbvFNm0FxvptVw0mMaqaXl2R6YecdHA== X-Google-Smtp-Source: ABdhPJzhr5UswaMT7F1OyCk083+R2wOZHEwcVvfkypvFYUFRK0pPN7sqIb8CdgutboBR4Raggs4Qj74sny/tSJ1be8k= X-Received: by 2002:adf:dfcb:: with SMTP id q11mr18953518wrn.181.1643129959261; Tue, 25 Jan 2022 08:59:19 -0800 (PST) MIME-Version: 1.0 References: <20220122023447.1480995-1-eugenis@google.com> In-Reply-To: From: Evgenii Stepanov Date: Tue, 25 Jan 2022 08:59:07 -0800 Message-ID: Subject: Re: [PATCH] arm64: extable: fix null deref in load_unaligned_zeropad. To: Mark Rutland Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , Robin Murphy , Jisheng Zhang , Linux ARM , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 25, 2022 at 7:50 AM Mark Rutland wrote: > > On Tue, Jan 25, 2022 at 03:23:20PM +0000, Mark Rutland wrote: > > On Fri, Jan 21, 2022 at 06:34:47PM -0800, Evgenii Stepanov wrote: > > > ex_handler_load_unaligned_zeropad extracts the source and data register > > > numbers from the wrong field of the exception table. > > > > Ouch. Did you find this by inspection, or did this show up in testing? > > > > Sorry about this. > > > > I think we should be a little more explicit as to exactly what goes wrong. How > > about: > > > > | In ex_handler_load_unaligned_zeropad() we erroneously extract the data and > > | addr register indices from ex->type rather than ex->data. As ex->type will > > | contain EX_TYPE_LOAD_UNALIGNED_ZEROPAD (i.e. 4): > > | > > | * We'll always treat X0 as the address register, since EX_DATA_REG_ADDR is > > | extracted from bits [9:5]. Thus, we may attempt to dereference an arbitrary > > | address as X0 may hold an arbitary value. > > | > > | * We'll always treat X4 as the data register, since EX_DATA_REG_DATA is > > | extracted from bits [4:0]. Thus we will corrupt X4 and cause arbitrary > > | behaviour within load_unaligned_zeropad() and its caller. > > | > > | Fix this by extracting both values from ex->data as originally intended. > > > > > Fixes: 753b3236 > > > > That should be expanded, e.g. > > > > Fixes: 753b32368705c396 ("arm64: extable: add load_unaligned_zeropad() handler") > > > > With those changes: > > > > Reviewed-by: Mark Rutland > > Looking again, sicne this isn't jsut a null-deref, can we also rework the > title, something like: > > | arm64: extable: fix load_unaligned_zeropad() reg indices That's a much better commit message, thank you! I'll upload v2 shortly. This was found by updating to a newer QEMU that correctly delivers MTE faults from unaligned memory accesses, and triggers this bug reliably during Android boot. I'll add a stack trace to v2. > > Thanks, > Mark.