From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECC88C4338F for ; Wed, 4 Aug 2021 22:36:37 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B9D1E6056B for ; Wed, 4 Aug 2021 22:36:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B9D1E6056B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f8EFpdDfGWkmWvIyiRGGkgOMm0nV7765PlEifcOZcoY=; b=Ir9qy8BQf7Rwg7 +bbA/GkHPsm83TukUFmbXpzN+pd4rhoN+jx58uvQwEXsBYi+U8ZCzLCqzX35OzxykYkOap13Iu+pn +kO+e1yFBoUVjaNkVkyTS41IWvMJNQM9QN+/JF1nNROC24dUna8Uw7/VfBoUa7q+qj0XMbKKDY6Yt pnfFzWuQbhSWrKkmKTxMc64NBYUsHewPEC+RajYvzsuACTmqt6TVJFw8iaCEjL9zLug/PkBNpANsN EW0gcRlwo+Rl5C5wjIk+lJcQgyg5cOSk3v71rmsxtUCfAFZh7zKbaDGRUk4xRgHvjvJxR6SsPM1ZX 3BNlpIF8l1+zUbPdJ5jQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBPTQ-007abe-5e; Wed, 04 Aug 2021 22:34:52 +0000 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBPTK-007ab2-FI for linux-arm-kernel@lists.infradead.org; Wed, 04 Aug 2021 22:34:50 +0000 Received: by mail-oo1-xc29.google.com with SMTP id s21-20020a4ae5550000b02902667598672bso836844oot.12 for ; Wed, 04 Aug 2021 15:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=UZJcNHJO4LQR36ixWf/ziwUjfQuMb7Mm0UXvd1Hg4gg=; b=tYW3NQDOaoOAmJhieZdnjoNjyaKSHVE6lyBu/OX7HVPsqfng6qLWGieMImgOnYOTJi cYngNaDNRi+IYluKEdjg2VZop0ieSPcf9B+mXmwNjeBrVp1v/38uzGbg7XC8EZm1aFpf tiFQ8nlYg0YZzyumw/O9+hiqvT0Jw8ihLS6nbGMrj7vqKue0Uq1+aldnBbWl7OoZPXuz kqWQZnQISxU2gZWw8cPt8ezEhjDk3bDetIIylfrpL7z3qftYHAcdSCW9pJSXTLw4UY2z 6YacG1MWStILNWzVOCNFqRAS0EY3KK/v9lETqF5C99PjApimrc+i7Gj6c0v1XBuA8Z++ 0qYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UZJcNHJO4LQR36ixWf/ziwUjfQuMb7Mm0UXvd1Hg4gg=; b=B9hrRq/ecLARiJhyCnADy96HBSI1i34zWngzLEocqPAmsfgq1cmekF9PfB0CJJ9ueu fpSTsXeihFgCpqv3IavnLwikSsw3h7CKTir6qVOTGpTkdRlwVpONr2mf4Sdm/kPbbp68 6VCQPtZBDHvcy16exEiu7BpNBWRH9r+/LzWn6cpMrdlTMRFuPYV5IOhYDi2aNMtYKTm9 lTePoU0hQoVnd/ejoHRusrHGiDlPgIv1sWyoOSQhI7Pj2KU49Pnblg+j+2svo1I1rnDy OKQiwLhFQ15RCZBaMlXP3nm4BJAyRyTBgl/RNiNm6PGsf8m+cJ1QHhnYr8v7t0xoDsGt euiA== X-Gm-Message-State: AOAM532AUQUjZLf3gS1kKZUQydVfKYMTKPyz+SDzgwb3V548SvIPrezx qGI0bhFCcNp1yeIwNTAUiO+5lw== X-Google-Smtp-Source: ABdhPJzoI974+mp/rfGo+7Xq9nqrA8eJ6Be/tx/TkRzTQ2z3SwevKn0NJ4P732tpLcSoO/FyWG+urg== X-Received: by 2002:a4a:d812:: with SMTP id f18mr1073419oov.50.1628116485417; Wed, 04 Aug 2021 15:34:45 -0700 (PDT) Received: from builder.lan (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id r15sm455538otn.33.2021.08.04.15.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 15:34:45 -0700 (PDT) Date: Wed, 4 Aug 2021 17:34:43 -0500 From: Bjorn Andersson To: Len Baker Cc: Kees Cook , Andy Gross , Geert Uytterhoeven , Magnus Damm , Santosh Shilimkar , David Laight , Robin Murphy , linux-hardening@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v3] drivers/soc: Remove all strcpy() uses Message-ID: References: <20210801131958.6144-1-len.baker@gmx.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210801131958.6144-1-len.baker@gmx.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210804_153446_567555_AFC78877 X-CRM114-Status: GOOD ( 26.39 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun 01 Aug 08:19 CDT 2021, Len Baker wrote: > strcpy() performs no bounds checking on the destination buffer. This > could result in linear overflows beyond the end of the buffer, leading > to all kinds of misbehaviors. The safe replacement is strscpy(). > > Moreover, when the size of the destination buffer cannot be obtained > using "sizeof", use the memcpy function instead of strscpy. > > Signed-off-by: Len Baker Forgot one thing, it's unclear who should pick this patch up and there's definitely a chance that it will cause merge conflicts regardless of whom of us end up picking it. Could you please split it so that the qcom, renesas and ti pieces can be picked up by respective maintainer? Thanks, Bjorn > --- > This is a task of the KSPP [1] > > [1] https://github.com/KSPP/linux/issues/88 > > Changelog v1 -> v2 > - Change the "area_name_size" variable for a shorter name (Geert > Uytterhoeven). > - Add the "Reviewed-by: Geert Uytterhoeven" tag. > - Use the memcpy function instead of strscpy function when the > size of the destination buffer cannot be obtained with "sizeof" > (David Laight, Robin Murphy). > > Changelog v2 -> v3 > - Remove the "Reviewed-by: Geert Uytterhoeven" tag since the code > has changed after the v1 review (use of memcpy instead of > strscpy). > > drivers/soc/qcom/pdr_interface.c | 13 +++++++------ > drivers/soc/renesas/r8a779a0-sysc.c | 6 ++++-- > drivers/soc/renesas/rcar-sysc.c | 6 ++++-- > drivers/soc/ti/knav_dma.c | 2 +- > 4 files changed, 16 insertions(+), 11 deletions(-) > > diff --git a/drivers/soc/qcom/pdr_interface.c b/drivers/soc/qcom/pdr_interface.c > index 915d5bc3d46e..cf119fde749d 100644 > --- a/drivers/soc/qcom/pdr_interface.c > +++ b/drivers/soc/qcom/pdr_interface.c > @@ -131,7 +131,7 @@ static int pdr_register_listener(struct pdr_handle *pdr, > return ret; > > req.enable = enable; > - strcpy(req.service_path, pds->service_path); > + strscpy(req.service_path, pds->service_path, sizeof(req.service_path)); > > ret = qmi_send_request(&pdr->notifier_hdl, &pds->addr, > &txn, SERVREG_REGISTER_LISTENER_REQ, > @@ -257,7 +257,7 @@ static int pdr_send_indack_msg(struct pdr_handle *pdr, struct pdr_service *pds, > return ret; > > req.transaction_id = tid; > - strcpy(req.service_path, pds->service_path); > + strscpy(req.service_path, pds->service_path, sizeof(req.service_path)); > > ret = qmi_send_request(&pdr->notifier_hdl, &pds->addr, > &txn, SERVREG_SET_ACK_REQ, > @@ -406,7 +406,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds) > return -ENOMEM; > > /* Prepare req message */ > - strcpy(req.service_name, pds->service_name); > + strscpy(req.service_name, pds->service_name, sizeof(req.service_name)); > req.domain_offset_valid = true; > req.domain_offset = 0; > > @@ -531,8 +531,8 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr, > return ERR_PTR(-ENOMEM); > > pds->service = SERVREG_NOTIFIER_SERVICE; > - strcpy(pds->service_name, service_name); > - strcpy(pds->service_path, service_path); > + strscpy(pds->service_name, service_name, sizeof(pds->service_name)); > + strscpy(pds->service_path, service_path, sizeof(pds->service_path)); > pds->need_locator_lookup = true; > > mutex_lock(&pdr->list_lock); > @@ -587,7 +587,8 @@ int pdr_restart_pd(struct pdr_handle *pdr, struct pdr_service *pds) > break; > > /* Prepare req message */ > - strcpy(req.service_path, pds->service_path); > + strscpy(req.service_path, pds->service_path, > + sizeof(req.service_path)); > addr = pds->addr; > break; > } > diff --git a/drivers/soc/renesas/r8a779a0-sysc.c b/drivers/soc/renesas/r8a779a0-sysc.c > index d464ffa1be33..7410b9fa9846 100644 > --- a/drivers/soc/renesas/r8a779a0-sysc.c > +++ b/drivers/soc/renesas/r8a779a0-sysc.c > @@ -404,19 +404,21 @@ static int __init r8a779a0_sysc_pd_init(void) > for (i = 0; i < info->num_areas; i++) { > const struct r8a779a0_sysc_area *area = &info->areas[i]; > struct r8a779a0_sysc_pd *pd; > + size_t n; > > if (!area->name) { > /* Skip NULLified area */ > continue; > } > > - pd = kzalloc(sizeof(*pd) + strlen(area->name) + 1, GFP_KERNEL); > + n = strlen(area->name) + 1; > + pd = kzalloc(sizeof(*pd) + n, GFP_KERNEL); > if (!pd) { > error = -ENOMEM; > goto out_put; > } > > - strcpy(pd->name, area->name); > + memcpy(pd->name, area->name, n); > pd->genpd.name = pd->name; > pd->pdr = area->pdr; > pd->flags = area->flags; > diff --git a/drivers/soc/renesas/rcar-sysc.c b/drivers/soc/renesas/rcar-sysc.c > index 53387a72ca00..b0a80de34c98 100644 > --- a/drivers/soc/renesas/rcar-sysc.c > +++ b/drivers/soc/renesas/rcar-sysc.c > @@ -396,19 +396,21 @@ static int __init rcar_sysc_pd_init(void) > for (i = 0; i < info->num_areas; i++) { > const struct rcar_sysc_area *area = &info->areas[i]; > struct rcar_sysc_pd *pd; > + size_t n; > > if (!area->name) { > /* Skip NULLified area */ > continue; > } > > - pd = kzalloc(sizeof(*pd) + strlen(area->name) + 1, GFP_KERNEL); > + n = strlen(area->name) + 1; > + pd = kzalloc(sizeof(*pd) + n, GFP_KERNEL); > if (!pd) { > error = -ENOMEM; > goto out_put; > } > > - strcpy(pd->name, area->name); > + memcpy(pd->name, area->name, n); > pd->genpd.name = pd->name; > pd->ch.chan_offs = area->chan_offs; > pd->ch.chan_bit = area->chan_bit; > diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c > index 591d14ebcb11..5f9816d317a5 100644 > --- a/drivers/soc/ti/knav_dma.c > +++ b/drivers/soc/ti/knav_dma.c > @@ -691,7 +691,7 @@ static int dma_init(struct device_node *cloud, struct device_node *dma_node) > dma->max_rx_flow = max_rx_flow; > dma->max_tx_chan = min(max_tx_chan, max_tx_sched); > atomic_set(&dma->ref_count, 0); > - strcpy(dma->name, node->name); > + strscpy(dma->name, node->name, sizeof(dma->name)); > spin_lock_init(&dma->lock); > > for (i = 0; i < dma->max_tx_chan; i++) { > -- > 2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel