Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp753419pxp; Fri, 11 Mar 2022 14:13:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZ0qBJ6nxe953z+g+Fkc/0Rg0VUJRhZthejQrNeSoFj7xa5Et5eog2xepeo7hYyUYKRBrZ X-Received: by 2002:a17:90b:314d:b0:1bf:acde:16e5 with SMTP id ip13-20020a17090b314d00b001bfacde16e5mr13043964pjb.165.1647036799708; Fri, 11 Mar 2022 14:13:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647036799; cv=none; d=google.com; s=arc-20160816; b=p+VVGpJ5tN1qfSI/x/HdEB23lAtYBRyDPF65qXzQ2WTPIKqeK5urDuMyZtk9vsp4f1 Vwpu+ld8r8leoxB0noGcYTKWjHdsT0QFsyQrYvY5Np6ID5xmdIIAt4D++r+9I6pXtoHh XwMYv1lBzAFD/eC4X8842s4r7uBTRwTALo2YwOOL581+udaTNv2va447wNVv1Sirmr1P nfeSxydX7RLuSW59Whq+YWD6ga9orPzP3LB4OgjMCTF1uLZtYHZz3An2lY5/mG+rSo5X Int4rFurDPpbQCKAS+gsrMIeNzPZvY6iePQ90/q9E6C2+T92TPEwLtscWRkvRPQ/SFnq U93A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=byy3khpUB/C66OcuZpBogrh1vBdJYZWOahv4ARsAqeU=; b=QYpw/c/RdAHkCPTxKUd/QnKUjR63H9Z1p8XcJvp294PfNEYhVXvllyBbASllRZw6UC eV9X9ZG2KdpB1Im7xTQrCH8pVHvy9rOU9MIdJd11Mv94OIvdkAippa68Ht6/939vmJhV Mu19b2lKhARhdsnXJVE9P26xxdLDoPyRKLfMlYJxboH3mDNeBl/LDWPoUKDh2XW4/otu PfTGbFeNjB6N47cDZgYINx3/aK7hvuDNJuUbQPhsNRUo2QQN4GstSOkxzVND/zEby9tX lfOhNbgk973OyJfm7kc8jcL2YopazVSPiQE6QKkQKzelgIlJWf0HbzJFtUChfM7vk7FL u/LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JsI+MgGw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l71-20020a63884a000000b00380f45bf1b5si4767337pgd.541.2022.03.11.14.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 14:13:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JsI+MgGw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9B1AC2B4932; Fri, 11 Mar 2022 13:22:35 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351181AbiCKUUL (ORCPT + 99 others); Fri, 11 Mar 2022 15:20:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348936AbiCKUUI (ORCPT ); Fri, 11 Mar 2022 15:20:08 -0500 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82BDB1AAFDD for ; Fri, 11 Mar 2022 12:19:04 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id b188so10558552oia.13 for ; Fri, 11 Mar 2022 12:19:04 -0800 (PST) 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=byy3khpUB/C66OcuZpBogrh1vBdJYZWOahv4ARsAqeU=; b=JsI+MgGwcNWNo5mFTmDhFQFX43IPSGP8AHmpadTTq1/jegWXkSYGxRbyYSNd2GGAfZ QJL9ePsqy1+pQCjIkYOKeRZF/4ou56BLTl43xcIPQgKVuLYTvOOSpWVMBXvPzi3iVcEE M9OokvdpojzL0W3mpYKQGxN00uuF3MValP5LkZwv7tBK8MbHNCEdcUSp8EyQgNvmdObM dV8uEHfL0A+kbdg4/kBwvllnMdB0q6LY78GBq99WSqCsQB+n/5bFK7oLoh//RzZWPskK DuBKl43ZqA2bbLdc1tjjtMkwJymKeQrW5rKztLf0fnJNsCRRE5EUHhDiGz2DbwyIRrvz mrcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=byy3khpUB/C66OcuZpBogrh1vBdJYZWOahv4ARsAqeU=; b=Xo6N4IFsbX6Q5X0KXtRrgTLRvh9Uri1AlcvwTmPYaSa7nmbEdoJnWA2i3UeHkU+S9H nQkWus8C+vVz7nTd4dCGY2Who9SmlUup++gYozzVy6cj5mR3LXP3Qe0KSmcA5/UFpT8R OP3PdTnty5Rn4SCTRom+VSn8Gfi5jElJGG59Wbx8GaVDeqlHirjYKUfept9F41y48bIz SUZ2bj6VfxOeKDA2HscIWavPjFBtMMJzkjATaUmqlcqe5MI8GkjkjcnfvIberxMGHd4m dm49pNDCAyW6HvZv8NvP+4nZ7zbb6wPs6z9tBPcbTzqbPFn1+0CmA1Z8PdtGaAN14RP2 5YFg== X-Gm-Message-State: AOAM530R6xzsUDSO/xO4vco+wVBvEwpbpnu+9U3iA9rp9JKdhRUvNlV4 DMfS1ryW9b3lekuHEIXexTwjEw== X-Received: by 2002:a05:6808:1406:b0:2d9:a01a:4bcb with SMTP id w6-20020a056808140600b002d9a01a4bcbmr7858798oiv.242.1647029943809; Fri, 11 Mar 2022 12:19:03 -0800 (PST) Received: from builder.lan ([2600:1700:a0:3dc8:3697:f6ff:fe85:aac9]) by smtp.gmail.com with ESMTPSA id r41-20020a056870582900b000d6cbaf589esm3887680oap.40.2022.03.11.12.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 12:19:02 -0800 (PST) Date: Fri, 11 Mar 2022 14:19:00 -0600 From: Bjorn Andersson To: Krzysztof Kozlowski Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds , Rasmus Villemoes , stable@vger.kernel.org Subject: Re: [PATCH v3 11/11] rpmsg: Fix kfree() of static memory on setting driver_override Message-ID: References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> <20220227135329.145862-5-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220227135329.145862-5-krzysztof.kozlowski@canonical.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Sun 27 Feb 07:53 CST 2022, Krzysztof Kozlowski wrote: > The driver_override field from platform driver should not be initialized > from static memory (string literal) because the core later kfree() it, > for example when driver_override is set via sysfs. > > Use dedicated helper to set driver_override properly. > > Fixes: 950a7388f02b ("rpmsg: Turn name service into a stand alone driver") > Fixes: c0cdc19f84a4 ("rpmsg: Driver for user space endpoint interface") > Cc: > Signed-off-by: Krzysztof Kozlowski Reviewed-by: Bjorn Andersson Regards, Bjorn > --- > drivers/rpmsg/rpmsg_core.c | 3 ++- > drivers/rpmsg/rpmsg_internal.h | 13 +++++++++++-- > drivers/rpmsg/rpmsg_ns.c | 14 ++++++++++++-- > include/linux/rpmsg.h | 6 ++++-- > 4 files changed, 29 insertions(+), 7 deletions(-) > > diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c > index d9e612f4f0f2..6e2bf2742973 100644 > --- a/drivers/rpmsg/rpmsg_core.c > +++ b/drivers/rpmsg/rpmsg_core.c > @@ -397,7 +397,8 @@ field##_store(struct device *dev, struct device_attribute *attr, \ > const char *buf, size_t sz) \ > { \ > struct rpmsg_device *rpdev = to_rpmsg_device(dev); \ > - char *new, *old; \ > + const char *old; \ > + char *new; \ > \ > new = kstrndup(buf, sz, GFP_KERNEL); \ > if (!new) \ > diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h > index b1245d3ed7c6..31345d6e9a7e 100644 > --- a/drivers/rpmsg/rpmsg_internal.h > +++ b/drivers/rpmsg/rpmsg_internal.h > @@ -92,10 +92,19 @@ int rpmsg_release_channel(struct rpmsg_device *rpdev, > */ > static inline int rpmsg_chrdev_register_device(struct rpmsg_device *rpdev) > { > + int ret; > + > strcpy(rpdev->id.name, "rpmsg_chrdev"); > - rpdev->driver_override = "rpmsg_chrdev"; > + ret = driver_set_override(&rpdev->dev, &rpdev->driver_override, > + "rpmsg_chrdev", strlen("rpmsg_chrdev")); > + if (ret) > + return ret; > + > + ret = rpmsg_register_device(rpdev); > + if (ret) > + kfree(rpdev->driver_override); > > - return rpmsg_register_device(rpdev); > + return ret; > } > > #endif > diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c > index 762ff1ae279f..95a51543f5ad 100644 > --- a/drivers/rpmsg/rpmsg_ns.c > +++ b/drivers/rpmsg/rpmsg_ns.c > @@ -20,12 +20,22 @@ > */ > int rpmsg_ns_register_device(struct rpmsg_device *rpdev) > { > + int ret; > + > strcpy(rpdev->id.name, "rpmsg_ns"); > - rpdev->driver_override = "rpmsg_ns"; > + ret = driver_set_override(&rpdev->dev, &rpdev->driver_override, > + "rpmsg_ns", strlen("rpmsg_ns")); > + if (ret) > + return ret; > + > rpdev->src = RPMSG_NS_ADDR; > rpdev->dst = RPMSG_NS_ADDR; > > - return rpmsg_register_device(rpdev); > + ret = rpmsg_register_device(rpdev); > + if (ret) > + kfree(rpdev->driver_override); > + > + return ret; > } > EXPORT_SYMBOL(rpmsg_ns_register_device); > > diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h > index 02fa9116cd60..20c8cd1cde21 100644 > --- a/include/linux/rpmsg.h > +++ b/include/linux/rpmsg.h > @@ -41,7 +41,9 @@ struct rpmsg_channel_info { > * rpmsg_device - device that belong to the rpmsg bus > * @dev: the device struct > * @id: device id (used to match between rpmsg drivers and devices) > - * @driver_override: driver name to force a match > + * @driver_override: driver name to force a match; do not set directly, > + * because core frees it; use driver_set_override() to > + * set or clear it. > * @src: local address > * @dst: destination address > * @ept: the rpmsg endpoint of this channel > @@ -51,7 +53,7 @@ struct rpmsg_channel_info { > struct rpmsg_device { > struct device dev; > struct rpmsg_device_id id; > - char *driver_override; > + const char *driver_override; > u32 src; > u32 dst; > struct rpmsg_endpoint *ept; > -- > 2.32.0 >