From patchwork Tue Nov 19 05:16:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 179644 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp154392ilf; Mon, 18 Nov 2019 21:32:59 -0800 (PST) X-Google-Smtp-Source: APXvYqzXA5n9CBHuqV4irAi4wlpEdEfxDB+bqbMEaBrMWRo+VfppFZtIC9yucQ0gkFfmv7qb1KQo X-Received: by 2002:a17:906:394c:: with SMTP id g12mr31842919eje.233.1574141579560; Mon, 18 Nov 2019 21:32:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574141579; cv=none; d=google.com; s=arc-20160816; b=h+5Uf/ZJHsmk6Z6h8DrVriw0qY7/ZKsaRXoPv+Fwo9UtckfCQHHXgS+e2iv3pu3Iso n0tEcto4B773pTdnjnGhs3QIZhCFEGBHObA9Qy3ey4I1tnjeF9hrTtE32cvZOBpx+a84 V2LhL3EYSANgiELq0WcJEzSi9+9dYX/C4NVHX4XBs1gjGo8bzIk5XLuGwp52xmKHr46D nS9iBcDRql0r+i2wFHcsQ4zhoc2X849Z/6pxTGuU8qcKVuFTb++HztGQsbXmf0TtKbmN K103VzuXD9LJcpYrwp/T6uEZBIDUM/twmpGcqTzPXBUINSKV3FWrElh8qwESArLnhgSk S2NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ASV3Hlr9DOzOm6oXOSAboVm6lA65/oLsksT5KnGp6S0=; b=o5giJjjr2quKXDuAsg2RdW81Pi6P1MHR5zPEfBVaJzyFXWGr4OOKO44WT863H81Elr DoIBEFs99iPI2hpriA/8yWIVkqPIktgPB+d/LuNv1XQQavFyqR5hfKhfCu5jJY/yM5CF GBC3fqqzNSa5NGsU+XMbqULOpe91UFX7gWV7jMDDC4cS1RMIE0J8vuFMFenN/sYYSFaC p6MssTpwbLd2+Lgo+abzOcyoo27qIDCervMF0UtMRdgReoPc/4vTSJBOayVzobc3hjqT nvfu4JT8qwqupigtj36qJHX7tq8SZNlXsy9IPxxsKRhGNkBcsnO3zG3lZQ7h+EGQDsIc L6iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hEiXGqY3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si13041915ejf.345.2019.11.18.21.32.59; Mon, 18 Nov 2019 21:32:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hEiXGqY3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728730AbfKSFc5 (ORCPT + 26 others); Tue, 19 Nov 2019 00:32:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:53328 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727717AbfKSFcz (ORCPT ); Tue, 19 Nov 2019 00:32:55 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 42A9F21783; Tue, 19 Nov 2019 05:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574141574; bh=UVs0BQCbS7l7vr5KRG0CBnk8B8+YWO9XidSyUtzdbGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hEiXGqY3qOQA0wrGiRflfQbjYLtWEM6inFY5WCDinad8bNvH6RklwZCAEMpmbD8xs HOUbUn3iDGOrbqiCt/mwMskc0WqDcE2EmF4Ku22KaM2v+OF7fOhsDIRbNoefZmYeFZ YgkRy+x3LPFF0qRhcZ3WNv9BNzA1GBmWvDFBuuBI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Niklas Cassel , Bjorn Andersson , Andy Gross , Sasha Levin Subject: [PATCH 4.19 207/422] soc: qcom: apr: Avoid string overflow Date: Tue, 19 Nov 2019 06:16:44 +0100 Message-Id: <20191119051412.003391715@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191119051400.261610025@linuxfoundation.org> References: <20191119051400.261610025@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Niklas Cassel [ Upstream commit 4fadb26574cb74e5de079dd384f25f44f4fb3ec3 ] '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 Signed-off-by: Andy Gross Signed-off-by: Sasha Levin --- drivers/soc/qcom/apr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c index 57af8a5373325..ee9197f5aae96 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);