Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp27060pxj; Wed, 16 Jun 2021 19:17:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaraPool8BQ/z43kUf9bemimBKzuDeBZz8sZY7n6fqW7n9zTGgyHG50PYA9JYoDrqmYRmI X-Received: by 2002:a17:906:d797:: with SMTP id pj23mr2532758ejb.367.1623896257424; Wed, 16 Jun 2021 19:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623896257; cv=none; d=google.com; s=arc-20160816; b=IEVsU0pnHXjdSiuC9XhKV5LcNv5n6quu+fiDsJGRtoMa4MulgKAqykz+mAnjGpRYfe 3KlOLg4mcSrlqQXJ/SJZJgkBRTZkVbfv3GBhHMiCj7wVZV+fTMwkNKkUzDh4G2/SQNK2 bTR8k40KseVJtq1R14ENl47vtfBGAN9vkn8O6FtIQEcO2In4BbwXG3oJe30RF6pzmMD6 U76/CY8ouxjxy1rJrbFisBHjKwnCXBwnw1T3iGxxorE/eNHDytuWzAt51Np0DbqvBa0Y SThq9TjmjPmL0FmWRxsMfhXmsj2JXgUUVqSCKPjteYFXybGLuXqPMDQbY32XjHmCCbwb 4ffA== 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=+KfHfR5+t0EnVDipxN8Cyuc0KkUY5m0xDUxbL/YVUKI=; b=vTfhJzP2zUiGg8GA8HVqrZ+meO/aOZclVAoovLMhM4FQ9K/a9+t6V470lsU38T85rH 9i9+e/J1+jnXtK95+S4rpWnnzqH6Gy3mtoNj197RE/peh1qnuK6iT/2dXOxmfb55Cp72 JoV9CtVq/vxKxt/7SxSTez2PH+B555sJ5qTa3n/JFiPYTUHLyDbHS0bzgq7NVjjtd0tf BUa/BLpdkS7n2i8gcxH/MysL60n6CW9Mwoydv1oBwU2Rqr3OpvTu5qE/wPvcElHgCPrC VOIrpHC2sJcZdFeasU1EcaRdRQN27t1n5pEWfaGkKUsGhIoJ8QOL/S3AJ991uRhSRAk/ mT2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M2M05GwA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w22si3614401edv.331.2021.06.16.19.17.14; Wed, 16 Jun 2021 19:17:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@chromium.org header.s=google header.b=M2M05GwA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233333AbhFPUVw (ORCPT + 99 others); Wed, 16 Jun 2021 16:21:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233317AbhFPUVv (ORCPT ); Wed, 16 Jun 2021 16:21:51 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A043FC06175F for ; Wed, 16 Jun 2021 13:19:44 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id fy24-20020a17090b0218b029016c5a59021fso4739618pjb.0 for ; Wed, 16 Jun 2021 13:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+KfHfR5+t0EnVDipxN8Cyuc0KkUY5m0xDUxbL/YVUKI=; b=M2M05GwAjHTM0WwuFWCLIJBXc7Mhmzduj5N8rkDWyWW7Bq+aM40Y5v6k5+kPQ4tecA YePfJMATp4pNXHeVunU8k8CCS3tNkZLexRP4nVx82umJkEDmIeIbwfBAqljx4nnxwFrE /9uTkaEqkwVn++hUMZzVnQ30+9Uy7Qe5wo0A0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+KfHfR5+t0EnVDipxN8Cyuc0KkUY5m0xDUxbL/YVUKI=; b=i/H/DfCC3AUbD01WFYCHhfZojRSbbYYtdP0SLuZoFulZ8MD56dDXj//lrrPGJAdNRe 8CUQ4gaOO19Sqm15t/xAeHCgSSDxuElqL+8CrPkLgHiLiN+jZmV/SnKuxDx1uVhSqQ4p uy2l/ELsTHk0opCR+FhL4dh2J0Dk6ack78S2w74SsCdtkiwnyLr67oCcCbcmfmg/nJhx CSHqgoA7ZDHt7+0cOPfQIGabNAM5sYAS1vFiRaRMnDR3XVOl83QKKNScoQ1qQ7ch7Un+ SZsm1JChpPl1q6Hn3/dHcj8PazkyfgbTYul47A8qfVoEE7pMBn/MAjXk69iUQXbmozH/ yxWA== X-Gm-Message-State: AOAM5326IT/TBvpfhaCCGoLACa1uLlsGXASb/R/K5aQyHvtqEacH6Sw2 Gtk1cxISfqq7Jk51p2GfAAUWsQ== X-Received: by 2002:a17:90a:aa8e:: with SMTP id l14mr1206561pjq.27.1623874784217; Wed, 16 Jun 2021 13:19:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c5sm3111954pfn.144.2021.06.16.13.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 13:19:43 -0700 (PDT) From: Kees Cook To: Heiko Carstens Cc: Kees Cook , Julian Wiedmann , Karsten Graul , "David S. Miller" , Jakub Kicinski , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] s390: iucv: Avoid field over-reading memcpy() Date: Wed, 16 Jun 2021 13:19:42 -0700 Message-Id: <20210616201942.1246211-1-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; g=0981c4eb75dd427d7d91cd99c36bf53addbcfc5d; i=YZOtmOq/sZVNbtRsnkBMD2Kw6M6DcNHBXTl6zJRUyvI=; m=CVqI9jG6YZ9jf8f1ED3Ps1ANOEjrAU1kS6Hl4wF6mU4=; p=5tZ5+WKosX4UV7nN9rSQBm46PiXYBFh/e0B4ynthelY= X-Patch-Sig: m=pgp; i=keescook@chromium.org; s=0x0x8972F4DFDC6DC026; b=iQIzBAABCgAdFiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAmDKXN0ACgkQiXL039xtwCaSnA/+Pcj H3UWanMJVaOTGAEIdXDCjPackgZXSABrZgBCld484XkzWVdo8GRuckbZCt4017+wGCvmoBES96pze OOJzXiG14jyAgv/c7zi6Q6Pdt8zVC+J9syB8vpovW/BYd3WRWbJWet+vyiVwXCFwLteMypdVQjSbD vPqlwtEIhLRIgQJWi7apUcKznj8cupOGcY6fDHrMXjqvk7Ef9nvM5D5I2mfZSjhxvQ6kSciJFTE90 3JNIuLnTh2L4FHQzf2aCR+6uzC6sveKa7LECGTT89TPiGvD0BqBRXfEvhz/gj5gS9iOKVPyUweUhk jV/Ix7tV7MrNl80eNRBtE1wGiGMRkMxckSrp4rWCyPYMLGvV3KszaQY7kwfRh6hOryEGqQifabHUR coGMga1jVG13xKwmqEpcgGJu6+RJ/MWXsw9uMWaV1NZefjZGmqd6x9zOv1SItCyqRceMSoPEQZeC0 VOlihXZ65qlXyXPdJDDWoe0sYlTTxZqhBSgJpnARCCwopTkG5ULwvaR5rXl/W+MUSlVOU/V4/SDn0 Yoo1ryNQjEIdhP7FsUcFA4ywbxOHPfqSW4AiFx3AlhJVDXnaMJtCopNV5jyCFsKSF0xJ45I61WG8L 3cVbIqTzvgqJ4IJcEwrYPdoVeKxae24fWQxBzwGeyIDrzrpSdHxqHSUGFesVyUP4= Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally reading across neighboring array fields. Add a wrapping struct to serve as the memcpy() source so the compiler can perform appropriate bounds checking, avoiding this future warning: In function '__fortify_memcpy', inlined from 'iucv_message_pending' at net/iucv/iucv.c:1663:4: ./include/linux/fortify-string.h:246:4: error: call to '__read_overflow2_field' declared with attribute error: detected read beyond size of field (2nd parameter) Signed-off-by: Kees Cook --- net/iucv/iucv.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c index 349c6ac3313f..e6795d5a546a 100644 --- a/net/iucv/iucv.c +++ b/net/iucv/iucv.c @@ -1635,14 +1635,16 @@ struct iucv_message_pending { u8 iptype; u32 ipmsgid; u32 iptrgcls; - union { - u32 iprmmsg1_u32; - u8 iprmmsg1[4]; - } ln1msg1; - union { - u32 ipbfln1f; - u8 iprmmsg2[4]; - } ln1msg2; + struct { + union { + u32 iprmmsg1_u32; + u8 iprmmsg1[4]; + } ln1msg1; + union { + u32 ipbfln1f; + u8 iprmmsg2[4]; + } ln1msg2; + } rmmsg; u32 res1[3]; u32 ipbfln2f; u8 ippollfg; @@ -1660,10 +1662,10 @@ static void iucv_message_pending(struct iucv_irq_data *data) msg.id = imp->ipmsgid; msg.class = imp->iptrgcls; if (imp->ipflags1 & IUCV_IPRMDATA) { - memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8); + memcpy(msg.rmmsg, &imp->rmmsg, 8); msg.length = 8; } else - msg.length = imp->ln1msg2.ipbfln1f; + msg.length = imp->rmmsg.ln1msg2.ipbfln1f; msg.reply_size = imp->ipbfln2f; path->handler->message_pending(path, &msg); } -- 2.25.1