Received: by 10.192.165.148 with SMTP id m20csp3393290imm; Mon, 23 Apr 2018 05:57:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+cFHycrapXc9x4wkjWPmuG0vwSfXuUxRZVbdk68fRe+jLRJSl7wk0lhso8md1X3Kw+7YoO X-Received: by 10.98.16.74 with SMTP id y71mr12439407pfi.188.1524488277728; Mon, 23 Apr 2018 05:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524488277; cv=none; d=google.com; s=arc-20160816; b=Y6puE2T7m65dPnL5z5nns1olJ9Y6ttKiltFe8EZAmjinp+hvL2FuIyUpBTOeeJKbli zchMUnvDmgyhEjLXjcis0Vh1nTD7SGXeCuibaPmc93ZO2t2gqMz0lBIrBFvt12oyz5w3 JTZqC9NJ5BKFlrgHwxwNAhfdMLCITl1jT/9c6LZKrLmEfSzJyoyORaHWELqbxcB2Um9a RhA7GyMWzMdfipUf3ziE8YibhNGtDNlWTwvfnvawYRRkvHPuzWQNA/knJtRmbi4KRJET NtXoFo9RbEJG+t/GgP2EmqSixc4voXL5vMpzVU9pptj1E0d/yCdepvOgCdwSzdePG35N 5x7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=U09LcbMGiUra9N5GfBrZ9Z2qeNHUrpNbiO9P5fSzuZo=; b=kA9sKpF3OT3pxIlyYu3NTnGWEAyqyUJGxBMmAd7hOwG6or6t9ujne7N2NFQIVeCxkb +YG4lfm82IapD0CztnW2bM5IcXBPPMWHt5TEHnG/MTMCzVdY4nVOXzeUQCnJdXECj0dX 9Z4OGbGBT2mgOsVfBRLIykPKipOGrxnY1YgPDO0av96B9L3fW/FtTlbGxBiDupjqI61p YR/82hHiYV+ApxwlUaZ4HGa6p39nbVcHMPmZ26aTDAka/27HpHtkgVVJIQ56vKUp1+PJ bg7waT4QJ4S8DR8gfdrp+CKRcawSkI9Wo2XAHDJ1njlHzZdoz5wq/UU+wEgKn2CSqJEG HFpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Xq0nRWIz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x11si9480810pgr.147.2018.04.23.05.57.43; Mon, 23 Apr 2018 05:57:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Xq0nRWIz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755298AbeDWM4C (ORCPT + 99 others); Mon, 23 Apr 2018 08:56:02 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:46201 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754930AbeDWMzx (ORCPT ); Mon, 23 Apr 2018 08:55:53 -0400 Received: by mail-io0-f194.google.com with SMTP id f3-v6so18277149iob.13; Mon, 23 Apr 2018 05:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U09LcbMGiUra9N5GfBrZ9Z2qeNHUrpNbiO9P5fSzuZo=; b=Xq0nRWIzsNFVfRgaixwK4d1eP8JPeOGZar3QT2Iz76LE9wA2SfQNH/T6SRrJeVGs2D L7WLLC/wM6UlMKdCt+MmlzClr3quHmDnsIL2zERqQc6FVGkVwImJY5AJZPW3Xzu2aRcS PIyS06ne8RCfkNJyXm1/VDCwmvNjiXTZo+dMtwX4ngKECAJZEInYy7tXpaGns8LrfLuN Yq1Zs5rzBYN90zeQ8nUtdc9ZjyIc3yIKkrF6BGBbGt/GJCg1zweFKUDcnUzIR6p10AGe hNK3piYoAlOGBLBDiGJcf6MjxYJdeV7HwIgD6M9ldoZxrPFHMatYRBFJPP66FW05hYio hKyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=U09LcbMGiUra9N5GfBrZ9Z2qeNHUrpNbiO9P5fSzuZo=; b=qBBTBqr2jYAtG1Od05QwJJkErhUfoLrF1CpPD7sM5NV3P9Exihlf69KC7LUYONYw3p qHgN7Wur92N48wbmQHDtcEJoezM9nqpxyjyP8YrU32vY7tva2KcdoEiI5ieelPsSvkdR iq5/O76vAkCDKPjV3/KHfyhCaMkereVUHHXHgoMXRV4AMhYu2eLg99L18HDlkWRbWSCr iGHyZCLLwNVxjB2gknXIACUOBOYNK5q21gb3wR3Z/3bTAds27xUgyoE1oSQCmTezqn5O 3PxmTGLshJpvw5/wApg0zSxkA2urXnzexyAWb9zBVsnLaJ+H8LYIpa9UUp16XmVpNIM9 XJug== X-Gm-Message-State: ALQs6tDwrIeG/NyiKcxh2gR+87QludtGye+uQkTWiLU/2IvzyYBmEcXB QT3HZ9oVPbSJmqZDrgj34+4= X-Received: by 2002:a6b:c882:: with SMTP id y124-v6mr22567384iof.64.1524488152791; Mon, 23 Apr 2018 05:55:52 -0700 (PDT) Received: from Mort.huawei.com (174-23-152-165.slkc.qwest.net. [174.23.152.165]) by smtp.gmail.com with ESMTPSA id n67-v6sm5934417ioe.20.2018.04.23.05.55.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 05:55:52 -0700 (PDT) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: willy@infradead.org, keescook@chromium.org, paul@paul-moore.com, sds@tycho.nsa.gov, mhocko@kernel.org, corbet@lwn.net Cc: labbott@redhat.com, linux-cc=david@fromorbit.com, --cc=rppt@linux.vnet.ibm.com, --security-module@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, igor.stoppa@gmail.com, Igor Stoppa Subject: [PATCH 8/9] Preliminary self test for pmalloc rare write Date: Mon, 23 Apr 2018 16:54:57 +0400 Message-Id: <20180423125458.5338-9-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180423125458.5338-1-igor.stoppa@huawei.com> References: <20180423125458.5338-1-igor.stoppa@huawei.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Try to alter locked but modifiable pools. The test neds some cleanup and expansion. It is provided primarily as reference. Signed-off-by: Igor Stoppa --- mm/test_pmalloc.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/mm/test_pmalloc.c b/mm/test_pmalloc.c index c8835207a400..e8e945e4a4a3 100644 --- a/mm/test_pmalloc.c +++ b/mm/test_pmalloc.c @@ -122,6 +122,80 @@ static void test_oovm(void) pmalloc_destroy_pool(pool); } +#define REGION_SIZE (PAGE_SIZE / 4) +#define REGION_NUMBERS 12 +static inline void fill_region(char *addr, char c) +{ + size_t i; + + for (i = 0; i < REGION_SIZE - 1; i++) + addr[i] = c; + addr[i] = '\0'; +} + +static inline void init_regions(char *array) +{ + size_t i; + + for (i = 0; i < REGION_NUMBERS; i++) + fill_region(array + REGION_SIZE * i, i + 'A'); +} + +static inline void show_regions(char *array) +{ + size_t i; + + for (i = 0; i < REGION_NUMBERS; i++) + pr_info("%s", array + REGION_SIZE * i); +} + +static inline void init_big_injection(char *big_injection) +{ + size_t i; + + for (i = 0; i < PAGE_SIZE * 3; i++) + big_injection[i] = 'X'; +} + +/* Verify rewritable feature. */ +static int test_rare_write(void) +{ + struct pmalloc_pool *pool; + char *array; + char injection[] = "123456789"; + unsigned short size = sizeof(injection); + char *big_injection; + + + pr_notice("Test pmalloc_rare_write()"); + pool = pmalloc_create_pool(PMALLOC_RW); + array = pzalloc(pool, REGION_SIZE * REGION_NUMBERS); + init_regions(array); + pmalloc_protect_pool(pool); + pr_info("------------------------------------------------------"); + pmalloc_rare_write(pool, array, injection, size); + pmalloc_rare_write(pool, array + REGION_SIZE, injection, size); + pmalloc_rare_write(pool, + array + 5 * REGION_SIZE / 2 - size / 2, + injection, size); + pmalloc_rare_write(pool, array + 3 * REGION_SIZE - size / 2, + injection, size); + show_regions(array); + pmalloc_destroy_pool(pool); + pr_info("------------------------------------------------------"); + pool = pmalloc_create_pool(PMALLOC_RW); + array = pzalloc(pool, REGION_SIZE * REGION_NUMBERS); + init_regions(array); + pmalloc_protect_pool(pool); + big_injection = vmalloc(PAGE_SIZE * 3); + init_big_injection(big_injection); + pmalloc_rare_write(pool, array + REGION_SIZE / 2, big_injection, + PAGE_SIZE * 2); + show_regions(array); + pr_info("------------------------------------------------------"); + return 0; +} + /** * test_pmalloc() -main entry point for running the test cases */ @@ -135,4 +209,5 @@ void test_pmalloc(void) test_is_pmalloc_object()))) return; test_oovm(); + test_rare_write(); } -- 2.14.1