From patchwork Wed May 17 18:13:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kursad Oney X-Patchwork-Id: 13245511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92A41C77B75 for ; Wed, 17 May 2023 18:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=ThS6YqpPQkx6Ze5uo10g2XT9VgjO2nvUAZtSFz0/P/k=; b=bmv AvKzLBPL+Bcye+GyUG8YLziC7HvWCb6/+RUJ5dUDW+uBt5s0uawzr4cKt/4FjSSvWokT9X41NbEjo kuj3ah8UIcXX9mFq09Z6rJguPg9jorDm7+HUDcswN7UgmTNXOqSdwPRQU6hg1xUk6hBqv0moDRVuJ Jo4iYegFhyUfjsBLGhNoKUY3cdqP8Md/Q3VK0jHh0c6Lzpyc5I46VPxRdZKU7lcvMh2irPFIQh3Si bL+/RKFKhiMXVTuquq8o5RYTMIXivkE8WYfxNtLkRQTZYSjg9PssibNVXKzjJOAuyzY9p2LX+KlwX M4MnesFGnF1Rp/H5ADUVW1fLxDFm5ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzLfH-00AhiS-0a; Wed, 17 May 2023 18:14:19 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzLfC-00AhhT-1F for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 18:14:16 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1ae52ce3205so7468125ad.3 for ; Wed, 17 May 2023 11:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1684347252; x=1686939252; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=+iPu0/ClNdGtl0RnDezkBCOGd/TG+xO61bPYwaxu53E=; b=cc56l4nzlDRgW2zRx8UfiU36z/MPH+rwiAs1f2o+X5wgReSppuG8pvpuMryKFA470Q LwPqxyIqRRLPkwJXeR2Dhq1z7KJPylRV6YIePFK6RgRVWV1H4Zbypy19WRmL4MBgLVXr Tx4zh5eVh8XEJyqXz0MpkCR5Ki4Xl2elRgK/E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684347252; x=1686939252; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+iPu0/ClNdGtl0RnDezkBCOGd/TG+xO61bPYwaxu53E=; b=A3+siip7++tjR4SKloVCQZCXOg6oT7RQ7xWScxR65ZsL3wYEuyiKLWbE7QJPW6RSfP pD+vWGJsOiHhQM1Li535Oq1AJFd/cGkhvx/j6UcfCF+GfKNg643DIlnFAeaBCRfHl2A1 ObroTmAudajz09k8U7biDK28/SLdn2pCZ9Gdtsrw9/DnKkTWKF/0N4cjbObTqTdsqFrk dmPhxEmGR23jXc/KYvOOBWIrIQZ/hGphlVaAZhwgmG8DyknDhFEJgQF5zucfSTjjEPAO PT3w84tT5tSPcglq/84IvaK3BZWYJfFObIb/KlNPNDJikdicymS4mJxl9UxNu2D2Rod5 ohgA== X-Gm-Message-State: AC+VfDyP0Hr/Q/Mrk8/gIFEnceBbT6Rew6iIbSzAqi9yZC7MGjCbpXkS Blzjz0uz/FaurLYv/ZHMc5Py+DBMSg2Vz9wprhJGIVC2ObAqfyksoqtgSdalh4LgllH6P0v5hkg RFwO090W+OknGjOKUzw28cUHS9TzO8UKe/J1B3e6DpgIVggcmiV8dfZsntgMT5sGuriwdGacrqZ VA5M6qctIFc7w0J4n5cPgaYg== X-Google-Smtp-Source: ACHHUZ7A0kEpjfqD1pnc4sa8WBRrOfVw+00PK0bqS3h8X1n2dOwkza4MXUGxI+Jub1H/HD1kawkWFA== X-Received: by 2002:a17:903:234f:b0:1ae:bf5:7b5 with SMTP id c15-20020a170903234f00b001ae0bf507b5mr15915501plh.34.1684347252392; Wed, 17 May 2023 11:14:12 -0700 (PDT) Received: from bld-lvn-bcawlan-30.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id w3-20020a1709027b8300b001ae626d051bsm205400pll.70.2023.05.17.11.14.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2023 11:14:11 -0700 (PDT) From: Kursad Oney To: linux-arm-kernel@lists.infradead.org Cc: BCM Kernel Feedback , Kursad Oney , Russell King , linux-kernel@vger.kernel.org Subject: [PATCH] ARM: memset: cast the constant byte to unsigned char Date: Wed, 17 May 2023 14:13:52 -0400 Message-Id: <20230517181353.381073-1-kursad.oney@broadcom.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_111415_384618_A77A2B64 X-CRM114-Status: GOOD ( 12.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Ard Biesheuvel Reviewed-by: Linus Walleij --- 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