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=-9.3 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,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 7E844C433E0 for ; Tue, 16 Mar 2021 07:07:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B183E64F94 for ; Tue, 16 Mar 2021 07:07:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B183E64F94 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 2D1CC6B006C; Tue, 16 Mar 2021 03:07:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 280096B006E; Tue, 16 Mar 2021 03:07:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FA8E6B0070; Tue, 16 Mar 2021 03:07:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id E52706B006C for ; Tue, 16 Mar 2021 03:07:07 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id ADD468249980 for ; Tue, 16 Mar 2021 07:07:07 +0000 (UTC) X-FDA: 77924855694.30.57044E6 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by imf10.hostedemail.com (Postfix) with ESMTP id 3E0F54080F45 for ; Tue, 16 Mar 2021 07:07:07 +0000 (UTC) Received: by mail-ed1-f50.google.com with SMTP id y6so20165726eds.1 for ; Tue, 16 Mar 2021 00:07:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=JxGKDkVfXGKRna8iTes4kKAsxWi/i4GQ3tOLDP6GpoQ=; b=vBUkvWkwbtG8vyiRoj73LMOZGE5jZs6YXdymjwqFgRrn7JBgNqAz1g/FeqyO9Lo7aV wDd0ovRVBne4iF+lNUuw+xOOLejKKloq3TXqOfDS++B+JfRwj1imgVnDe6coNFsE0nge OQlJ9AuqLuEH7qAAprpzScUxNTzqvV3DTpPfqVDavOTqifjzVgPrX/T3ZTix1mMmTHio 9YPAF3GTetgOmohJpy753d5Q9Vc4A+RQPgS4JyV4R8Mt+1ouxReKo2oA8HlKLNm2ICcH mHCSHmvQzkMQp9eGiNCUrwnvao49mvYuVMQvMcDO59S8Y8GTjRL0UoZIOooDoJZxmaF+ wj9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=JxGKDkVfXGKRna8iTes4kKAsxWi/i4GQ3tOLDP6GpoQ=; b=bHvYcZRSSdv7/9rlf8TTIWXqNXAIuw2yWP87BejgoioIWMwkOezYrt2BUcwmrI2lN4 1j1K3wwmKm0V2cevkubrZmk4P7+nVeXYiE8QqJ5DB+/neBWUe7hGYIp1kX9RLyqd1MBh oUOtWAyWdZsjI3IUQ08z97dpeXb4wc1f819C29/K2VHHaXC7mK692YFf8JbtnglWhsKe zah6BS5WlzWmoNbAz4ei5ag4uCUC+FgAs5S9P2qttL4mwNEcuqg0ecZfQY6M+T0SaX6c F4fPWdwKav7V4hSFFuw9iY6dJo90f9SXfdxi69EjtVYjIMRaUGKTwWztgL/pcyH2G9x9 NNBw== X-Gm-Message-State: AOAM531e75xSJ+HWmC5mq39yAN/jpP84gQDeGN/w/vGbCdrTaz4fqdJq yOj7igOmy68tyrwKOMXaPPHVbWXUcgc= X-Google-Smtp-Source: ABdhPJyMAE8C/sIfU75yfYl+rcee6p15k6kf1B6GndQrRvtbx/qWrWoqKFUHhIBzwyqHx380aPHg6A== X-Received: by 2002:a19:488e:: with SMTP id v136mr10457749lfa.611.1615878075482; Tue, 16 Mar 2021 00:01:15 -0700 (PDT) Received: from [192.168.1.39] (88-114-223-25.elisa-laajakaista.fi. [88.114.223.25]) by smtp.gmail.com with ESMTPSA id t201sm3028596lff.70.2021.03.16.00.01.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Mar 2021 00:01:14 -0700 (PDT) Subject: Re: [PATCH v4] mm/vmalloc: randomize vmalloc() allocations To: Uladzislau Rezki Cc: linux-hardening@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Jann Horn , Kees Cook , Linux API , Matthew Wilcox , Mike Rapoport References: <20210309135757.5406-1-toiwoton@gmail.com> <20210314172312.GA2085@pc638.lan> <20210315153510.GA1865@pc638.lan> <4649f69d-b7cd-d1a6-26e0-9b8bf3b17df5@gmail.com> <20210315180239.GA2117@pc638.lan> From: Topi Miettinen Message-ID: Date: Tue, 16 Mar 2021 09:01:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210315180239.GA2117@pc638.lan> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Stat-Signature: has8g1rrzo9f8w5hg4wr6hdq3gqw7dof X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3E0F54080F45 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mail-ed1-f50.google.com; client-ip=209.85.208.50 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615878427-295947 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 15.3.2021 20.02, Uladzislau Rezki wrote: > On Mon, Mar 15, 2021 at 06:23:37PM +0200, Topi Miettinen wrote: >> On 15.3.2021 17.35, Uladzislau Rezki wrote: >>>> On 14.3.2021 19.23, Uladzislau Rezki wrote: >>>>> Also, using vmaloc test driver i can trigger a kernel BUG: >>>>> >>>>> >>>>> [ 24.627577] kernel BUG at mm/vmalloc.c:1272! >>>> >>>> It seems that most tests indeed fail. Perhaps the vmalloc subsystem isn't >>>> very robust in face of fragmented virtual memory. What could be done to fix >>>> that? >>>> >>> Your patch is broken in context of checking "vend" when you try to >>> allocate next time after first attempt. Passed "vend" is different >>> there comparing what is checked later to figure out if an allocation >>> failed or not: >>> >>> >>> if (unlikely(addr == vend)) >>> goto overflow; >>> >> >> >> Thanks, I'll fix that. >> >>> >>>> >>>> In this patch, I could retry __alloc_vmap_area() with the whole region after >>>> failure of both [random, vend] and [vstart, random] but I'm not sure that >>>> would help much. Worth a try of course. >>>> >>> There is no need in your second [vstart, random]. If a first bigger range >>> has not been successful, the smaller one will never be success anyway. The >>> best way to go here is to repeat with real [vsart:vend], if it still fails >>> on a real range, then it will not be possible to accomplish an allocation >>> request with given parameters. >>> >>>> >>>> By the way, some of the tests in test_vmalloc.c don't check for vmalloc() >>>> failure, for example in full_fit_alloc_test(). >>>> >>> Where? >> >> Something like this: >> >> diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c >> index 5cf2fe9aab9e..27e5db9a96b4 100644 >> --- a/lib/test_vmalloc.c >> +++ b/lib/test_vmalloc.c >> @@ -182,9 +182,14 @@ static int long_busy_list_alloc_test(void) >> if (!ptr) >> return rv; >> >> - for (i = 0; i < 15000; i++) >> + for (i = 0; i < 15000; i++) { >> ptr[i] = vmalloc(1 * PAGE_SIZE); >> >> + if (!ptr[i]) >> + goto leave; >> + } >> + >> > Hmm. That is for creating a long list of allocated areas before running > a test. For example if one allocation among 15 000 fails, some index will > be set to NULL. Later on after "leave" label vfree() will bypass NULL freeing. > > Either we have 15 000 extra elements or 10 000 does not really matter > and is considered as a corner case that is probably never happens. Yes, > you can simulate such precondition, but then a regular vmalloc()s will > likely also fails, thus the final results will be screwed up. I'd argue that if the allocations fail, the test should be aborted immediately since the results are not representative. -Topi > >> + >> for (i = 0; i < test_loop_count; i++) { >> ptr_1 = vmalloc(100 * PAGE_SIZE); >> if (!ptr_1) >> @@ -236,7 +241,11 @@ static int full_fit_alloc_test(void) >> >> for (i = 0; i < junk_length; i++) { >> ptr[i] = vmalloc(1 * PAGE_SIZE); >> + if (!ptr[i]) >> + goto error; >> junk_ptr[i] = vmalloc(1 * PAGE_SIZE); >> + if (!junk_ptr[i]) >> + goto error; >> } >> >> for (i = 0; i < junk_length; i++) >> @@ -256,8 +265,10 @@ static int full_fit_alloc_test(void) >> rv = 0; >> >> error: >> - for (i = 0; i < junk_length; i++) >> + for (i = 0; i < junk_length; i++) { >> vfree(ptr[i]); >> + vfree(junk_ptr[i]); >> + } >> >> vfree(ptr); >> vfree(junk_ptr); >> > Same here. > > -- > Vlad Rezki >