Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2387565rdb; Mon, 12 Feb 2024 03:18:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUMl2bl3TdFH2dzeOIbO+RWmtLLNIGF+eDFReGI0pluvz2ZNU6/Hu+Iun/Y+JncSoOq6S5Joa00kUAvUV1FtHoZZXWi9AMnDRHCtL+BIQ== X-Google-Smtp-Source: AGHT+IFGqmKJY30CtsRY04yy5s8Q46O8DXTvbqb1iyaSJSiY8fl2ryeOHoAOTauu2mGwLsAkzpgS X-Received: by 2002:a05:620a:4495:b0:785:ceca:3053 with SMTP id x21-20020a05620a449500b00785ceca3053mr5533032qkp.61.1707736683222; Mon, 12 Feb 2024 03:18:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707736683; cv=pass; d=google.com; s=arc-20160816; b=m5091lCmpWW/sw/AMERXgs0mEk/kNMyOpU27IRdLbAWvnAmd+uD5dCzhCiZbKeBIie nnTTYMOs/GW2lWPhA+Sj6S1LElQH6M1HLKhs0a6utMGSzJ5JqFKTcEK0AB8qzptcWHBj JZaKChmYLQ8fbHKI9JVuGr3pXySAKSwn/SXUZNuXh1B4yMX+Tk+mfbGfofxchNAjsHQ1 vFC9EQn4hzCm+G8KzP/xmJ2Omd1Qf5rxXJ7Q6P7WxdlZ/zbf+VOYtESsTPsGk9UBkTOT EfacLoF4OssaWXbv+bEEI48fIg7x7gGzmxm6EiUg9GiKAU5xo3CH1kNPYYNTyeitA0O+ +hYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=iL+QtMsZTKrSGTb1pzvx7jDYORIO80vzBrYhsMugk+I=; fh=FVXQKzvTm5VD7/JwGgNbrQ3GsiWiLdRmOtHRnADQ+68=; b=x4ntjnHcZISJW2UOonFWKJQ/+zbwu3U2dlKaJ4LCAnZF7J96vrpDfEOa1NRDujAd+4 0OaE53DsKZ+qVGP4jXHQxgGBHXME2i9AShFrhJ8inesjrgmUXon0NpBIxSrsOQ6TzOz9 lu+M7wETDcf6bhpgKhgY9uhVn/whp2yCBM5/j58yqL8Jy0zAspZKxo0FniwFe4BD/i+C TKrMsJThd4P77qg9VCBUVhdG8VOtT1OQAJyrdwVafiF3pVxHyQda066ZInYrJXyWH/St nH8PzQxykvI4jRv1WVnC6WGF2dGcFFHrySqPPpyM20WiJleXARjbXqUx5Rp9ztDondFW /jMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uI3t9Err; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61407-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXYplpCmzE3vcnPtlNeOkgtdhC6LlZyaTWnJWJetAsW6Fzz0K5XrV7u8+Q4jON2ly3pFajG/JObbMb/XRSoEangTXsFnY/V2OQuBFgbbQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m3-20020a05620a24c300b007853c309bd0si6002974qkn.701.2024.02.12.03.18.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 03:18:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61407-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=@kernel.org header.s=k20201202 header.b=uI3t9Err; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61407-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 F2D581C21589 for ; Mon, 12 Feb 2024 11:18:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4084C39AD1; Mon, 12 Feb 2024 11:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uI3t9Err" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FB3C39877 for ; Mon, 12 Feb 2024 11:17:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707736664; cv=none; b=iBjfEKjHP/Et42baVZR1JtJhmnEZrBpoMCdWuxhM3Fl1YI5tgo5WbZ73iwoQ8MJNlvIsS3QPEaNR+NEaaSRg7AOObx7hjD4dNwm6XjYah/flusqHpz81lw6p9iGPbJEaJXV+sMCSfHi7d56arcsFoQU6eTQMQj+HiA1iaeVE/0c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707736664; c=relaxed/simple; bh=YCI5M76ZWV3agMAEsxysptr2SwbMtl3GoSgyNq4kuHM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=WilFmZqu6qcnSJPweSEY6heB3RguFYEyNYsmJUF4hZdOgCIlm9Sap7Kh/ZvS3UDQA/XviWbtNKlEPty2CRG+7ggS7YszQ46iJkoBcbV27DTHE9j+86be7/6G4DfCDbdtNcjRGIDYOMtn82GyJFzXCwK2hOlGWkew16z+CuQ9F6g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uI3t9Err; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33642C433C7; Mon, 12 Feb 2024 11:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707736664; bh=YCI5M76ZWV3agMAEsxysptr2SwbMtl3GoSgyNq4kuHM=; h=From:To:Cc:Subject:Date:From; b=uI3t9Err5RSXW5W3b0MsjFi/rTEbrQsdY0RZkCxI3OuIZHaoktNEWhszlyUdDfmSG aDryVTPOn9cBxqiUJNl5KopjoaOFBskt+vCtpzF85hlHlRDc45H8rP+DEsSXhT8ATh Ar2dYy++CV/rWqE2HXS3rgwb97LoGCL4aycz1fBRLlNx84BDdBZaccZXg08avAZeIW z/Z600Qbyso+3x1VEngdXtRWxbRcaVRfj5Ny9m2yqtUdeUG0CiYAzXORKYsx87xXVB wwZJZN1oCjBQTmHCK+AKPdpIFZK83ffIipbBza2Sv/1cf4Z8p24yFOqM5nXJ1EO6eI 04D8nrJm8Uygw== From: Arnd Bergmann To: Tycho Andersen , Kees Cook Cc: Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH] samples: user-trap: fix strict-aliasing warning Date: Mon, 12 Feb 2024 12:17:31 +0100 Message-Id: <20240212111737.917428-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Arnd Bergmann I started getting warnings for this one file, though I can't see what changed since it was originally introduced in commit fec7b6690541 ("samples: add an example of seccomp user trap"). samples/seccomp/user-trap.c: In function 'send_fd': samples/seccomp/user-trap.c:50:11: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 50 | *((int *)CMSG_DATA(cmsg)) = fd; | ~^~~~~~~~~~~~~~~~~~~~~~~ samples/seccomp/user-trap.c: In function 'recv_fd': samples/seccomp/user-trap.c:83:18: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 83 | return *((int *)CMSG_DATA(cmsg)); | ~^~~~~~~~~~~~~~~~~~~~~~~ Using a temporary pointer variable avoids the warning. Signed-off-by: Arnd Bergmann --- samples/seccomp/user-trap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/seccomp/user-trap.c b/samples/seccomp/user-trap.c index 20291ec6489f..a23fec357b5d 100644 --- a/samples/seccomp/user-trap.c +++ b/samples/seccomp/user-trap.c @@ -33,6 +33,7 @@ static int send_fd(int sock, int fd) { struct msghdr msg = {}; struct cmsghdr *cmsg; + int *fd_ptr; char buf[CMSG_SPACE(sizeof(int))] = {0}, c = 'c'; struct iovec io = { .iov_base = &c, @@ -47,7 +48,8 @@ static int send_fd(int sock, int fd) cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN(sizeof(int)); - *((int *)CMSG_DATA(cmsg)) = fd; + fd_ptr = (int *)CMSG_DATA(cmsg); + *fd_ptr = fd; msg.msg_controllen = cmsg->cmsg_len; if (sendmsg(sock, &msg, 0) < 0) { @@ -62,6 +64,7 @@ static int recv_fd(int sock) { struct msghdr msg = {}; struct cmsghdr *cmsg; + int *fd_ptr; char buf[CMSG_SPACE(sizeof(int))] = {0}, c = 'c'; struct iovec io = { .iov_base = &c, @@ -79,8 +82,9 @@ static int recv_fd(int sock) } cmsg = CMSG_FIRSTHDR(&msg); + fd_ptr = (int *)CMSG_DATA(cmsg); - return *((int *)CMSG_DATA(cmsg)); + return *fd_ptr; } static int user_trap_syscall(int nr, unsigned int flags) -- 2.39.2