From patchwork Wed Dec 16 04:43:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11976427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE673C2BBD4 for ; Wed, 16 Dec 2020 04:43:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6E88F2335A for ; Wed, 16 Dec 2020 04:43:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E88F2335A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1011B6B0073; Tue, 15 Dec 2020 23:43:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AFC86B0074; Tue, 15 Dec 2020 23:43:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F09888D0008; Tue, 15 Dec 2020 23:43:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id D75D56B0073 for ; Tue, 15 Dec 2020 23:43:09 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 97992181AEF1E for ; Wed, 16 Dec 2020 04:43:09 +0000 (UTC) X-FDA: 77597900898.17.salt66_2c0033f27429 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 7FA85180D018B for ; Wed, 16 Dec 2020 04:43:09 +0000 (UTC) X-HE-Tag: salt66_2c0033f27429 X-Filterd-Recvd-Size: 2272 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 04:43:08 +0000 (UTC) Date: Tue, 15 Dec 2020 20:43:07 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608093788; bh=1k7VqyyUZbR3M+tfaIAckOATam0jAq+vTTRRI3L3bzQ=; h=From:To:Subject:In-Reply-To:From; b=R6arNDs2vZvId+IgwAAUAy5XNuBb8BixaXobiTEyEIaRzrPveWl53nIuTDr6UdHra YxkBxsOhkdwVAXwue7zjy4crJN4nakwZrkYVAtD4TT/U+JRvkr92OSKKSd9aiCTvuI dJ3BMbq9xCGt3HPDMnFA7bSR0br9RPkM5wbiIw1o= From: Andrew Morton To: akpm@linux-foundation.org, gustavoars@kernel.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 15/95] lib/stackdepot.c: use flex_array_size() helper in memcpy() Message-ID: <20201216044307.Qzi6xASDs%akpm@linux-foundation.org> In-Reply-To: <20201215204156.f05ec694b907845bcfab5c44@linux-foundation.org> User-Agent: s-nail v14.8.16 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: From: "Gustavo A. R. Silva" Subject: lib/stackdepot.c: use flex_array_size() helper in memcpy() Make use of the flex_array_size() helper to calculate the size of a flexible array member within an enclosing structure. This helper offers defense-in-depth against potential integer overflows, while at the same time makes it explicitly clear that we are dealing with a flexible array member. Link: https://lkml.kernel.org/r/186e37fe07196ee41a0e562fa8a8cb7a01112ec5.1601565471.git.gustavoars@kernel.org Signed-off-by: Gustavo A. R. Silva Signed-off-by: Andrew Morton --- lib/stackdepot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/lib/stackdepot.c~lib-stackdepotc-use-flex_array_size-helper-in-memcpy +++ a/lib/stackdepot.c @@ -135,7 +135,7 @@ static struct stack_record *depot_alloc_ stack->handle.slabindex = depot_index; stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN; stack->handle.valid = 1; - memcpy(stack->entries, entries, size * sizeof(unsigned long)); + memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); depot_offset += required_size; return stack;