From patchwork Wed Aug 29 07:57:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 10579641 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 981F0175A for ; Wed, 29 Aug 2018 07:58:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C8922A941 for ; Wed, 29 Aug 2018 07:58:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ECCF2AA1C; Wed, 29 Aug 2018 07:58:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26F682A941 for ; Wed, 29 Aug 2018 07:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728024AbeH2Lxp (ORCPT ); Wed, 29 Aug 2018 07:53:45 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:45446 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727668AbeH2Lxo (ORCPT ); Wed, 29 Aug 2018 07:53:44 -0400 Received: by mail-lf1-f67.google.com with SMTP id r4-v6so3502358lff.12 for ; Wed, 29 Aug 2018 00:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WGcGxBYbMR3lYiFeso6+j/q0sgMwNMyzkoeytqhrrrw=; b=WPxuH4FEJqGnE517ARbt1uzfFsPp8ytr1oMwjBDUNHNo5fmIpTQAAm9y3sI9brHI6A tdqnUm2Ed0vS+hZ9vrptewg9I8ejvYK6kQd+oAq107kuxp5OJ7qNkfC9fwYNgCNdxNoM OhtlFc4FsSCXYJ5lABPkWmE/YP03pcxk6Y4lE= 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:in-reply-to :references; bh=WGcGxBYbMR3lYiFeso6+j/q0sgMwNMyzkoeytqhrrrw=; b=GqzuRc7h7Kdf3lLujdnCJ4WsHXGFTQYI0mMBi+IqA63E1eIX48gljyMYN+XeQgcnbB bKJvQuV5ekTxoNKDyagaEEkNSftAPeDUwnNquFkKibHEsZKlfVRenNIGY+rW4ZxMdDva soW5ZB4sRzh4i/I3T2qYnIj13qC0T1npgC3rplgo9m/cGpDnIk2v/NIT0saUQT5PndTC vIRqBQiS2L9uR7VYvs7c2nUreAsOlxFv1nWl654XZDBr4g4qdzB+NSF12Y+SQsbmPUt1 /CYuf1RqYXlSdEunTqVy/4vnEDMitG8mm7pnhXe0RIP/Qmd2UbN3xm3FSnp5+8N4hq+2 eDkg== X-Gm-Message-State: APzg51Bm4Ac0meTEX9N+M7Mhh5NMNDBtI0HXTgk+gNbBS8GAWYA1xvca ZJWCWXR/oDekxHWEp7KDsCM8qw== X-Google-Smtp-Source: ANB0VdbbFl2j18WiFp8S5cwsXkWO0k5xxDWzgqly5jEGGRu/P+vPtVIar2mp9pEp9FccfyJyHbn3fg== X-Received: by 2002:a19:be55:: with SMTP id o82-v6mr3353559lff.58.1535529486221; Wed, 29 Aug 2018 00:58:06 -0700 (PDT) Received: from centauri.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id j9-v6sm592303ljh.40.2018.08.29.00.58.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Aug 2018 00:58:05 -0700 (PDT) From: Niklas Cassel To: Andy Gross , David Brown Cc: Niklas Cassel , linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 8/9] soc: qcom: apr: Avoid string overflow Date: Wed, 29 Aug 2018 09:57:22 +0200 Message-Id: <20180829075724.9095-9-niklas.cassel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180829075724.9095-1-niklas.cassel@linaro.org> References: <20180829075724.9095-1-niklas.cassel@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 'adev->name' is used as a NUL-terminated string, but using strncpy() with the length equal to the buffer size may result in lack of the termination: In function 'apr_add_device', inlined from 'of_register_apr_devices' at drivers//soc/qcom/apr.c:264:7, inlined from 'apr_probe' at drivers//soc/qcom/apr.c:290:2: drivers//soc/qcom/apr.c:222:3: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation] strncpy(adev->name, np->name, APR_NAME_SIZE); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This changes it to use the safer strscpy() instead. Signed-off-by: Niklas Cassel Reviewed-by: Bjorn Andersson --- drivers/soc/qcom/apr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c index 57af8a537332..ee9197f5aae9 100644 --- a/drivers/soc/qcom/apr.c +++ b/drivers/soc/qcom/apr.c @@ -219,9 +219,9 @@ static int apr_add_device(struct device *dev, struct device_node *np, adev->domain_id = id->domain_id; adev->version = id->svc_version; if (np) - strncpy(adev->name, np->name, APR_NAME_SIZE); + strscpy(adev->name, np->name, APR_NAME_SIZE); else - strncpy(adev->name, id->name, APR_NAME_SIZE); + strscpy(adev->name, id->name, APR_NAME_SIZE); dev_set_name(&adev->dev, "aprsvc:%s:%x:%x", adev->name, id->domain_id, id->svc_id);