Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2241779pxb; Thu, 4 Nov 2021 16:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6SLrR4kmw2EsykJ5YnMF30001fQYQsoWyjK9YHDuXqfL54BCKokZ+Sg2qJjqlSWHjr07f X-Received: by 2002:a17:907:7d86:: with SMTP id oz6mr7403626ejc.193.1636069883391; Thu, 04 Nov 2021 16:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636069883; cv=none; d=google.com; s=arc-20160816; b=B/3cA+I0Bs7OM/FLq/iIo7x/+F9NfliEylAfJSCfuaWoh/wGkfZ/akCuvYKw26Hd0w zp8Z2dGrZEyi8B9X2HPpWklw3xRR8IYjnoiqtRcPAoCKeOP4nSHgL1j/B7ZBPP84NZmQ KGEuVMLnESEgqzXmHy1+b9lBsAWctJ9gg23ZtQSG3mMAc7aR4uVFEdH4WlTKlqHAy+df DP9TaqC+wlFKFH5iJAYtZz6c5jrPJiWX9PKYEozJ59gCt31e8SjlhE8xB7rk63uy7042 z8WsZZokOzJoP+sxEmSX0I9XqsRcAFNHboZXDnQrEKvPSm0Yvzeedasp/RnSNljebZ4O vY8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RUydRgKitS7xjl4fUt0DmUmUJFyOp4TRNw35dFlgrg8=; b=qrhJpdQeW/oMp2G0I9MZXPYnJaM1QYn61abzaTikF2N1043ciEotHJqq08pdtg/L3S IDIYiWOde7vVj0u0avAU8hCZEB0zNOLgMB7Bl3Ch1THqMYv55kY2EecN4THeDVisku6p cL3HgJniD4PLrceBUvID/kvLbsUWyGN05DWFAGtzwJs3HKcvLMmFN4Xp3TfzzK8EL7Ye Zh4cZtwLlTG38YmR5FGnF3K5wb3UJpCXiFln134nrl9WykBwh7+UuMSWrbCvRQ4+x0kF ML2UF/zsc3KAyoa8/Q1pL1YbWYmcxFBDire23WcypcyA0r9D7O0/Qb50Fnlzi3SzerLh M42A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=MZKfUpmf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p7si9431726edw.260.2021.11.04.16.50.56; Thu, 04 Nov 2021 16:51:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=MZKfUpmf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231731AbhKDXvS (ORCPT + 99 others); Thu, 4 Nov 2021 19:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbhKDXvR (ORCPT ); Thu, 4 Nov 2021 19:51:17 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3034C061714 for ; Thu, 4 Nov 2021 16:48:38 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id v23so12187241ljk.5 for ; Thu, 04 Nov 2021 16:48:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=RUydRgKitS7xjl4fUt0DmUmUJFyOp4TRNw35dFlgrg8=; b=MZKfUpmfymkhP20bCj4T/LQGFFD4TKWsAiGHdVXd3kwJPDnWfMcAnqxRJ08O8QT1OY dwtn6D9ewzqc8BkE0xYN4gtsU2zfsNzEWhBkte4+mUewcvVfXfe3MtK2QXR9+w7RHB0i 80LHGxbyyxLaUEJg60P6V4UiVFSMqXREUwuG8= 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; bh=RUydRgKitS7xjl4fUt0DmUmUJFyOp4TRNw35dFlgrg8=; b=cBpUcgg9sGAHEikPt/opxXAdQlEaMSW9rx6wb2Rf5iocBB834KqDuriI0BmtmRa6WL /PhH0SED+gYuzGdGPQ8DYVXxHkqV9xUvQWchEE4IbfVBzoQHrlSiesALgl0uzOWGeVPx 5R/+lTFSi4zpX0ls2QZ12eTk/WveGhyG7CJ4E4FsMM0DlP/xdRKP3CzW9DW1qHOW9Msp kQdI2VpMYQpBdRvR84xhmBgfoliI2ywIXePaBWPY+hUKm/XhVjL44A6hykPaWYtfAuuP CT+DxhM5wGywc7Oqrmd3ei6WUpcoUdQ9R7fYptweFvSh/VU0RnxlO6TSnQzzXpzt1g4N SS9w== X-Gm-Message-State: AOAM532LTRkQbf40b81gCm+ovBV4BmXINjFDhE5s2laVwrtSnXL1/Dmd Fn8lHl/KOFxnsdXLpAe5junFZt+rNwgYsCJE X-Received: by 2002:a2e:90da:: with SMTP id o26mr951677ljg.292.1636069716793; Thu, 04 Nov 2021 16:48:36 -0700 (PDT) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com. [209.85.208.169]) by smtp.gmail.com with ESMTPSA id i11sm621766lfu.269.2021.11.04.16.48.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 16:48:35 -0700 (PDT) Received: by mail-lj1-f169.google.com with SMTP id j5so12161877lja.9 for ; Thu, 04 Nov 2021 16:48:35 -0700 (PDT) X-Received: by 2002:a05:651c:113:: with SMTP id a19mr11688124ljb.249.1636069714934; Thu, 04 Nov 2021 16:48:34 -0700 (PDT) MIME-Version: 1.0 References: <20211104115001.GU20319@twin.jikos.cz> In-Reply-To: From: Linus Torvalds Date: Thu, 4 Nov 2021 16:48:19 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Kmap-related crashes and memory leaks on 32bit arch (5.15+) To: David Sterba , Qu Wenruo , Linux Kernel Mailing List , Linux-MM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 4, 2021 at 4:37 PM Linus Torvalds wrote: > > Having looked at it once more, it still looks "ObviouslyCorrect(tm)" > to me, but I suspect I'm just being blind to some obvious bug. Oh, I was just looking at the pattern of kmap/kunmap, but there does seem to be a questionable pattern outside of that: This pattern looks odd: kaddr = kmap(cur_page); write_compress_length(kaddr + offset_in_page(*cur_out), compressed_size); ... (and then whether you kunmap immediately, or you leave it kmap'ed and use it again at the end is a different issue) In particular, what if "offset_in_page(*cur_out)" is very close to the end of the page? That write_compress_length() always writes out a word-sized length (ie LZO_LEN bytes), and the above pattern seems to have no model to handle the "oh, this 4-byte write crosses a page boundary" The other writes in that function seem to do it properly, and you have u32 copy_len = min_t(u32, sectorsize - *cur_out % sectorsize, orig_out + compressed_size - *cur_out); so doing the memcpy() of size 'copy_len' should never cross a page boundary as long as sectorsize is a power-of-2 smaller or equal to a page size. But those 4-byte length writes seem like they could be page crossers. The same situation exists on the reading side, I think. Maybe there's some reason why the read/write_compress_length() can never cross a page boundary, but it did strike me as odd. Linus