From: Barry Song <21cnbao@gmail.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Yosry Ahmed <yosryahmed@google.com>,
Nhat Pham <nphamcs@gmail.com>,
syzbot <syzbot+adbc983a1588b7805de3@syzkaller.appspotmail.com>,
akpm@linux-foundation.org, chengming.zhou@linux.dev,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
syzkaller-bugs@googlegroups.com,
Barry Song <v-songbaohua@oppo.com>
Subject: Re: [syzbot] [mm?] kernel BUG in sg_init_one
Date: Tue, 19 Mar 2024 10:37:32 +1300 [thread overview]
Message-ID: <CAGsJ_4xTx_FRCrh0KQ4dGAyHisWaK9kUa5UPETWcLnqPwxPkkg@mail.gmail.com> (raw)
In-Reply-To: <20240318213257.GB4210@cmpxchg.org>
On Tue, Mar 19, 2024 at 10:33 AM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> On Tue, Mar 19, 2024 at 10:15:43AM +1300, Barry Song wrote:
> > On Tue, Mar 19, 2024 at 10:10 AM Johannes Weiner <hannes@cmpxchg.org> 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 <nphamcs@gmail.com> wrote:
> > > > >
> > > > > On Mon, Mar 18, 2024 at 9:58 AM syzbot
> > > > > <syzbot+adbc983a1588b7805de3@syzkaller.appspotmail.com> 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.
no worries. I just wonder why Ira's commit ef6e06b2ef870 has added a
WARN_ON_ONCE
in kmap_to_page() given we still have many users :-)
drivers/fpga/fpga-mgr.c: pages[index] =
kmap_to_page((void *)p);
drivers/spi/spi.c: vm_page = kmap_to_page(buf);
drivers/vfio/pci/pds/lm.c: pages[i] =
kmap_to_page((void *)p);
fs/erofs/data.c: .page = kmap_to_page(ptr),
fs/smb/server/transport_rdma.c: page = kmap_to_page(buf);
net/9p/trans_virtio.c: (*pages)[index] =
kmap_to_page(p);
next prev parent reply other threads:[~2024-03-18 21:37 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-18 16:58 [syzbot] [mm?] kernel BUG in sg_init_one syzbot
2024-03-18 18:00 ` Nhat Pham
2024-03-18 20:17 ` Yosry Ahmed
2024-03-18 21:09 ` Johannes Weiner
2024-03-18 21:15 ` Barry Song
2024-03-18 21:32 ` Johannes Weiner
2024-03-18 21:37 ` Barry Song [this message]
2024-03-18 21:18 ` Yosry Ahmed
2024-03-18 21:21 ` Barry Song
2024-03-18 20:25 ` Barry Song
2024-03-18 20:34 ` Yosry Ahmed
2024-03-18 20:50 ` Barry Song
2024-03-18 20:59 ` Yosry Ahmed
2024-03-18 21:12 ` Barry Song
2024-03-18 20:42 ` Barry Song
2024-03-18 20:52 ` syzbot
2024-03-18 21:03 ` Barry Song
2025-02-12 17:20 ` Yosry Ahmed
2025-02-22 0:48 ` Yosry Ahmed
2025-02-26 16:01 ` Ira Weiny
2025-02-26 16:45 ` Yosry Ahmed
2025-02-26 20:36 ` Ira Weiny
2024-03-18 22:27 ` Barry Song
2024-03-18 22:52 ` syzbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGsJ_4xTx_FRCrh0KQ4dGAyHisWaK9kUa5UPETWcLnqPwxPkkg@mail.gmail.com \
--to=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=syzbot+adbc983a1588b7805de3@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=v-songbaohua@oppo.com \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).