Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp195352rdb; Thu, 1 Feb 2024 06:11:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMp1gsmRUpn41doQcUvU3lruaTiC6sdtYUKVHk1TlsEBgrmQ+IEn9odrR7eYdq74wOUSqt X-Received: by 2002:a05:6122:368d:b0:4b7:41f2:9e9f with SMTP id ec13-20020a056122368d00b004b741f29e9fmr5012649vkb.9.1706796662832; Thu, 01 Feb 2024 06:11:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706796662; cv=pass; d=google.com; s=arc-20160816; b=WGKYBRxCZneOpwgipijhpijAuovYJxDhDxrfacftaPlz53nfX3MfeDCt7BsKNAa/Uv rkSN5zR6Bxjem1vcrgjyxpmeZI58xvFL42SUFAhmXHD+c2GSALVvB5fJrIfMwvFzYulE 8fsSCUZQRPTESg9Adxh+5YuzEse+azPkwSJ3UFwmYKR6ya2Tp6+OU6jFAs1mRBj9/rVl +vMu4OhRx//aZNGYKIswwA2HXraMOCyNh5tPi1fVu1Hf0XLRMbS8eDLUDQhA7jxykDMV lV6tVm1Hsa0We47NAp++/b298i266VveE+QqKAuCA7QCeEnqaJl33jOOrytEh6jl4aet 2EJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=RXTNG0NGaTKBhOKJjgCQmT3vvlhWCnQV7wCDhgjDYvY=; fh=ZJwT/f7f4pOS0nprDAdtlKUkaRDnd+3ygQV+KRPLZVg=; b=SYdNU5U3w/oU5U1r37uDhI3yDwdZn22LAKFtUCcd31VCffgYKp01w/yxj+wfbhfxL8 U1LXDa0lREOSCOUcSlVQnd4Cyen95EFzw9A80GlNAhnVYEDwgnqUEpc8j0HreRLl+lml 91F8I0gXLA6VpqZahsJVW+EJ7yh5gcguiMCrwoUuZWpIFAjF8FW123gw73Uxzv9riWSx zE3sxgX63AatoUpA6oDVKHDc0jQK81mUFtbSXnTzpDZRpQJRrmtgtzyPADTj19MsOxLr NWL2A8OAh13NRju8xxMzmozYOK0PEz7+zoOwNUfBElIrAocGAOvYuMeCjbUrEpljNowE kuow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H9uSLSPI; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-48292-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCWbAbje68CUDRG+hy6Fytz8nyttiCfVxOj4E4i1z4AvgvB8CB3z5Snt/VE8Pe2G2wWs7IZkz8jB/+CSWrFNx2u/o0uzBzbyAljyDAEb4A== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id fv14-20020a0561223c4e00b0049d2be551d9si1783788vkb.154.2024.02.01.06.11.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 06:11:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48292-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H9uSLSPI; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-48292-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A59D91C2AAC2 for ; Thu, 1 Feb 2024 14:08:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0BD55D47F; Thu, 1 Feb 2024 14:08:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H9uSLSPI" Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 701B25D46C for ; Thu, 1 Feb 2024 14:08:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706796530; cv=none; b=O1ogUH49mQhyctZjBoFDvZxrkBJ0VRjMQe7x7ILVpe+vJ/1VTUeJ3oN8WG8DkCE0YXjJOTvJXX7tRTkn8uGUyI8GVm9FxX/CIKapr665OWMbdl6n+Y4c+jfXgLKOCbLdf8HNbEYtXnXcO9XztpwQz4W6HwUxO1I52wEbR7AFgqw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706796530; c=relaxed/simple; bh=S/kT237ryNm3PnPnPKNnfVvpg+yzXlMfAL2xvda/AUg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Ntda04RA10UxiJos0QAkiMGREwlkmwlHTVA5AsSTlJRFwTMVrRKdJzvgoqZq+zoaugpi/i6MBIL57yfOo/jrLbfpeQKHP6jSu9F2syBMhS2d208kt341CjptCEuipHO6wCA10khg8nWtMTkh3wqjFD0Gt6KWtS+Xl3MTm91h8OE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H9uSLSPI; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-40fb804e4deso8633285e9.0 for ; Thu, 01 Feb 2024 06:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706796526; x=1707401326; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RXTNG0NGaTKBhOKJjgCQmT3vvlhWCnQV7wCDhgjDYvY=; b=H9uSLSPIb36xXGqJMtatGZTm62wRRQANP+utYPUE5YS1M4Vl24JAtTxgaAi+b2gS2L 9prFvSpQN0y+UW7UM+rvBGvp/m82UonIrwHOk2pv8GxFFt+U+QKty3FMYERrESr3zOaC F2KF594CFGvu6pEJ7Qp3v3HKbOipfim5lor8Y0+mVDf1cuvJ+AnN6wrulhGUfNgQvB6H 6Vyp35ER7wv6mCrhoABYhvoQtfi8yVFl6AQCAmDiwhptzik2r4Uu/6CQUQlzeH+h327e BxXLMlsF36bmBV8iIcbA5BjH+JaO7tkBLp1T8iBB8PCt25YQ7jl7jPC8/uqjeTQ40gZB ssug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706796526; x=1707401326; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RXTNG0NGaTKBhOKJjgCQmT3vvlhWCnQV7wCDhgjDYvY=; b=Xe42mg5Qc1iOzN+mIJupvoNr3MvqYNKsvDBf/cbLIQ4oQUcGE2ddrKFSPwTY0v47UK hd9a0i/C0s2ge8bDs7yQelGO7dUvI3pHYB/Mtn32YtXCEETXNvr5Rhp75koHAhz8yPPL oDO2lFEWXvqawH7xknu41rRAfTuBXeAPCAJtzLCR1H85ltBu/TECSrfp/O97lyMAkXs6 TvorFm+Uc27KKJn37m6s+5ZXVHcEq2lKIoSzUTrZfEBW1UE+UgJpslJdUvNzl/nAdQqH 0miPJPjlaF0UNH5c/GixaukVOfUB5dkOpDx6Gl+zroCOQB/oJLYhL5NuK/vk+SWFmm9u HT5Q== X-Gm-Message-State: AOJu0YwMRxMLF7hEdsG6WcqOxRJiRgYCJrPK+gFPLTNSAOM5NTRn77ZQ OaDl8zsh+RwBOpzxxJD6jX6cbG9TqWa/9V4RDJgcgThcfh48PGWN1oGv/sTG9VJ/mKpiW3JW+YP 9/+FNSyDhZIyG543FrELjhHDPwUW4fdE2 X-Received: by 2002:adf:fe48:0:b0:33a:f321:5ae6 with SMTP id m8-20020adffe48000000b0033af3215ae6mr3848112wrs.35.1706796526366; Thu, 01 Feb 2024 06:08:46 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240201090434.1762340-1-elver@google.com> In-Reply-To: <20240201090434.1762340-1-elver@google.com> From: Andrey Konovalov Date: Thu, 1 Feb 2024 15:08:35 +0100 Message-ID: Subject: Re: [PATCH -mm v2] stackdepot: fix -Wstringop-overflow warning To: Marco Elver Cc: Andrew Morton , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, Stephen Rothwell Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 1, 2024 at 10:04=E2=80=AFAM Marco Elver wrot= e: > > Since 113a61863ecb ("Makefile: Enable -Wstringop-overflow globally") > string overflow checking is enabled by default. Within stackdepot, the > compiler (GCC 13.2.0) assumes that a multiplication overflow may be > possible and flex_array_size() can return SIZE_MAX (4294967295 on > 32-bit), resulting in this warning: > > In function 'depot_alloc_stack', > inlined from 'stack_depot_save_flags' at lib/stackdepot.c:688:4: > arch/x86/include/asm/string_32.h:150:25: error: '__builtin_memcpy' speci= fied bound 4294967295 exceeds maximum object size 2147483647 [-Werror=3Dstr= ingop-overflow=3D] > 150 | #define memcpy(t, f, n) __builtin_memcpy(t, f, n) > | ^~~~~~~~~~~~~~~~~~~~~~~~~ > lib/stackdepot.c:459:9: note: in expansion of macro 'memcpy' > 459 | memcpy(stack->entries, entries, flex_array_size(stack, e= ntries, nr_entries)); > | ^~~~~~ > cc1: all warnings being treated as errors > > This is due to depot_alloc_stack() accepting an 'int nr_entries' which > could be negative without deeper analysis of callers. > > The call to depot_alloc_stack() from stack_depot_save_flags(), however, > only passes in its nr_entries which is unsigned int. Fix the warning by > switching depot_alloc_stack()'s nr_entries to also be unsigned. > > Link: https://lore.kernel.org/all/20240201135747.18eca98e@canb.auug.org.a= u/ > Fixes: d869d3fb362c ("stackdepot: use variable size records for non-evict= able entries") > Reported-by: Stephen Rothwell > Signed-off-by: Marco Elver > --- > v2: > * Just switch 'nr_entries' to unsigned int which is already the case > elsewhere. > --- > lib/stackdepot.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index 8f3b2c84ec2d..4a7055a63d9f 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -420,7 +420,7 @@ static inline size_t depot_stack_record_size(struct s= tack_record *s, unsigned in > > /* Allocates a new stack in a stack depot pool. */ > static struct stack_record * > -depot_alloc_stack(unsigned long *entries, int nr_entries, u32 hash, depo= t_flags_t flags, void **prealloc) > +depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 h= ash, depot_flags_t flags, void **prealloc) > { > struct stack_record *stack =3D NULL; > size_t record_size; > -- > 2.43.0.429.g432eaa2c6b-goog > Reviewed-by: Andrey Konovalov