Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4677796pxu; Wed, 21 Oct 2020 02:26:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLcHkN+iIQ3Y5oyNFLkgi+C2KPshcppnClnfIviKVXNYeqt2KdxNAKNctsvAYeubSgOSG8 X-Received: by 2002:aa7:c746:: with SMTP id c6mr2136082eds.221.1603272380029; Wed, 21 Oct 2020 02:26:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603272380; cv=none; d=google.com; s=arc-20160816; b=h8jerXx50OO3boPlRo7rFmLo/gAw4wAeJvLWhpZ0qeI4Y8BQYZBcrkeCgkw240WpiK aW/7NNxdxFs8qfmZfUcuZz9CUSJZ7tAgDEDU4Kaf9WkXw03zzKTwlb4hBjL2vk2WwmWL O+WwgNJNeRkCvvEn0jGgZIMOqz84KKbp5+xFaKWbSbl0iLHdA7jgU+jXamddYVL/Aj0W qbXQj6+o03Yknk5ysEjGaNGG7vFwViziFTivalPhncZTJYXi9dkqnKFH5wY8KJG94ZjO 65vRFQig6ybQ47uVL2gmpYQY19X5j6CpWg3nEQlgmzCvKhS4FuE0bWILLS1d2+A81RHR Astw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UWc8U77CNrLKZ3E96OfmQgNgI56h2VKz/Wr6ZaJNokk=; b=WynK6/+Rc6dWUA3XeACig/i10tBEv8bcl7xdAHSeMI5uLQgVYr22aTsVuzFXv15TSN 7TAU7I7BYMbdrs+yG1AjPzUZGd11Cev667FsgQa5+aNf54plLRYbrpQ3pdhvo+0sLSQY 1DLjsmhy7BbWOsSD7d9o9dTWQqSflex/Fln0Rruto54HAO0FlmQrQHUXD3AEAiTAiliJ Da8KGtBlpEvcFPpvHZo6jnVDYuDmDw3YTpd4an74gCjwxA+EJC5MnMv7hRHZypytyj6i 1Lt8IHfDuOVN80clzBMg28yspJ5wNuWTKrBrYA492Ft4X5hSGioTnilR95DFcvOSDoSO HoHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr11si978460ejb.116.2020.10.21.02.25.50; Wed, 21 Oct 2020 02:26:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438036AbgJTTPw (ORCPT + 99 others); Tue, 20 Oct 2020 15:15:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438033AbgJTTPw (ORCPT ); Tue, 20 Oct 2020 15:15:52 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91576C0613CE; Tue, 20 Oct 2020 12:15:51 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 4722E1F44C34 From: Gabriel Krisman Bertazi To: dhowells@redhat.com Cc: viro@zeniv.linux.org.uk, tytso@mit.edu, khazhy@google.com, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel@collabora.com, Miklos Szeredi , Gabriel Krisman Bertazi Subject: [PATCH RFC 1/7] watch_queue: Make watch_sizeof() check record size Date: Tue, 20 Oct 2020 15:15:37 -0400 Message-Id: <20201020191543.601784-2-krisman@collabora.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201020191543.601784-1-krisman@collabora.com> References: <20201020191543.601784-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: David Howells Make watch_sizeof() give a build error if the size of the struct won't fit into the size field in the header. Reported-by: Miklos Szeredi Signed-off-by: David Howells [Rebase to 5.10] Signed-off-by: Gabriel Krisman Bertazi --- include/linux/watch_queue.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h index c994d1b2cdba..f1086d12cd03 100644 --- a/include/linux/watch_queue.h +++ b/include/linux/watch_queue.h @@ -120,7 +120,12 @@ static inline void remove_watch_list(struct watch_list *wlist, u64 id) * watch_sizeof - Calculate the information part of the size of a watch record, * given the structure size. */ -#define watch_sizeof(STRUCT) (sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT) +#define watch_sizeof(STRUCT) \ + ({ \ + size_t max = WATCH_INFO_LENGTH >> WATCH_INFO_LENGTH__SHIFT; \ + BUILD_BUG_ON(sizeof(STRUCT) > max); \ + sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT; \ + }) #else static inline int watch_queue_init(struct pipe_inode_info *pipe) -- 2.28.0