From patchwork Thu Dec 21 18:35:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13502532 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 065BEC35274 for ; Thu, 21 Dec 2023 18:35:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 787556B0085; Thu, 21 Dec 2023 13:35:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 70EE86B0092; Thu, 21 Dec 2023 13:35:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 449066B008C; Thu, 21 Dec 2023 13:35:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 054886B0088 for ; Thu, 21 Dec 2023 13:35:52 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6A6231A079C for ; Thu, 21 Dec 2023 18:35:51 +0000 (UTC) X-FDA: 81591679302.23.C323DFC Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 7236018002B for ; Thu, 21 Dec 2023 18:35:49 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tbPj3uPo; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.172 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703183749; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=DILt3p53uNIRMlyKqLmSfi67XoCveJqLdgVMwZq9yXA=; b=w/pUwTO8Gk9F8kS8Sr3YywgQQWlU2DeWmvcVauzQRqIoFnggxifzibWN0uwAl2PHudyQVh nWDn524btDLDrv2pfO9FBvehGYflFkwLdovEFc6OAzhJ775Ghy32twgqv1qWNvIaFetoIp oLGOzPOdasNMzDr89UtIUakvJUoh2pE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tbPj3uPo; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.172 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703183749; a=rsa-sha256; cv=none; b=7MFLWYAp2lFjqyCHoKB7He7RGm9meeQWZBXZt0yEbCE5RJjYxee0INHmmGLAa+JcTxedud CGozJBsqnD/8NyJdySqG1ax8OAjMEHKAQmo85888nKn1Ri4oSca86gRkOYV1M9/FaKyjSA sGny2AYuEsHjZamTlsFnI7g8XXBtgmk= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703183747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DILt3p53uNIRMlyKqLmSfi67XoCveJqLdgVMwZq9yXA=; b=tbPj3uPoBR5fvyz4IQYqOUCK1dVNmUbtUl682TOpZhrRNOI2YNW915Z6Ra8mnw382p2lYY HAd5JqqGBNdGgKffBGvfA3Jgnw4Cwc00qn3tU0JtUl5qPdxqASFQcj+BykHY8fWr1UcDvc K8EcdixFixDgAws3WeDglq4de+F8pvM= From: andrey.konovalov@linux.dev To: Andrew Morton , Juntong Deng Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 1/4] kasan: clean up kasan_cache_create Date: Thu, 21 Dec 2023 19:35:37 +0100 Message-Id: <20231221183540.168428-1-andrey.konovalov@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 7236018002B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bxfx1z7k5ycwn6mn819hnnuowfjg5qcm X-HE-Tag: 1703183749-205429 X-HE-Meta: U2FsdGVkX1+tZyRUKKWeU8lbrJbXHVE75It7r8e3u8sV7ME6vW2X/5EmpnYf2b2VJmxe7AvnAALT9L9bfJR18Xii2bDLnPDPLexviHUTI85Sv5COc6DZ6M6HJFF1XHUnKuBR5JQiSLDyOP/IehEJkHGlbJ5XFLb+Eg8jJ7PSiuPw2uxbu8EVNeC1ceBJTun8Q3XtQ3uLJU6wmt4wuxm8Yvb9yNVQYx9f3cuioyJ+jdgwylBFkm+HWAAUVS6xXHmUzQVoxSxS9yBgdU08TnfDY0VEKS1Ar3M4fC37sMOc37xkFVQ1mllo/b56q28tVt7jhnZ9M/0wSueKqJ70ydKOeN8FrcpD+YBJ1oU0XT3SZnznJOWlmmmrwEVyPOvxlsDr1CGTuwnhSiu7yfWIjVqk8CSMHDqZRRJEVnfaC8u3gtQNVFtIXJrY89EWoLUO35rzys9cugig0ofsX+saIJ/NMZi1vsVjUxMPQRFAc1ySL2o1413+kfzn1+386FUdf5nceCnRghINIXalfDb02KnbUjSYfnHFb5Hrfr79NKir4Lu2727LApBbq63ANc+MavVX4qE8e9g2Kvx8wvG8NaWsnCwj3vPT1Czlp6CRWC4QKpPOCAvbWEmU6UKsJlc9mhc0OvzGOcOkXCWanD6TXUf//dYKuFB6RwLwouSY6rEf5PiwHtIOZWxp8mUv4hG0bpj9Jp2bJJZnCVvpfQsLuYyb9NQAuN7KX9eJhneDJkBxnvJqeILirxneF0CaE7fx/FpsH2OCuN/3AlMk29ouevv2AaRVqsQby8PMroEGm3kX12XHwwPlphJ9YPNLCZemJ6qmrb/Gp0BXr7MnvOAHdykbgfQGoF+xdRJDu70l67BpmmvC+2HIcwcdx9HpUiUjbKOED4+hg48GWh023H3t8wM0S9JysCcs0npaYuvQ/Af/RX1MmbX0RmIjz+fc/0sKyGHuyjoc25FkBHUCrrhUQvc M27bBFKH FF28jkUq/Sc0V8xlsRWfeLGF0bDoZjklt5DlQadkdr5EOHdkDUkOVFHTV9PlqgrAe7cWpCbiy3ec8bJwKP8R7Cr1sB/Qqo6L0Od+zZ9mWHmXoHXVjNh5XBeeD+//f2C/GW+4WeMhu58GEFBXlW909ahvwopjE4I04vR8yfwqqonOygDycNnYJuf1skYYDB9sXvIRLXHwiBWRpGAdtJCstlLeyVuQZgEPUYXKyv8yQnkLA513CQ2Oc+z1DgevTCC5Ixlm2cn5LSgvrDgtXj7gwD2RWoQviE70uOyVW 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: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov Reorganize the code to avoid nested if/else checks to improve the readability. Also drop the confusing comments about KMALLOC_MAX_SIZE checks: they are relevant for both SLUB and SLAB (originally, the comments likely confused KMALLOC_MAX_SIZE with KMALLOC_MAX_CACHE_SIZE). Fixes: a5989d4ed40c ("kasan: improve free meta storage in Generic KASAN") Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- mm/kasan/generic.c | 67 +++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 54e20b2bc3e1..769e43e05d0b 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -381,16 +381,11 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, ok_size = *size; - /* Add alloc meta into redzone. */ + /* Add alloc meta into the redzone. */ cache->kasan_info.alloc_meta_offset = *size; *size += sizeof(struct kasan_alloc_meta); - /* - * If alloc meta doesn't fit, don't add it. - * This can only happen with SLAB, as it has KMALLOC_MAX_SIZE equal - * to KMALLOC_MAX_CACHE_SIZE and doesn't fall back to page_alloc for - * larger sizes. - */ + /* If alloc meta doesn't fit, don't add it. */ if (*size > KMALLOC_MAX_SIZE) { cache->kasan_info.alloc_meta_offset = 0; *size = ok_size; @@ -401,36 +396,52 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, orig_alloc_meta_offset = cache->kasan_info.alloc_meta_offset; /* - * Add free meta into redzone when it's not possible to store + * Store free meta in the redzone when it's not possible to store * it in the object. This is the case when: * 1. Object is SLAB_TYPESAFE_BY_RCU, which means that it can * be touched after it was freed, or * 2. Object has a constructor, which means it's expected to - * retain its content until the next allocation, or - * 3. Object is too small and SLUB DEBUG is enabled. Avoid - * free meta that exceeds the object size corrupts the - * SLUB DEBUG metadata. - * Otherwise cache->kasan_info.free_meta_offset = 0 is implied. - * If the object is smaller than the free meta and SLUB DEBUG - * is not enabled, it is still possible to store part of the - * free meta in the object. + * retain its content until the next allocation. */ if ((cache->flags & SLAB_TYPESAFE_BY_RCU) || cache->ctor) { cache->kasan_info.free_meta_offset = *size; *size += sizeof(struct kasan_free_meta); - } else if (cache->object_size < sizeof(struct kasan_free_meta)) { - if (__slub_debug_enabled()) { - cache->kasan_info.free_meta_offset = *size; - *size += sizeof(struct kasan_free_meta); - } else { - rem_free_meta_size = sizeof(struct kasan_free_meta) - - cache->object_size; - *size += rem_free_meta_size; - if (cache->kasan_info.alloc_meta_offset != 0) - cache->kasan_info.alloc_meta_offset += rem_free_meta_size; - } + goto free_meta_added; + } + + /* + * Otherwise, if the object is large enough to contain free meta, + * store it within the object. + */ + if (sizeof(struct kasan_free_meta) <= cache->object_size) { + /* cache->kasan_info.free_meta_offset = 0 is implied. */ + goto free_meta_added; } + /* + * For smaller objects, store the beginning of free meta within the + * object and the end in the redzone. And thus shift the location of + * alloc meta to free up space for free meta. + * This is only possible when slub_debug is disabled, as otherwise + * the end of free meta will overlap with slub_debug metadata. + */ + if (!__slub_debug_enabled()) { + rem_free_meta_size = sizeof(struct kasan_free_meta) - + cache->object_size; + *size += rem_free_meta_size; + if (cache->kasan_info.alloc_meta_offset != 0) + cache->kasan_info.alloc_meta_offset += rem_free_meta_size; + goto free_meta_added; + } + + /* + * If the object is small and slub_debug is enabled, store free meta + * in the redzone after alloc meta. + */ + cache->kasan_info.free_meta_offset = *size; + *size += sizeof(struct kasan_free_meta); + +free_meta_added: /* If free meta doesn't fit, don't add it. */ if (*size > KMALLOC_MAX_SIZE) { cache->kasan_info.free_meta_offset = KASAN_NO_FREE_META; @@ -440,7 +451,7 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, /* Calculate size with optimal redzone. */ optimal_size = cache->object_size + optimal_redzone(cache->object_size); - /* Limit it with KMALLOC_MAX_SIZE (relevant for SLAB only). */ + /* Limit it with KMALLOC_MAX_SIZE. */ if (optimal_size > KMALLOC_MAX_SIZE) optimal_size = KMALLOC_MAX_SIZE; /* Use optimal size if the size with added metas is not large enough. */ From patchwork Thu Dec 21 18:35:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13502530 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B4EDC35274 for ; Thu, 21 Dec 2023 18:35:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5DA96B007B; Thu, 21 Dec 2023 13:35:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DE7426B0080; Thu, 21 Dec 2023 13:35:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C87876B0085; Thu, 21 Dec 2023 13:35:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B2D606B007B for ; Thu, 21 Dec 2023 13:35:51 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7F1531C0C1F for ; Thu, 21 Dec 2023 18:35:51 +0000 (UTC) X-FDA: 81591679302.21.3A55C5C Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) by imf24.hostedemail.com (Postfix) with ESMTP id 9B37418000D for ; Thu, 21 Dec 2023 18:35:49 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WarMWAg0; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf24.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.177 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703183749; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9xuoTXuQnTI+pN/bKZ3i8KybAohyAUoP+IGmtMicRak=; b=VF5HSyxsOc4IsmqMPLKPCy745WMT4sPdJW3RrMIr3w9IbLcbJm4gBCYDYn7FOR1V4AOln9 YxImP5kXlrOPSwfWOARWjarxRrT5jFgPen4nudXOb6W/dOkcTDWdPewD+k291mL1AnJlPm MgDI+5rPsjretiFNk8nVR9SzRGoJmi8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WarMWAg0; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf24.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.177 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703183749; a=rsa-sha256; cv=none; b=8cfEMTlIslq3ZClBvDJVZ1EIIE3fd/20m6M5jPTLiqvkjax2dV9GFDslHJfb+bUrkKyP+l 8OTVLjMWuXZH/hqELimugVNZygWeSunOv1naegwz+GRupwJBsFsfxiCbdZ0LKE+LSTxVv9 rCwtBIjvCxjhjofX3RxGslW2lvyHTj0= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703183747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9xuoTXuQnTI+pN/bKZ3i8KybAohyAUoP+IGmtMicRak=; b=WarMWAg0K7SHak78ygWtlpgqTMwt7mumTYTiIrRXvERxbmLV9b2mB09CJkEoY/kvKqecGT LJD1Iz9YrXuxQjpfGtqzVdMCmE1Di3rxLYHjeVLXbJ+cka5BV4sF8NvnLlPNSEtQ8xSxsE gYC+xeKuS4JVZvylLWKrrqmi4VV2GMA= From: andrey.konovalov@linux.dev To: Andrew Morton , Juntong Deng Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 2/4] kasan: reuse kasan_track in kasan_stack_ring_entry Date: Thu, 21 Dec 2023 19:35:38 +0100 Message-Id: <20231221183540.168428-2-andrey.konovalov@linux.dev> In-Reply-To: <20231221183540.168428-1-andrey.konovalov@linux.dev> References: <20231221183540.168428-1-andrey.konovalov@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 9B37418000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ccywk1g3ng75j4mdba8w6jienzpehmqd X-HE-Tag: 1703183749-131537 X-HE-Meta: U2FsdGVkX1/Kgv8nOYEqqxCLyq6nV3B6CXJitTrGdCt9GquMXSWAHov+hX7IG84/sLeOW+brzHIqpjqE4qk0eYE1UHLaBmRMXLsHa7Ag0scU4r4GptOm2bxQhldsZviOWtMRPnDgtn4RxInu9rdrFCGK8H5H3ESy/jGTQCA/9lBqeDWfjrdU/LGaeqSM47bqKneZLgXpXX/lMOm4QRzIqMLQtDHDx5AsmwhJk7OtZGRJKbKaguplyw4R0zXy7tU4TSHy45aKKV+RoctZnXcpq0fNoWJeLApT975Mn8h+ErfD17M3T/FcVNwBJPKanXNk0jO7JHm9fNqVWStIEV0FKJYHbRkj9rOU1SebsaorZQVKw4lVrkamdMX9neUCzu+QJYfywHWrLIB/1jCVfh9+P0nvva+ohVNB60TM9AsNnLOl9pMyB5Olf9CDa3f8bzDFMIX6G3S8g9U1dTP2+MhnnVDDMM2D2nhQxDVQroNLPTu6yZeYVHBro0aUmXiOuB0rI23B0rHbM1hpvj/DS872Fk3uwBekG8qB59M3i3gaT8O5MhDCG6W3l+NCuR5wutSbqbl9Tlll7UojydUj0PU2P668YNA9RkxyZBdiq5/NLX6ul7vmVVZg7VVbMgcjmv8b3pAUX2tTauiTzmMokLRgGQ3W06O1mB8mzoLaLzL705vUKj5tUuUw5k13Sk8UkUrdw2VSIAA+0a5YucMkegMKxZeIwer9MJ6/jBeNdsJclFAhVD9VS6M7ucKfXG6xljDHXyH1px7wA+j6AUskYQ1jb/lLvQviNKJk+aQf4QGVV+Vw+HyB5r3leh9qBSi8J/g+J5W41ZRcZe3lVHeW3MFVFqlnhREphN3ri4XDkiOVBrv/0P2J3IHVA7rufZ+L1IuhlbxAH7ps7z3AngLIIEcXyT9AsNmJuzCs0TRZmwi7d5D+NvnPsbV8sp2bF9Ud/H1FJGKHPwRAlzDrZuf0Lg8 rGOG4ga4 YwaXlVLGV9GiyMaX26c8AVTSqnipruNeG26cu8LGwufPwebftZ4w8hGbaBM034Nad+mKq6wAr9ErgcViWBm/saJCVqSeIGIF6kod8uElPzpM9jIAckm7cSuUKtGj7Kmk2CDTyvF3tc7wQE1+gm3dV0jjzXKaOUfwgU83HIC1PuaHSBvhKA1IMhtE4IZ4FzXQSF63Mv9tvfaFZxkaRCq4/fXrNpHCzwxxUGLhu 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: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov Avoid duplicating fields of kasan_track in kasan_stack_ring_entry: reuse the structure. Fixes: 5d4c6ac94694 ("kasan: record and report more information") Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- mm/kasan/kasan.h | 7 +------ mm/kasan/report_tags.c | 12 ++++++------ mm/kasan/tags.c | 12 ++++++------ 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 5e298e3ac909..9072ce4c1263 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -279,13 +279,8 @@ struct kasan_free_meta { struct kasan_stack_ring_entry { void *ptr; size_t size; - u32 pid; - depot_stack_handle_t stack; + struct kasan_track track; bool is_free; -#ifdef CONFIG_KASAN_EXTRA_INFO - u64 cpu:20; - u64 timestamp:44; -#endif /* CONFIG_KASAN_EXTRA_INFO */ }; struct kasan_stack_ring { diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c index 979f284c2497..688b9d70b04a 100644 --- a/mm/kasan/report_tags.c +++ b/mm/kasan/report_tags.c @@ -31,8 +31,8 @@ static const char *get_common_bug_type(struct kasan_report_info *info) static void kasan_complete_extra_report_info(struct kasan_track *track, struct kasan_stack_ring_entry *entry) { - track->cpu = entry->cpu; - track->timestamp = entry->timestamp; + track->cpu = entry->track.cpu; + track->timestamp = entry->track.timestamp; } #endif /* CONFIG_KASAN_EXTRA_INFO */ @@ -80,8 +80,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) if (free_found) break; - info->free_track.pid = entry->pid; - info->free_track.stack = entry->stack; + info->free_track.pid = entry->track.pid; + info->free_track.stack = entry->track.stack; #ifdef CONFIG_KASAN_EXTRA_INFO kasan_complete_extra_report_info(&info->free_track, entry); #endif /* CONFIG_KASAN_EXTRA_INFO */ @@ -98,8 +98,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) if (alloc_found) break; - info->alloc_track.pid = entry->pid; - info->alloc_track.stack = entry->stack; + info->alloc_track.pid = entry->track.pid; + info->alloc_track.stack = entry->track.stack; #ifdef CONFIG_KASAN_EXTRA_INFO kasan_complete_extra_report_info(&info->alloc_track, entry); #endif /* CONFIG_KASAN_EXTRA_INFO */ diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index c13b198b8302..c4d14dbf27c0 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -100,8 +100,8 @@ static void save_extra_info(struct kasan_stack_ring_entry *entry) u32 cpu = raw_smp_processor_id(); u64 ts_nsec = local_clock(); - entry->cpu = cpu; - entry->timestamp = ts_nsec >> 3; + entry->track.cpu = cpu; + entry->track.timestamp = ts_nsec >> 3; } #endif /* CONFIG_KASAN_EXTRA_INFO */ @@ -134,15 +134,15 @@ static void save_stack_info(struct kmem_cache *cache, void *object, if (!try_cmpxchg(&entry->ptr, &old_ptr, STACK_RING_BUSY_PTR)) goto next; /* Busy slot. */ - old_stack = entry->stack; + old_stack = entry->track.stack; entry->size = cache->object_size; - entry->pid = current->pid; - entry->stack = stack; - entry->is_free = is_free; + entry->track.pid = current->pid; + entry->track.stack = stack; #ifdef CONFIG_KASAN_EXTRA_INFO save_extra_info(entry); #endif /* CONFIG_KASAN_EXTRA_INFO */ + entry->is_free = is_free; entry->ptr = object; From patchwork Thu Dec 21 18:35:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13502531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0084AC46CCD for ; Thu, 21 Dec 2023 18:35:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 536726B0080; Thu, 21 Dec 2023 13:35:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BEA56B0085; Thu, 21 Dec 2023 13:35:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EADB6B008A; Thu, 21 Dec 2023 13:35:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E05716B0085 for ; Thu, 21 Dec 2023 13:35:51 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B4D64A0DEF for ; Thu, 21 Dec 2023 18:35:51 +0000 (UTC) X-FDA: 81591679302.22.E08619E Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by imf22.hostedemail.com (Postfix) with ESMTP id 00541C000E for ; Thu, 21 Dec 2023 18:35:49 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Wp4SgxAx; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703183750; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wLcCaNYp1HtmrZAPrigLSWnYXTa9aslZ8ruUHa0DHbo=; b=vl0HHfwM3rG7cQzT8ip00AazDUhiFweydbFLGsWvek6E9jOnC5To1cD8E6OoqF49XN8zmX 49gKg/aeV2SbRznV11xYNBtqX19rbXOhAfzVZ8IU41LORcGvLBXtY/ibAm+a3KD66E6GR0 8gfJDhFcaZPRYGRm0O/606vZPhpLAd4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Wp4SgxAx; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703183750; a=rsa-sha256; cv=none; b=fbqt9VltgM+IeJTykfHImQWQMtSxKdtKjJXmJzInuKL7VAv+IDApqRL/oIG4XIH4BryN84 EVYakBKd/G3/2rsnM/hBMVy/BBznFaSV9qXQ33+jaA7kQ+65wlVCsSEuQjeAjYSF1dkw68 tTFd4yzTbG9x8dqfuskpqVU0OfXO0CY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703183748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wLcCaNYp1HtmrZAPrigLSWnYXTa9aslZ8ruUHa0DHbo=; b=Wp4SgxAxzf33U9vG6eCpb57dWh/1TqzRC2qPSlMKfzo4YFjahK6jxrjxwucpfy7HNf515z HVTQaBE2QE4c7zE1ojOnJfPr31drq3YJKN5R0J3wvccZ6BKYlSSN5VG/UPs4jM7chLnJJ2 iVscHV7PW/6Z659boGsoyF6DsXA5Ssw= From: andrey.konovalov@linux.dev To: Andrew Morton , Juntong Deng Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 3/4] kasan: simplify saving extra info into tracks Date: Thu, 21 Dec 2023 19:35:39 +0100 Message-Id: <20231221183540.168428-3-andrey.konovalov@linux.dev> In-Reply-To: <20231221183540.168428-1-andrey.konovalov@linux.dev> References: <20231221183540.168428-1-andrey.konovalov@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 00541C000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 7xd54aaouk5uiu9hoaa8n8r4pftcw47j X-HE-Tag: 1703183749-203953 X-HE-Meta: U2FsdGVkX1+EuL7HFDTaNv8m0n2VCcJ1KJ4wujhOYyhd5l5GUEM6LRu5i5okZ58Mdkaw/FHKDZQCpTI8i/P0Js/B2n6mlqBwiX2oxroktWU+UFvZlYNJOXxhkx70Eggee2ePGi43HrWNy9KLO6tIrDqL3RZc6zvnQkb2AIXJGT8NjTgpsNxf41GoV72Qj2x0ZKicKgJtQ7vWhRTHYNCQ87NDJEH4XzNDlOsdpe2Jiy0pLGTbI7cGwwupYtz4iBDsly6CCGjqHh1ysLM+++QE1txBc9VK3K7tcshVFZhDFfdtFcQ+XZn7aaL+GFbwSaKHGziKqjYKjeOj5sHbHsKm1C9teO4gyyl6IqQ3swGg9WE8h/tJZViPwf0EValWqRsKhrfXUaU0JgKxt/nkcGAVEdJ6EOX8Vj1bjmZqnRMJBRC5OoPMgaKjHF+q5zCwzJAniDcUSpWUEDgFQVyiGykNUlpeEZPO1uuQ70X/nT4rpLzIjAV7Y3ODj2KKWDRSmEbTfr3lzx+QXXVDBYuT0YqY0Xmgv1CFiyf02z5qzzGb4OnRsI4JSiFlDr0Xna2u6dhVcPzkMDe08IK8aN2IgkrhxWZI22Z0otunD2R8Do5/7CEzfcjDx2SXPlXxyjJQDQb5BdaTsOIGZ5S8liXERglZJtde9zejhKSJArQKZHa1NmWWcVR4VEwsWoETtzfWHKq9LvTj79KnjzoQbZD58keBgYYBl4JHQlc+5Ug+19QT8f5BWpYzMqFkYaTdzPwLpc54kDQkEs2v0pFHXCMf+Q7NI3UPKko+xywm5EZCAW98NUPBDaJAEVeck4rm6XHG5MN1NoB1nrlRWCBR1g28J/rhmPGIvV3PdwW8+8gY63xCDtNjQk2BGlPOsV+2WG4ae7KNwwA3jnMPkMybuUqLJk91TbbTou1INqresR72fqAMCpxLQVFZybuUKFs319MUhAKLi4gjUThn8jHiKnYLwe4 QJ0Ru5RO InfQT4si0uV0z2cnkKpWjUNuU1Vui2FyqjA92HnaSd5koX230Kn0nn/ywZ8vfvzP9GB6PULC8RgAg4foOb25PoB41BTi9k85XZ2a3X/N5EnNPVLNE7cp6letS8rA51V3ybmXVx3ykMA/Wn3KPUu+KuDg4kIrxYhXuMtFp4yl+4jOZJgY= 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: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov Avoid duplicating code for saving extra info into tracks: reuse the common function for this. Fixes: 5d4c6ac94694 ("kasan: record and report more information") Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- mm/kasan/common.c | 12 ++++++++++-- mm/kasan/generic.c | 4 ++-- mm/kasan/kasan.h | 3 ++- mm/kasan/tags.c | 17 +---------------- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index fe6c4b43ad9f..d004a0f4406c 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -48,7 +48,7 @@ depot_stack_handle_t kasan_save_stack(gfp_t flags, depot_flags_t depot_flags) return stack_depot_save_flags(entries, nr_entries, flags, depot_flags); } -void kasan_set_track(struct kasan_track *track, gfp_t flags) +void kasan_set_track(struct kasan_track *track, depot_stack_handle_t stack) { #ifdef CONFIG_KASAN_EXTRA_INFO u32 cpu = raw_smp_processor_id(); @@ -58,8 +58,16 @@ void kasan_set_track(struct kasan_track *track, gfp_t flags) track->timestamp = ts_nsec >> 3; #endif /* CONFIG_KASAN_EXTRA_INFO */ track->pid = current->pid; - track->stack = kasan_save_stack(flags, + track->stack = stack; +} + +void kasan_save_track(struct kasan_track *track, gfp_t flags) +{ + depot_stack_handle_t stack; + + stack = kasan_save_stack(flags, STACK_DEPOT_FLAG_CAN_ALLOC | STACK_DEPOT_FLAG_GET); + kasan_set_track(track, stack); } #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 769e43e05d0b..11b575707b05 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -553,7 +553,7 @@ void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) stack_depot_put(alloc_meta->aux_stack[1]); __memset(alloc_meta, 0, sizeof(*alloc_meta)); - kasan_set_track(&alloc_meta->alloc_track, flags); + kasan_save_track(&alloc_meta->alloc_track, flags); } void kasan_save_free_info(struct kmem_cache *cache, void *object) @@ -564,7 +564,7 @@ void kasan_save_free_info(struct kmem_cache *cache, void *object) if (!free_meta) return; - kasan_set_track(&free_meta->free_track, 0); + kasan_save_track(&free_meta->free_track, 0); /* The object was freed and has free track set. */ *(u8 *)kasan_mem_to_shadow(object) = KASAN_SLAB_FREETRACK; } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 9072ce4c1263..31fb6bb26fed 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -372,7 +372,8 @@ static inline void kasan_init_object_meta(struct kmem_cache *cache, const void * #endif depot_stack_handle_t kasan_save_stack(gfp_t flags, depot_flags_t depot_flags); -void kasan_set_track(struct kasan_track *track, gfp_t flags); +void kasan_set_track(struct kasan_track *track, depot_stack_handle_t stack); +void kasan_save_track(struct kasan_track *track, gfp_t flags); void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags); void kasan_save_free_info(struct kmem_cache *cache, void *object); diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index c4d14dbf27c0..d65d48b85f90 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -94,17 +94,6 @@ void __init kasan_init_tags(void) } } -#ifdef CONFIG_KASAN_EXTRA_INFO -static void save_extra_info(struct kasan_stack_ring_entry *entry) -{ - u32 cpu = raw_smp_processor_id(); - u64 ts_nsec = local_clock(); - - entry->track.cpu = cpu; - entry->track.timestamp = ts_nsec >> 3; -} -#endif /* CONFIG_KASAN_EXTRA_INFO */ - static void save_stack_info(struct kmem_cache *cache, void *object, gfp_t gfp_flags, bool is_free) { @@ -137,11 +126,7 @@ static void save_stack_info(struct kmem_cache *cache, void *object, old_stack = entry->track.stack; entry->size = cache->object_size; - entry->track.pid = current->pid; - entry->track.stack = stack; -#ifdef CONFIG_KASAN_EXTRA_INFO - save_extra_info(entry); -#endif /* CONFIG_KASAN_EXTRA_INFO */ + kasan_set_track(&entry->track, stack); entry->is_free = is_free; entry->ptr = object; From patchwork Thu Dec 21 18:35:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13502533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00266C46CD4 for ; Thu, 21 Dec 2023 18:35:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8AD16B0088; Thu, 21 Dec 2023 13:35:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB4656B008A; Thu, 21 Dec 2023 13:35:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 905136B008C; Thu, 21 Dec 2023 13:35:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5EFF26B008A for ; Thu, 21 Dec 2023 13:35:52 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 31D4E807CE for ; Thu, 21 Dec 2023 18:35:52 +0000 (UTC) X-FDA: 81591679344.11.558BDF7 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) by imf04.hostedemail.com (Postfix) with ESMTP id 90DC64000A for ; Thu, 21 Dec 2023 18:35:50 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=iZOz0xdv; spf=pass (imf04.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703183750; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FiI0FbwykV/2XbgOuJsaOX93jnuQZGsyNc8LlrDSdxY=; b=JsyAODUybcDxmVujtdi/rPnonMBiNLiPBBDNlP7JTZXS95xMnxqIIR60BxUkpp0KIVbfwr k8Yc286L+GFFVYuv2/PFJrWBssG95Qt873Zgf/sTbFUcRFfGqGvi63JqP+teQv9f/zVIF4 zVN5ytiQeikAw7Z/MWhPW3cfrSlRhFo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=iZOz0xdv; spf=pass (imf04.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703183750; a=rsa-sha256; cv=none; b=p4G8sQ397W6pNdTd5qHQCaER50PqpHbJYd/s8J4ZpIxACuFijJUouTDfVvh0fdJqKDekRH ajQZNKWLBzKW/X+JEek8x39ur2PhpRChYjy1nVS5K4UWN5KMAx7jU1BxzOmANyTfNZ+Jqd 1/sAplKJpJUNCV3PoBsWjYYW2MvhIM4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703183749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FiI0FbwykV/2XbgOuJsaOX93jnuQZGsyNc8LlrDSdxY=; b=iZOz0xdvhazUGbDD/nkQ4ayAtlGnpXZBnWnzL0gh008WaAjCs/ptKU+lof1bjeEEnJT4H3 m/04qiY03QGGFOPq+9Um1KjCZvu3EYR64rQmdOa8BsiMcU4UbcAkLwg4eDeQRQK3p7PEb3 QlQ59oWVTbABhYd7X+p6qVYXgnw5aDw= From: andrey.konovalov@linux.dev To: Andrew Morton , Juntong Deng Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 4/4] kasan: simplify kasan_complete_mode_report_info for tag-based modes Date: Thu, 21 Dec 2023 19:35:40 +0100 Message-Id: <20231221183540.168428-4-andrey.konovalov@linux.dev> In-Reply-To: <20231221183540.168428-1-andrey.konovalov@linux.dev> References: <20231221183540.168428-1-andrey.konovalov@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 90DC64000A X-Rspam-User: X-Stat-Signature: jfcfu3zz5do9rqfhg8ip313aua9u8175 X-Rspamd-Server: rspam01 X-HE-Tag: 1703183750-729480 X-HE-Meta: U2FsdGVkX19+nMmFrcTbHGvjyLELV7CaM8d3t3ECToy6/A2s0JpNbZn15ATHCKP0+ToCTHtUNsJzrkxc9SU6UQs8NxibWLQqHkJibtx5r0tIppnD/D6RcHCC7EmXhJqFvQwU/hxjD+Po+3KFtai1L6zXGYklx9yyK2wjHkX4L2mohG/hqOL+RcBx7ZSdebH3LKWvAa36buTxA+QfuezZ2Qgl2zgXCsm1CoRNZkPwHH41ZUVLwBcg6YvOjFurenKqrl2l42nO6nS6Sd7fYAAqJN7m/10+AECND9gWhI1wNGmJwWigXesqUgaecoZVayITfuEYIVOVkxFJ9kqWEnZJd+7diIhs0riBcoXJnk0zs7LT7M6oFbslv+EgC9mDnNyVfh0vbGxAxcK05v/WAsXbTgZidFwDLThUgHupLisd27y1f48CnoIBEQRb/1JgtlC+vhVs0VTKdgmVRqG9L857UwGcoslH+x0LCUpN7jWI7nWejtv/MDShvX3xKqgn/4vhachscFkFdJI1S4rxMJZhjzeViMt9oOM1TW7TCagiM3a+63PEcOIsM9UNxKRcTk3aPDr3r6BwmgsIU3cdEvwgz5sf1J1WsE22Mvl1ldwKGcEqoixgw27HtN/aHu3NKBue97h/QmC57GHLGAiD/zXxYYH0sUB1ys8QCaQ5ah+SYUVYmX3OajgfqTUGN8p/7P9rGVPaPKQxMG8b+5M/ZqIcdp9wBfcNlLrpWEDUCYpdeC/XnAcUrDg1AFSXmEdB97EEtoMZR+WF9paXy8lDL2tQZ0F3qn8z73Y58vuI3mnNEOVWnB0RRQkxxntN8Audq+S/WFNtyQCKG6yFyjIC7YW+cj5OXjT+BU87EnsbESWIdWmQhxZYIFDVzMmJ2bCN16HjmHKyxNbV/16zMsOzg92YPtpm7XkqRND5zazsQB4A07Ch894gF6I1dIwahM/BR8D14RxOJBRUBsY= 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: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov memcpy the alloc/free tracks when collecting the information about a bad access instead of copying fields one by one. Fixes: 5d4c6ac94694 ("kasan: record and report more information") Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- mm/kasan/report_tags.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c index 688b9d70b04a..d15f8f580e2c 100644 --- a/mm/kasan/report_tags.c +++ b/mm/kasan/report_tags.c @@ -27,15 +27,6 @@ static const char *get_common_bug_type(struct kasan_report_info *info) return "invalid-access"; } -#ifdef CONFIG_KASAN_EXTRA_INFO -static void kasan_complete_extra_report_info(struct kasan_track *track, - struct kasan_stack_ring_entry *entry) -{ - track->cpu = entry->track.cpu; - track->timestamp = entry->track.timestamp; -} -#endif /* CONFIG_KASAN_EXTRA_INFO */ - void kasan_complete_mode_report_info(struct kasan_report_info *info) { unsigned long flags; @@ -80,11 +71,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) if (free_found) break; - info->free_track.pid = entry->track.pid; - info->free_track.stack = entry->track.stack; -#ifdef CONFIG_KASAN_EXTRA_INFO - kasan_complete_extra_report_info(&info->free_track, entry); -#endif /* CONFIG_KASAN_EXTRA_INFO */ + memcpy(&info->free_track, &entry->track, + sizeof(info->free_track)); free_found = true; /* @@ -98,11 +86,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) if (alloc_found) break; - info->alloc_track.pid = entry->track.pid; - info->alloc_track.stack = entry->track.stack; -#ifdef CONFIG_KASAN_EXTRA_INFO - kasan_complete_extra_report_info(&info->alloc_track, entry); -#endif /* CONFIG_KASAN_EXTRA_INFO */ + memcpy(&info->alloc_track, &entry->track, + sizeof(info->alloc_track)); alloc_found = true; /*