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 X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E97CDC433DF for ; Wed, 14 Oct 2020 15:13:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 71BD922201 for ; Wed, 14 Oct 2020 15:13:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YmNXzgrX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71BD922201 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6AA066B005D; Wed, 14 Oct 2020 11:13:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 659346B0062; Wed, 14 Oct 2020 11:13:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 521596B0068; Wed, 14 Oct 2020 11:13:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 252816B005D for ; Wed, 14 Oct 2020 11:13:53 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B1522180AD806 for ; Wed, 14 Oct 2020 15:13:52 +0000 (UTC) X-FDA: 77370875904.18.flag02_1f0048b2720c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 70804101E0238 for ; Wed, 14 Oct 2020 15:13:16 +0000 (UTC) X-HE-Tag: flag02_1f0048b2720c X-Filterd-Recvd-Size: 7482 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 14 Oct 2020 15:13:15 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id e23so2638921wme.2 for ; Wed, 14 Oct 2020 08:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=wKovQW/BZuEib5N5VKz8qE8nvWBDTtqg2/y0GWx/Iik=; b=YmNXzgrXVkV698eCXfcnujqTNF3EKUMoTQh9uHThFLNUxNiPJDLk1hI+WU0Ps9QUO8 cuGhKieHQH6XcpjSiluSYv1h/NGuD32ednc4pR2Ezz0Rq+theBtb0TZBFhpDlgJmXc9V hco3+4ai/fq1K56tqCHnVcnjupTq/p1U2PphwPR7Wt64HcAYz86SXfeulVdAhSNbUFVm zfIn6oxR22rIYftr0tStucjaJmYIGWbUbAagURiSTfk3JLPGHd51QSmFkqzkzqukniDc pl0WWTAtuUXEOUjZo2U9yxTtBVzMmZQO2CdVtRcngXRmPqGUZz21aqyeQswvfLRLbx/i hX1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wKovQW/BZuEib5N5VKz8qE8nvWBDTtqg2/y0GWx/Iik=; b=NGBls9KsbaR9Fdq6a5hUjS54dvsOgXu1lA1lRnllM93Bw3ucu5iHTXqyxCwvFm4A1M 820M7izL2f9uQS0QdoZT3VUjlLGPYUgsMF4gDZPCdfOI1DzfyUg/opaKJVdKRjNP0V5q VPUl/AZJTrk1JHD00Y8CZrA0OH2G3znZVNYyMsKWtNs8l0t24HCvLrb51zbnhWkjoOOu PU4AIeCGk5GHOyjszFpTsBj0kmFgl0+7W4zEYWhkTjT9vBdTRIXOPo+RSKYNZ6jqLYXq EL4ZZpoe8g7QEd/AffT5XFT7jrGB8GmLkoMtK3nETX5Ij22S1sX5b+zmPZGYe9IQD6uJ RRMQ== X-Gm-Message-State: AOAM533hH5/OQ8b1k3lxTmmGr3yBL9onWaFGXcbkeQVR/wKgVmJfVwqA JmMYwhGTROeQEgkqeHNrUAQ= X-Google-Smtp-Source: ABdhPJwNJFUjgI7k1EEdEK1tFg+hZKBTmpSryM9LzxTsfjZfGH0RpcayvBv23jwUUqfioArrIn4Aow== X-Received: by 2002:a1c:495:: with SMTP id 143mr3713978wme.63.1602688394508; Wed, 14 Oct 2020 08:13:14 -0700 (PDT) Received: from alley (176-114-240-43.rychlydrat.cz. [176.114.240.43]) by smtp.gmail.com with ESMTPSA id p4sm5463735wrf.67.2020.10.14.08.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2020 08:13:13 -0700 (PDT) From: Petr Mladek X-Google-Original-From: Petr Mladek Date: Wed, 14 Oct 2020 17:13:11 +0200 To: Naresh Kamboju Cc: Linux-Next Mailing List , linux-mm , open list , lkft-triage@lists.linaro.org, LTP List , Andrew Morton , Mike Rapoport , Stephen Rothwell , John Ogness , Sergey Senozhatsky , Rasmus Villemoes , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Thomas Gleixner Subject: Re: BUG: KASAN: global-out-of-bounds in vprintk_store on x86_64 Message-ID: <20201014151311.GB13775@alley> References: <20201014140514.GB17231@alley> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201014140514.GB17231@alley> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed 2020-10-14 16:05:20, Petr Mladek wrote: > On Wed 2020-10-14 16:19:18, Naresh Kamboju wrote: > > While testing LTP controllers testing on x86_64 KASAN enabled linux > > next 20201013 tag > > kernel this kernel BUG noticed. The oom-killer log also noticed while > > running tests. > > > > metadata: > > git branch: master > > git repo: https://gitlab.com/Linaro/lkft/mirrors/next/linux-next > > git commit: f2fb1afc57304f9dd68c20a08270e287470af2eb > > git describe: next-20201013 > > make_kernelversion: 5.9.0 > > kernel-config: > > https://builds.tuxbuild.com/TXP6cqokP8BCYJrv7zf6kw/kernel.config > > > This is the last string stored in the ring buffer before KASAN trigerred. > > > [ 221.922108] ================================================================== > > [ 221.922111] BUG: KASAN: global-out-of-bounds in vprintk_store+0x362/0x3d0 > > [ 221.922112] Write of size 2 at addr ffffffffba51dbcd by task > > memcg_test_1/11282 > > > [ 221.922114] CPU: 1 PID: 11282 Comm: memcg_test_1 Not tainted > > 5.9.0-next-20201013 #1 > > [ 221.922116] Hardware name: Supermicro SYS-5019S-ML/X11SSH-F, BIOS > > 2.0b 07/27/2017 > > [ 221.922116] Call Trace: > > [ 221.922117] dump_stack+0xa4/0xd9 > > [ 221.922118] print_address_description.constprop.0+0x21/0x210 > > [ 221.922119] ? _raw_write_lock_bh+0xe0/0xe0 > > [ 221.922120] ? vprintk_store+0x362/0x3d0 > > [ 221.922121] kasan_report.cold+0x37/0x7c > > [ 221.922122] ? vprintk_store+0x362/0x3d0 > > [ 221.922123] check_memory_region+0x18c/0x1f0 > > [ 221.922124] memcpy+0x3c/0x60 > > [ 221.922125] vprintk_store+0x362/0x3d0 > > It seems that vprintk() store was able to extend the last string > by the two characters. So this is likely: > > static size_t log_output(int facility, int level, enum log_flags lflags, > const struct dev_printk_info *dev_info, > char *text, size_t text_len) > { > [...] > if (prb_reserve_in_last(&e, prb, &r, caller_id, LOG_LINE_MAX)) { > memcpy(&r.text_buf[r.info->text_len], text, text_len); > > But very likely the two characters were copied to wrong location. > There are many similar lines in the full log and they always contain > > task_memcg=/0 > > It means that the size of the path is 2 characters but it should be > "/0". I guess that "in" was in the log buffer from the previous > wrap. > > So, it seems that prb_reserve_in_last() correctly updated the size > of the extended record but it returned wrong pointer to the buffer > or wrong current length. > > Anyway, prb_commit(&e) moved the buffer back to consistent state. > > [ 213O[ 221.922182] The buggy address belongs to the variable: > > [ 221.922183] clear_seq+0x2d/0x40 > > The address ffffffffba51dbcd seems to be from the range of > "module mapping space" adresses. > > "clear_seq" is static variable from kernel/printk/printk.c. There is a bug in data_realloc(). We return wrong pointer when there is no need to resize the record and it has been wrapped. It might happen when we add only few characters and there was a space because of alignment. It would cause writing outside the buffer into another statically defined variables. So, it might be it. The following change patch should fix it: diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index 2493348a1631..24a960a89aa8 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1125,7 +1125,10 @@ static char *data_realloc(struct printk_ringbuffer *rb, /* If the data block does not increase, there is nothing to do. */ if (head_lpos - next_lpos < DATA_SIZE(data_ring)) { - blk = to_block(data_ring, blk_lpos->begin); + if (wrapped) + blk = to_block(data_ring, 0); + else + blk = to_block(data_ring, blk_lpos->begin); return &blk->data[0]; }