Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1919629pxm; Sun, 27 Feb 2022 06:33:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVnosK7hYVx40irfUxBCzpSrRmyeKYvBMGmJDLU23ffStxjVtjy/mstZYStOYC1o/fXOoV X-Received: by 2002:aa7:8f33:0:b0:4cb:95a7:928c with SMTP id y19-20020aa78f33000000b004cb95a7928cmr17025127pfr.42.1645972437664; Sun, 27 Feb 2022 06:33:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645972437; cv=none; d=google.com; s=arc-20160816; b=VTAOzkD8qyvWL9bSjKSsCJ+UzhWH0YS+dldkOZEcgjqHoA5wZInfvTNxC2KOMVtjsR V67jSPWr+0X7O5ab6DzOh+nf02QZz9gaOZzJLqicYsGK6fpt0rSXsFVaBtFNbwhgt1zW XV18H5VSmzhCsNtTgont8jfpvb9l0jdkTSmmynq7IvdYIGKs8Y1GfnHxP2JLVB6VYg74 gai7A7zYSEglRpzSwZmFWlHWFe3ALrHXLi/r/WtGHuvSsqrOur+Y2+RbQUKbPeX9OyXa Q6oirNGFxlk7UtxljgXaf5xBR7QUakUo4VEMcfUWHCnSGz9kQbYPFefgP1E/r2bTM6yM K52g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bTICqCcdg5iJm3vxMOdY/WqtQRYU17qjxPM4LOVV5J8=; b=FzzN/aOglMggLseITjhkrtP21oCpgvnQNQyuZPWZ/LGk7zGmx8RkRretlGNJ272is8 IvKhLTKS9D6So44A43/wK9JApEkxnTyb93xWbW0duVrhpSatltbJ/vasGDENvHhJeOKX eEVHqvoooP2VU+1eXGafb8s5WjTs46AGrly3SmgDMXycW56mkbrlSBaRiVthkqhjPNP2 AeIk9CR48mCuHPeDRGXs2o5o04nmJILR0o4dJde0yv/iwNkWNuKpQozc8fer++7jv7Jf fQQ7jZ4ZaRBxJrMZsJvLg+Z5I96Stg1gdhSWDU+qKn0vRaY70Nnjs5XzGCNurBr+iltc ya0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=gbvrEcld; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cp17-20020a170902e79100b0014fab714222si6857886plb.308.2022.02.27.06.33.40; Sun, 27 Feb 2022 06:33:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=gbvrEcld; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231388AbiB0Nyc (ORCPT + 99 others); Sun, 27 Feb 2022 08:54:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbiB0NyZ (ORCPT ); Sun, 27 Feb 2022 08:54:25 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE25713E0E for ; Sun, 27 Feb 2022 05:53:48 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 05A333FCAC for ; Sun, 27 Feb 2022 13:53:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645970024; bh=bTICqCcdg5iJm3vxMOdY/WqtQRYU17qjxPM4LOVV5J8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gbvrEcldOtK+hxyrzeVqbzr2kfB0nRT52tBKNvwQto2aoWTlcX3jc+hq7gmqJ8rBc Orb4qUQvLY1sKWnHSTYcaphUJ6YjczvDlaDA1cfjQ6tSZCjmT1sT55F9N9Hij0G54N 1nz+btti5IbjHpaV6W2NL0RFb+beVpIcLHWZ2dG13dCoPkEvSIOY5Vq12vSR1mm66i RDL3urJo6Es1blobBROwHVCgJZMDj6F6qsgCuVfqO70wNijS/J1PUuTR5q08+YmZs+ NgUrTTD+uKhRc8z95JVNQN5VhHRZZClphUYgMqFJi2tno35f9fTNdtc2CB5KgO9VWz nZy9oV8M99xdQ== Received: by mail-ed1-f69.google.com with SMTP id d11-20020a50c88b000000b00410ba7a14acso4250101edh.6 for ; Sun, 27 Feb 2022 05:53:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bTICqCcdg5iJm3vxMOdY/WqtQRYU17qjxPM4LOVV5J8=; b=PHMqBnYG9zCu2sxQqTfdZDKhL2pecw4oZaoilr07sfDP4r5sF4C/tm6ZmidiOxx536 i+vigj3RZ+iLNROKYd4jGMAsExm9guvASDkVMA0xEoNfw/Ig8Zfz7OM14TuDKSQG0Tvv 3cYJZLduSTFBryaH7muIKNrGtM+nl2LlWZcW4VDDHfpx6KISt5K6f3RI1VNMrVXOisvo cq9wF5Ecv1U8G9ksQ17rggY0+DwJ3GI8fIMjx+2SGLq23iiRXoQNEZlPDbefz5qGmfv2 ixvqjulSBUpNaji31z1ih7SQ/TZQKWlfFNwDi4C8GXmSCu8lUyDzFMzPx6zcsg8abw4w W8Rw== X-Gm-Message-State: AOAM533t1PcQA0xD9WiZhdoK5xqFvdg4/fj4kr+xkMhpVmwVops1bBVW PTd73Xf9yJOolrOPkRJ4I8ipDxdg9JyzM3Sy8z7eFVF72nPpLixnllF+CnVP4yVzp8OmOToArMS BaEAnIUsG4Y0JrgciVMO/8fhar3NADJAZ9Z2gLPEWZQ== X-Received: by 2002:a17:906:d8dc:b0:6cf:d1d1:db25 with SMTP id re28-20020a170906d8dc00b006cfd1d1db25mr12142691ejb.285.1645970022946; Sun, 27 Feb 2022 05:53:42 -0800 (PST) X-Received: by 2002:a17:906:d8dc:b0:6cf:d1d1:db25 with SMTP id re28-20020a170906d8dc00b006cfd1d1db25mr12142671ejb.285.1645970022727; Sun, 27 Feb 2022 05:53:42 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id w11-20020a056402128b00b00412ec3f5f74sm4600760edv.62.2022.02.27.05.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:53:42 -0800 (PST) From: Krzysztof Kozlowski To: 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 , Bjorn Andersson , 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 Cc: Rasmus Villemoes , Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v3 11/11] rpmsg: Fix kfree() of static memory on setting driver_override Date: Sun, 27 Feb 2022 14:53:29 +0100 Message-Id: <20220227135329.145862-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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 --- 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