Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp505263lqt; Mon, 18 Mar 2024 14:33:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUjexSUhS+2NUYZqkZU5HOD7Zxd16uxvmbozzY+8dltY9u06IAR0805Zo1mUkG9rjaI+IpJcjfELOEEgTfQyKseD/HzUFbRpJ7bV+pyMA== X-Google-Smtp-Source: AGHT+IElbzAROWPNsuik47l45q1ctavyxmrWEnYhq8P6X44D//+oajd7U92z8U+U2FPrugGmMtUp X-Received: by 2002:a17:903:124b:b0:1de:ff81:f650 with SMTP id u11-20020a170903124b00b001deff81f650mr1075559plh.10.1710797599090; Mon, 18 Mar 2024 14:33:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710797599; cv=pass; d=google.com; s=arc-20160816; b=cOsxGHP2D5kDPWaR/sm1MO5CgE733OFqoI4pp/TXUAv6iCYlt1ie3CsX91YLA0zHg4 uhvHp4HOySNIG2GJ08fM342ya+xZcLipK1sWBHQdaF7yKBvufL1ym5FpiQwf5s4WtOjI zhYsUbCgeO060kC5g4CkVF0RbjIwIjxvwPZjJN0K/mGkZvh1SxYzuBH1hMogoxhnkdkO J3KToUqd/tMLNxCkTMhmjhEOuvd7aWele51NBm8ZMpqbBI27WWvKfk+AlVbEPPUR0aPm bmV4b90gxAuuTfuY9dupIx74QxX80L9barTnSkPFdKojwNr8j58+yN1fuUvgXZ0JMFue g1rg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=mGPv8yamP9bphcl7rsqbJVKUCn1NBYwIxJacintSX4E=; fh=qAmkdqxTaZ0Hww3l01fIcVixJlj9LFd3SXwkNKud8yQ=; b=wzBP0bMtmgF3CTHZBvUhhmjnhEvBWTHqCa860Y0iEL1SV10rmDupEH9Bj1jYd3Y8X8 H/Sklze0KbfpQQlvAhspP3LuOlMTvZqtxC4zu4FPDNpsPfjGuhEWW2Az9jEYD9PaZvGI MrFGKMLrs1P2qLsREvJif/vs2sHqV+QxqKX/j8t9ME/pK3jUUIZWiy3ZLB6kD7guEoWN VnigeqXcsSZhAtAWsL0knQMfeJM/9JAkV3CO+VO9Zj2/j1vG1K5yeer85vuns0G4U5eI RisG5ihofhS3itSf2O4jmO34gn9MaFRvWMyWlWAynkqMLPy+u2/jvaFaQmmnEgcnLJqg jvIA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=RTDU9oaq; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-106707-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106707-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t5-20020a170902e84500b001e026b9d4f6si2730478plg.333.2024.03.18.14.33.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 14:33:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106707-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=RTDU9oaq; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-106707-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106707-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 90086B20F0E for ; Mon, 18 Mar 2024 21:33:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2011559143; Mon, 18 Mar 2024 21:33:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="RTDU9oaq" Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (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 EE4D358AC3 for ; Mon, 18 Mar 2024 21:33:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710797587; cv=none; b=BQE+lL85963AvwqBzeMGi2wPaM5m2DW8R1/dyc64hSxu7dGb8yLBw9u2TOee+6iSW7iUm4GeTqv9HPc25K+U+mkTyGTF9LwiRJhyNQ+Toq+CWnNpY4NlhNP4Emao13rwaTwP0CddK/zPEj+Dc2hYJnWxtSjI9vtiqvKnF2as2gs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710797587; c=relaxed/simple; bh=9UyEleUnZum8/j9s4RGJ600MaybJEwjgwNGZe5TtsUk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aQS0gOW3/IooCLBU5xpGbz+YPLw0zhqdCoxX30O0DapQ3k+q56mofgVRnx6nwb2xiVfiy08K5s1AAPH10Wk9/QCfD18zhBkoHGYJe5pOO/FJ/+2tpY07yh9GJZvl7Mz0QwQZLIGSS+R0pkvls6Xy5cAWsndTbagvnNrvpKrB908= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=RTDU9oaq; arc=none smtp.client-ip=209.85.160.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-42a0ba5098bso28525151cf.0 for ; Mon, 18 Mar 2024 14:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1710797583; x=1711402383; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=mGPv8yamP9bphcl7rsqbJVKUCn1NBYwIxJacintSX4E=; b=RTDU9oaqsdXUorIbRjEhK9OIxR741Co9b21x0FX5SCuhXXUtUQrsjFs5DQ9P+rOVGm 7y4EoDmqrd19H6iiU9yAc35sYfVodWMS6HZ+L9aBG+cA7O23YmGe+DVJB7NRzIckOhoY TbIEIux0kSGGBAhKnf8KHFtVnrFna3qGgLcAui5SpkrPmIg/xzhUEAcJVaJCU97frCPo DXICth2ujuhmOa1I3yF/UQZAnx0mTomKdZ9sjx6Lyybslhc0O0UCCVA2GQ7dm8jf6QxM YFbrzR5qakiy094/zZJvRWrQvy3qMl0nm+RN4jnazi/az8cKw2CL9f3v4Y0Ez2IOrbKz hYJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710797583; x=1711402383; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mGPv8yamP9bphcl7rsqbJVKUCn1NBYwIxJacintSX4E=; b=jqmilrfzSImIQUFHitvnbnlnJTC/hHUQGYGnYmwVWQ6X9X6WYzUId0Xl/kHRjQ9tya FMwcJ9HQyHgMAiVKVubf6l4BaKU7ekrwhoHa7Nt0Oo1RhSrm88uBePVkD3fi5ydToDwP Npas1gwl2987SPkFwGUBaWw8oZZTC3tNBH2n6kpRpQLw0lrhaf04c35n+DLh6a0j06Xe V8NieqNtAbUqKX0radXng7T3882CRnEnyT6dWywRt9ab2SK23S9jGty6qh1ZKU3VwgWC yDyeiYqGS9stm+JkZyViaHqmpTedwUD4EAOhQTnoaoNEDOPiQdxgFgpQjMv2PDRiTPB2 /dWw== X-Forwarded-Encrypted: i=1; AJvYcCXGXR4sSmJXDOrzk8HOJjDGlkSEftzVRYUipSZ6TI4WI/BHpa/F5ucgNf9mfNVAFZhAOP6+aSc+g1R/920dvm1nvQssJuF60sGMjzhc X-Gm-Message-State: AOJu0YxqVcpq28cs1cAyXCjQ7uGhT4To8q4Vw/1PFlTxnczYPzJYG9M7 tlaND/w+bdXN8Ytf6IDpbzvkm/BXF4gjzZ9eveFBLRggg0gTysvQKWSCoMjhPTomuKjhpV+LkoY 8 X-Received: by 2002:ac8:7e96:0:b0:430:e2a3:f80c with SMTP id w22-20020ac87e96000000b00430e2a3f80cmr696515qtj.31.1710797582770; Mon, 18 Mar 2024 14:33:02 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-da5e-d3ff-fee7-26e7.res6.spectrum.com. [2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id ay29-20020a05622a229d00b00430b385f721sm3924923qtb.15.2024.03.18.14.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 14:33:02 -0700 (PDT) Date: Mon, 18 Mar 2024 17:32:57 -0400 From: Johannes Weiner To: Barry Song <21cnbao@gmail.com> Cc: Yosry Ahmed , Nhat Pham , syzbot , akpm@linux-foundation.org, chengming.zhou@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, Barry Song Subject: Re: [syzbot] [mm?] kernel BUG in sg_init_one Message-ID: <20240318213257.GB4210@cmpxchg.org> References: <000000000000bbb3d80613f243a6@google.com> <20240318210917.GA4210@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Mar 19, 2024 at 10:15:43AM +1300, Barry Song wrote: > On Tue, Mar 19, 2024 at 10:10 AM Johannes Weiner wrote: > > > > On Mon, Mar 18, 2024 at 01:17:19PM -0700, Yosry Ahmed wrote: > > > On Mon, Mar 18, 2024 at 11:00 AM Nhat Pham wrote: > > > > > > > > On Mon, Mar 18, 2024 at 9:58 AM syzbot > > > > wrote: > > > > > > > > > > Hello, > > > > > > > > > > syzbot found the following issue on: > > > > > > > > > > HEAD commit: e5eb28f6d1af Merge tag 'mm-nonmm-stable-2024-03-14-09-36' .. > > > > > git tree: upstream > > > > > console output: https://syzkaller.appspot.com/x/log.txt?x=13043abe180000 > > > > > kernel config: https://syzkaller.appspot.com/x/.config?x=19bb57c23dffc38e > > > > > dashboard link: https://syzkaller.appspot.com/bug?extid=adbc983a1588b7805de3 > > > > > compiler: arm-linux-gnueabi-gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 > > > > > userspace arch: arm > > > > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1706d231180000 > > > > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=13ba7959180000 > > > > > > > > > > Downloadable assets: > > > > > disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/8ead8862021c/non_bootable_disk-e5eb28f6.raw.xz > > > > > vmlinux: https://storage.googleapis.com/syzbot-assets/0a7371c63ff2/vmlinux-e5eb28f6.xz > > > > > kernel image: https://storage.googleapis.com/syzbot-assets/7539441b4add/zImage-e5eb28f6.xz > > > > > > > > > > IMPORTANT: if you fix the issue, please add the following tag to the commit: > > > > > Reported-by: syzbot+adbc983a1588b7805de3@syzkaller.appspotmail.com > > > > > > > > > > ------------[ cut here ]------------ > > > > > kernel BUG at include/linux/scatterlist.h:187! > > > > > > > > Looks like the provided buffer is invalid: > > > > > > > > #ifdef CONFIG_DEBUG_SG > > > > BUG_ON(!virt_addr_valid(buf)); > > > > #endif > > > > > > > > which is "src" from: > > > > > > > > sg_init_one(&input, src, entry->length); > > > > > > > > Looking at the surrounding code and recent history, there's this > > > > commit that stands out: > > > > > > > > mm/zswap: remove the memcpy if acomp is not sleepable > > > > (sha: 270700dd06ca41a4779c19eb46608f076bb7d40e) > > > > > > > > which has the effect of, IIUC, using the zpool mapped memory directly > > > > as src, instead of acomp_ctx->buffer (which was previously the case, > > > > as zsmalloc was not sleepable). > > > > > > > > This might not necessarily be a bug with that commit itself, but might > > > > have revealed another bug elsewhere. > > > > > > > > Anyway, cc-ing the author, Barry Song, to fact check me :) Will take a > > > > closer look later. > > > > > > I am not a highmem expert, but the reproducer has CONFIG_HIGHMEM=y, > > > and it seems like zs_map_object() may return a highmem address if the > > > compressed object is entirely in a single page to avoid copying to a > > > buffer: > > > > > > if (off + class->size <= PAGE_SIZE) { > > > /* this object is contained entirely within a page */ > > > area->vm_addr = kmap_atomic(page); > > > ret = area->vm_addr + off; > > > goto out; > > > } > > > > > > The virt_addr_valid() check seems to indicate that we expect a direct > > > map address in sg_init_one(), right? > > > > If the page is highmem, kmap_atomic() establishes a temporary mapping > > to it in the direct map, such that we have a legit kernel pointer to > > the memory. Otherwise the memcpy() in zswap also wouldn't work... Am I > > missing something? > > Right, we built a map but it is not a linear mapping. so we can't use > virt_to_page > on this kind of non-linear mapping. > kmap_to_page can handle both linear and non-linear, but Ira's commit > added a WARN_ON_ONCE in it for non-linear mapping case. Ah, I misread what virt_addr_valid() does. It actually excludes kmap. Which, yes, makes sense, if the next line does virt_to_page()... Sorry about the noise.