From patchwork Tue Mar 13 21:10:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=C3=B6rn_Engel?= X-Patchwork-Id: 10281829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 640556038F for ; Wed, 14 Mar 2018 10:15:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5228528845 for ; Wed, 14 Mar 2018 10:15:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4650928848; Wed, 14 Mar 2018 10:15:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 8D7C728847 for ; Wed, 14 Mar 2018 10:15:38 +0000 (UTC) Received: (qmail 25684 invoked by uid 550); 14 Mar 2018 10:15:29 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 6055 invoked from network); 13 Mar 2018 21:10:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=1x+enLGXp8EToJZkHeSGFRA4I50aqhWfid5KEdvEZ5w=; b=CQ2p0tGS0MCoLfQnO2O8ckRwNrNlRCjGEap/T5DKQ4E+W38RHO23gIoGkYqKFsV5Oq U6tuV9ENbkER/EvxYjR9ta/JZwZgmPTI0ThmsXE0x14m9jAFFbCML2hbVdrp4t2dT9Cg VApAcl6nx4kIcGCdeGHjGuoTgRsnb4HCcyC54= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=1x+enLGXp8EToJZkHeSGFRA4I50aqhWfid5KEdvEZ5w=; b=AzxLZ0/hBCuv9w+hjKkYX/RPXZYPq2sT7mQLEEUQiX3FroXLdgNj/bVsLIr3KUQ0Oi ZjIzmD8jMyehZDJixOtRBCx3IB3DQQdBt1bznq1T1kF8/dIYqP2EOf+bbw6CK/POIjpQ I2No18E0RCCG/GQhPMPU5t8tPNJfM1aNO5cLrN5iQB2yTxv3bpPSLEtNLVmsV6XX4vV7 zwvi7D83+evBmJV5wJ8XckzGFcb8xSXd7lgJwgxAiYJjuMsKMbCGc/FgzF4w6oGqajw4 yiht7d7GCrGdwUa5yzpVAT/2iBxvWgIVwCcos3S+gHLU3Hrf59bBkzX1L/aaYyS69YuQ hq7Q== X-Gm-Message-State: AElRT7HUAvRHDJqxzZXGALRbOOD6nCFwPQB2mXeQ/bJ+HKBY03OrYkEr cTdVUM+WKW6qE5fBXKi8tYKfXA== X-Google-Smtp-Source: AG47ELszEt5q0aWlFrikYwLhAGEFJZe42J0opCfPXZwEFMM8BtNwqMLUWzjcT3xivkxU9lTwne046w== X-Received: by 10.99.100.197 with SMTP id y188mr1575674pgb.277.1520975415765; Tue, 13 Mar 2018 14:10:15 -0700 (PDT) Date: Tue, 13 Mar 2018 14:10:12 -0700 From: =?iso-8859-1?Q?J=F6rn?= Engel To: Linus Torvalds Cc: Kees Cook , "Tobin C. Harding" , "Tobin C. Harding" , Kernel Hardening , Tycho Andersen , Oleg Drokin , Andreas Dilger , James Simmons , Greg Kroah-Hartman , LKML , Herbert Xu , Peter Zijlstra , Ingo Molnar , "Gustavo A. R. Silva" Subject: [PATCH] btree: avoid variable-length allocations Message-ID: <20180313211012.GB29976@cork> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.3 (2018-01-21) X-Virus-Scanned: ClamAV using ClamSMTP I agree that the code is garbage. In my defense, creating generic iterator-type functions for multiple data types appears to be one of the hardest problems in CS with many bad examples of what not to do. Patch below should fix it. We have tcm_qla2xxx systems, so I will stick it into our test system as well. Jörn --- It is a cliché that most clichés are true, but then, like most clichés, that cliché is untrue. -- Stephen Fry From 0077d19b11ec27c3287787d2413b26fc4cf0b3ca Mon Sep 17 00:00:00 2001 From: Joern Engel Date: Tue, 13 Mar 2018 11:36:49 -0700 Subject: [PATCH] btree: avoid variable-length allocations geo->keylen cannot be larger than 4. So we might as well make fixed-size allocations. Given the one remaining user, geo->keylen cannot even be larger than 1. Logfs used to have 64bit and 128bit keys, tcm_qla2xxx only has 32bit keys. But let's not break the code if we don't have to. Signed-off-by: Joern Engel --- lib/btree.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/btree.c b/lib/btree.c index f93a945274af..590facba2c50 100644 --- a/lib/btree.c +++ b/lib/btree.c @@ -3,7 +3,7 @@ * * As should be obvious for Linux kernel code, license is GPLv2 * - * Copyright (c) 2007-2008 Joern Engel + * Copyright (c) 2007-2008 Joern Engel * Bits and pieces stolen from Peter Zijlstra's code, which is * Copyright 2007, Red Hat Inc. Peter Zijlstra * GPLv2 @@ -76,6 +76,8 @@ struct btree_geo btree_geo128 = { }; EXPORT_SYMBOL_GPL(btree_geo128); +#define MAX_KEYLEN (2 * LONG_PER_U64) + static struct kmem_cache *btree_cachep; void *btree_alloc(gfp_t gfp_mask, void *pool_data) @@ -313,7 +315,7 @@ void *btree_get_prev(struct btree_head *head, struct btree_geo *geo, { int i, height; unsigned long *node, *oldnode; - unsigned long *retry_key = NULL, key[geo->keylen]; + unsigned long *retry_key = NULL, key[MAX_KEYLEN]; if (keyzero(geo, __key)) return NULL; @@ -639,8 +641,8 @@ EXPORT_SYMBOL_GPL(btree_remove); int btree_merge(struct btree_head *target, struct btree_head *victim, struct btree_geo *geo, gfp_t gfp) { - unsigned long key[geo->keylen]; - unsigned long dup[geo->keylen]; + unsigned long key[MAX_KEYLEN]; + unsigned long dup[MAX_KEYLEN]; void *val; int err;