Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32294994rwd; Fri, 7 Jul 2023 11:28:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHWmCy8cs4cYLPAikQCKgiuOK7h+rKDEc2+cP25iJ5x7orsz21/g+2Kq2D250Oc1MExplW3 X-Received: by 2002:a05:6a21:328a:b0:12c:efd8:de4c with SMTP id yt10-20020a056a21328a00b0012cefd8de4cmr5278932pzb.18.1688754508925; Fri, 07 Jul 2023 11:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688754508; cv=none; d=google.com; s=arc-20160816; b=D3zN4U1Cf2/5HwbDRsgQM8ZAwgSwMaUFFH/wKCDjxlY1kj59VtFcYxrRtfua4Ig+zn beBCX200WAdqz872tG1KUrc1G8CuvitDdNcIq+N2o2bv6SI/hDnXNQtWNfQnO/NDqfm2 sRTYvrzkh+cimgOI0okDHQJtkZYxjFS6TkcWSMFCoCyBAQ3MrnZSTTeUHZv6QHgv03+z 4r803oidTRd9uRQ9UeMDrfj+V37E+fkPleHYUI7lMfVPRFy8NO5ZkImhyqGr3/VfHd/b oVjN2EMXGMGDzQrmijUga9sVBw7zY6BAq3Smf/1ZRQJJy0pbhF6ioxq2othKpBFTb0OJ GhRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ogL7+ASej7HUPOYlcuGXrcVhciSbk6CUWHVmAj6hh7M=; fh=+VAW6QhHnfqte8uMMLIkjDNz/4z6VD8f1kSBB6EklbI=; b=tVgDxdbrDFyp4Nc4t1R15mxN4yEqk1CP8mVc7FKHyD2tCs5AIzenSKzqhLTVD9Tzjz dZrRHADLnLl13Nu0QSL6oIp8b81SM9vddAgQPxb67WXs24/yejD/r60lbifWDZ1JdUWC rPNpy2OsBp2r8mqOtK8vXLJ4Vh2XSbN22n8VwmvPG1xuF/c6XANWjXRmWYotA3+rwQ3x n/s48lLrwQZNZlhb00mMdYy0ub4VguA50cyqMTVQxDCgbxpP5Q5hEpqfAWdDD+dtZSXb aXEnWtYCgN/vFd56NO7WJAI/fjTHdkHBV5trzp5maIq+QKsYtsRZJ1Nu7G3lm7N5k/Xm VKow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=cB5NI2mo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q3-20020a170902dac300b001b7e63cfa10si4291121plx.623.2023.07.07.11.28.16; Fri, 07 Jul 2023 11:28:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=cB5NI2mo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbjGGRqN (ORCPT + 99 others); Fri, 7 Jul 2023 13:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbjGGRqM (ORCPT ); Fri, 7 Jul 2023 13:46:12 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A87C10CE for ; Fri, 7 Jul 2023 10:46:11 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2b6afc1ceffso35422061fa.0 for ; Fri, 07 Jul 2023 10:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1688751969; x=1691343969; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ogL7+ASej7HUPOYlcuGXrcVhciSbk6CUWHVmAj6hh7M=; b=cB5NI2movEiNLk/GPwvPDfCCmew4SANFvreCWJSXOhWxrNCUjP/fEVDAbCp0JG0Dhl I8aCPBdPUTxBxjXGZS4Z2u/jSEIWDTgkGgK0ua2aUxSfNv45f98yJRW6bl7cxJelxEaT tiCmIiB7vDL1Yw3zj4JgmPa/PSzYvO2ziR8Ac= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688751969; x=1691343969; h=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=ogL7+ASej7HUPOYlcuGXrcVhciSbk6CUWHVmAj6hh7M=; b=DNhNEZtUTh/OWGXdGEHeEs0n8fUhx1612z99TDV80eGZb4pHKWa2Z904sBd3VD3PS0 EfXJqndNcDEdV8cqF3v0OMJhmpcY4BgphS39jhOYMl2O972JKBWvKvwIlxRAEebPQ/lI zZD74EYAi00rfRHl3szdHptvIRnMIKlSm1kaV3rIu13+hlKyoQCKr5i6WCpZGjO8ci4F FdPgV5OH3jZYg0xvUMTOMO1w9w+3aYUt4DMA99dNhSeTmNr3n0UpqND4qZ8lxVIN8QyN RPhZQsPIz8qJB+Wh5Ded8zSWrs8DYIZ7V9AA3sZfpkJ5gcJEDyBJVAHkToRLiqI7PvNF EEHA== X-Gm-Message-State: ABy/qLaNo2OpVOC2/W1gzQKzMayRE/9HE1MGDWRE4TCf05EhqazrAkXX TItn01gf5zN+2ErddchYxGuacMzQfStOnYkV7LM0xw== X-Received: by 2002:a2e:a40b:0:b0:2b6:df8a:d44b with SMTP id p11-20020a2ea40b000000b002b6df8ad44bmr3892966ljn.36.1688751969347; Fri, 07 Jul 2023 10:46:09 -0700 (PDT) MIME-Version: 1.0 References: <20230517181353.381073-1-kursad.oney@broadcom.com> In-Reply-To: <20230517181353.381073-1-kursad.oney@broadcom.com> From: Kursad Oney Date: Fri, 7 Jul 2023 13:45:57 -0400 Message-ID: Subject: Re: [PATCH] ARM: memset: cast the constant byte to unsigned char To: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel Cc: BCM Kernel Feedback , Russell King , linux-kernel@vger.kernel.org Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="00000000000044d0ca05ffe93508" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --00000000000044d0ca05ffe93508 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Ard, On Wed, May 17, 2023 at 2:14=E2=80=AFPM Kursad Oney wrote: > > memset() description in ISO/IEC 9899:1999 (and elsewhere) says: > > The memset function copies the value of c (converted to an > unsigned char) into each of the first n characters of the > object pointed to by s. > > The kernel's arm32 memset does not cast c to unsigned char. This results > in the following code to produce erroneous output: > > char a[128]; > memset(a, -128, sizeof(a)); > > This is because gcc will generally emit the following code before > it calls memset() : > > mov r0, r7 > mvn r1, #127 ; 0x7f > bl 00000000 > > r1 ends up with 0xffffff80 before being used by memset() and the > 'a' array will have -128 once in every four bytes while the other > bytes will be set incorrectly to -1 like this (printing the first > 8 bytes) : > > test_module: -128 -1 -1 -1 > test_module: -1 -1 -1 -128 > > The change here is to 'and' r1 with 255 before it is used. > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > Signed-off-by: Kursad Oney > > --- > > arch/arm/lib/memset.S | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/arm/lib/memset.S b/arch/arm/lib/memset.S > index d71ab61430b2..de75ae4d5ab4 100644 > --- a/arch/arm/lib/memset.S > +++ b/arch/arm/lib/memset.S > @@ -17,6 +17,7 @@ ENTRY(__memset) > ENTRY(mmioset) > WEAK(memset) > UNWIND( .fnstart ) > + and r1, r1, #255 @ cast to unsigned char > ands r3, r0, #3 @ 1 unaligned? > mov ip, r0 @ preserve r0 as return value > bne 6f @ 1 > -- > 2.37.3 > I didn't get any reaction to this patch so I added you to see if you could help review it or direct me to the right channel. Thank you! kursad --00000000000044d0ca05ffe93508 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIIQagYJKoZIhvcNAQcCoIIQWzCCEFcCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg gg3BMIIFDTCCA/WgAwIBAgIQeEqpED+lv77edQixNJMdADANBgkqhkiG9w0BAQsFADBMMSAwHgYD VQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UE AxMKR2xvYmFsU2lnbjAeFw0yMDA5MTYwMDAwMDBaFw0yODA5MTYwMDAwMDBaMFsxCzAJBgNVBAYT AkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMTEwLwYDVQQDEyhHbG9iYWxTaWduIEdDQyBS MyBQZXJzb25hbFNpZ24gMiBDQSAyMDIwMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA vbCmXCcsbZ/a0fRIQMBxp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