From patchwork Tue Oct 30 18:42:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 195585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1D7752C0080 for ; Wed, 31 Oct 2012 05:43:10 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932726Ab2J3SnH (ORCPT ); Tue, 30 Oct 2012 14:43:07 -0400 Received: from mail-ia0-f174.google.com ([209.85.210.174]:54614 "EHLO mail-ia0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932708Ab2J3SnF (ORCPT ); Tue, 30 Oct 2012 14:43:05 -0400 Received: by mail-ia0-f174.google.com with SMTP id y32so412761iag.19 for ; Tue, 30 Oct 2012 11:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=converseincode.com; s=google; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=ha1YyC7aN0atEV/tEEsb+cGoECgfgdSvf2FkqQNouQ0=; b=aQzArwGYuisjnJNBBzuvGZ9kDCLGFFWPw1+r4COw/gMc9tluzqa6jTv/B/0t3Wj/d2 1i34W/IFfWsQo9fgMXZTErLEWcCDVQGMMysCN9GgX/0D8m7luWI+GECwultkPBZzWT4n brACQ4lm17/3xW4EP2zavxOOv/VeQRJdGDgsU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=ha1YyC7aN0atEV/tEEsb+cGoECgfgdSvf2FkqQNouQ0=; b=i8V7Ss7IrZ3GzQIq033U6F7ECT8ZG6xuet/QTV+AWP4lXUTvRyP4FcxlpoyPYSGpzJ 7jJX3L2sKKF9XefBJg+adcM4t3HJtqgAj1WLa3WAo7Vv7tBn0DZXuHT759VDvJByuZzN 3SmPoXsFlVd4+NGMyGPQxBTQ4WbDy2fdrX1DBJpZfTQqG8OXngt3PNSTp65YR5wGCd/u mdhdgM0vN7DfSCsTIDcBOnvHoRKabqhcUNSnhjQU4IZay0BBljYLNMV1kyZFqJ6g1FPP Uc23EHCcidlG4pgqhjgWUdq7Cr3oXGbghQ3nPNMhPkN0GW49lMa8/+ADfw2fZyO69vXs tfzA== Received: by 10.50.197.169 with SMTP id iv9mr2442341igc.32.1351622584970; Tue, 30 Oct 2012 11:43:04 -0700 (PDT) Received: from GaldorVB.converseincode.com (216-58-123-56.cpe.distributel.net. [216.58.123.56]) by mx.google.com with ESMTPS id l8sm1128753igo.13.2012.10.30.11.42.52 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 30 Oct 2012 11:42:52 -0700 (PDT) Received: by GaldorVB.converseincode.com (Postfix, from userid 1000) id EC6196509D; Tue, 30 Oct 2012 14:43:12 -0400 (EDT) From: Behan Webster To: davem@davemloft.net Cc: netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= , pageexec@freemail.hu, Behan Webster Subject: [PATCH 2/2] Remove VLAIS usage from netfilter Date: Tue, 30 Oct 2012 14:42:54 -0400 Message-Id: <1351622574-18421-3-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1351622574-18421-1-git-send-email-behanw@converseincode.com> References: <1351622574-18421-1-git-send-email-behanw@converseincode.com> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQn5TUNiNJrfIojbQAezBm61f7+RkftqtU7VU82S/nOtVWFUK52yHz3VuNnaYni1mJBqfLVj Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org From: Jan-Simon Möller The use of variable length arrays in structs (VLAIS) in the Linux Kernel code precludes the use of compilers which don't implement VLAIS (for instance the Clang compiler). This patch instead calculates offsets into the kmalloc-ed memory buffer using macros from valign.h. Patch from series at http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120507/142707.html by PaX Team. Signed-off-by: Jan-Simon Möller Cc: pageexec@freemail.hu [Modified to use macros from valign.h] Signed-off-by: Behan Webster --- net/netfilter/xt_repldata.h | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h index 6efe4e5..d2b4232 100644 --- a/net/netfilter/xt_repldata.h +++ b/net/netfilter/xt_repldata.h @@ -5,31 +5,39 @@ * they serve as the hanging-off data accessed through repl.data[]. */ +#include + #define xt_alloc_initial_table(type, typ2) ({ \ unsigned int hook_mask = info->valid_hooks; \ unsigned int nhooks = hweight32(hook_mask); \ unsigned int bytes = 0, hooknum = 0, i = 0; \ - struct { \ - struct type##_replace repl; \ - struct type##_standard entries[nhooks]; \ - struct type##_error term; \ - } *tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); \ - if (tbl == NULL) \ + int replsize = paddedsize(0, 1, \ + struct type##_replace, struct type##_standard); \ + int entsize = paddedsize(replsize, nhooks, \ + struct type##_standard, struct type##_error); \ + int termsize = paddedsize(replsize+entsize, 1, \ + struct type##_error, int); \ + struct type##_replace *repl = kzalloc(replsize+entsize+termsize, \ + GFP_KERNEL); \ + if (repl == NULL) \ return NULL; \ - strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \ - tbl->term = (struct type##_error)typ2##_ERROR_INIT; \ - tbl->repl.valid_hooks = hook_mask; \ - tbl->repl.num_entries = nhooks + 1; \ - tbl->repl.size = nhooks * sizeof(struct type##_standard) + \ - sizeof(struct type##_error); \ + struct type##_standard *entries = paddedstart(repl, replsize, \ + struct type##_standard); \ + struct type##_error *term = paddedstart(entries, entsize, \ + struct type##_error); \ + strncpy(repl->name, info->name, sizeof(repl->name)); \ + *term = (struct type##_error)typ2##_ERROR_INIT; \ + repl->valid_hooks = hook_mask; \ + repl->num_entries = nhooks + 1; \ + repl->size = entsize+termsize; \ for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \ if (!(hook_mask & 1)) \ continue; \ - tbl->repl.hook_entry[hooknum] = bytes; \ - tbl->repl.underflow[hooknum] = bytes; \ - tbl->entries[i++] = (struct type##_standard) \ + repl->hook_entry[hooknum] = bytes; \ + repl->underflow[hooknum] = bytes; \ + entries[i++] = (struct type##_standard) \ typ2##_STANDARD_INIT(NF_ACCEPT); \ bytes += sizeof(struct type##_standard); \ } \ - tbl; \ + repl; \ })