From patchwork Tue Mar 23 12:52:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 406865 Delivered-To: patch@linaro.org Received: by 2002:a17:906:5290:0:0:0:0 with SMTP id c16csp2114462ejm; Tue, 23 Mar 2021 05:53:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6dFYya1sIJvaf6D0K/Dm3m86LTfRoz5SkKweqiY2peQYNLRrjmQUWN+12j3heJQNwuUIE X-Received: by 2002:a17:907:aa2:: with SMTP id bz2mr4827128ejc.239.1616504008669; Tue, 23 Mar 2021 05:53:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616504008; cv=none; d=google.com; s=arc-20160816; b=DOsRsKaTK+r8WoY1VxhO8zNVlmNi65Nm4HPRfMN7jlnjb7P4mPu8wEZ+Orsy+c7mS6 kJQyDVrrBF55zO0vHwjsRPPk9SGg1uX0q9f4xTL1BDnxEof4wEwmHHcCDp3bIkEFeXv8 zBjvU0S1TRKjgyfrnRPrijaOJ1G6bS/f3M0nTS6MKLMOh0/Tb9bPveG5fieaQxfnY96a vHaFpIq7ijJsUVx8OZ+DVn1MDSOx+PgVQ8vnBkqQBrP9RGrvxYsSA1/3fwHLK/aFFf/s 5dwlhS6jdSbYn2nP4GFtDpthG8jgtXYdEg/WLU2jaPMZ5dPKsKfSAuZrhSKMuGUnutHe rsjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=2fdrD6UfPl8Nlb7BlBNBS7DsDxlEpUDn6c+cW+HXbn4=; b=IY5bI0//yRDiNiFa5rsIsKEb7I0ML3FCUwk3fkEXbWCB6nY2mSFr1GIghTLhZFKEBH uhgF0tQqATguIkik4i0VUz5iXbqeAVTPmTOph23LzlBmzc28AKxCOSSvz7QsW1P3YneX zCW2Gufywp45Nopj6DmcLjfsEFnTX9VrtM7fKJ91Qaay0z3QsA9FEJiVTLUzkP8oKLX2 O9xKEZvXmLZEAAJL1P3foN3SsI7g84n+T/tmQTJ4ulEf97Q8M9p3+DJOwrrOgH1DplqS mnS69O9RWf/e05M3iO0NhF4dz0Yj4F6B5NSh4KnCRVu4nZWTx0FySXCgo7B8wuQRWJ33 xmfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dMqTWv2a; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp17si10154019ejc.744.2021.03.23.05.53.28; Tue, 23 Mar 2021 05:53:28 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dMqTWv2a; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231348AbhCWMw6 (ORCPT + 8 others); Tue, 23 Mar 2021 08:52:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:40170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231338AbhCWMwk (ORCPT ); Tue, 23 Mar 2021 08:52:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B99CE619B7; Tue, 23 Mar 2021 12:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616503957; bh=mRfSmzsVcIVbIadqBeT4oBqLsxBa56oCuRtUUGrMpok=; h=From:To:Cc:Subject:Date:From; b=dMqTWv2afZWj5Mau1JMxfYA7kxXLGNPM8ApL0kZgm0672qqwnDpwudjobI59hNCL5 AAVnM9vwGVQn8l3bZJv+iJa+sdORsCqm513oGXaRCZymrXkXKFDv1m/C05QoVMt27j okhe0gj56VRxdUOelQO9F0qhbxNDMrhEJWj+RqYbm06XxE4fzgZOI0QxbRX6yvfHyJ TEU8SXNVImuroAMjfjkInlUwIyXgSfnHcgy+OFi+5b+zdYLX0sbHNoBTr/ZITwK0A/ t73s18aYtMuuFqGWWwRwBmDKf32qvCGY2nbqutCWSvCPMH0GYfijtpYWJ9WRK/aT0S aJy8Q+Y3tgpiw== From: Arnd Bergmann To: "David S. Miller" , Jakub Kicinski , Willem de Bruijn Cc: Arnd Bergmann , Alexander Lobakin , Jonathan Lemon , Miaohe Lin , Guillaume Nault , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [RFC net] net: skbuff: fix stack variable out of bounds access Date: Tue, 23 Mar 2021 13:52:24 +0100 Message-Id: <20210323125233.1743957-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arnd Bergmann gcc-11 warns that the TS_SKB_CB(&state)) cast in skb_find_text() leads to an out-of-bounds access in skb_prepare_seq_read() after the addition of a new struct member made skb_seq_state longer than ts_state: net/core/skbuff.c: In function ‘skb_find_text’: net/core/skbuff.c:3498:26: error: array subscript ‘struct skb_seq_state[0]’ is partly outside array bounds of ‘struct ts_state[1]’ [-Werror=array-bounds] 3498 | st->lower_offset = from; | ~~~~~~~~~~~~~~~~~^~~~~~ net/core/skbuff.c:3659:25: note: while referencing ‘state’ 3659 | struct ts_state state; | ^~~~~ The warning is currently disabled globally, but I found this instance during experimental build testing, and it seems legitimate. Make the textsearch buffer longer and add a compile-time check to ensure the two remain the same length. Fixes: 97550f6fa592 ("net: compound page support in skb_seq_read") Signed-off-by: Arnd Bergmann --- include/linux/textsearch.h | 2 +- net/core/skbuff.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) -- 2.29.2 diff --git a/include/linux/textsearch.h b/include/linux/textsearch.h index 13770cfe33ad..6673e4d4ac2e 100644 --- a/include/linux/textsearch.h +++ b/include/linux/textsearch.h @@ -23,7 +23,7 @@ struct ts_config; struct ts_state { unsigned int offset; - char cb[40]; + char cb[48]; }; /** diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 545a472273a5..dd10d4c5f4bf 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -3633,6 +3633,7 @@ static unsigned int skb_ts_get_next_block(unsigned int offset, const u8 **text, struct ts_config *conf, struct ts_state *state) { + BUILD_BUG_ON(sizeof(struct skb_seq_state) > sizeof(state->cb)); return skb_seq_read(offset, text, TS_SKB_CB(state)); }